From 95dd4739aa62188f6ffbfdf80b6537357559a7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Tue, 4 Dec 2012 03:44:32 +0100 Subject: Updating git scripts + add support for gitfile (submodules with git >= 1.7.8) + add gituser detection from git configuration + add support for branches + various optimizations --- switch_all_submodules_to_head_and_clean | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'switch_all_submodules_to_head_and_clean') diff --git a/switch_all_submodules_to_head_and_clean b/switch_all_submodules_to_head_and_clean index c395e62..0171537 100755 --- a/switch_all_submodules_to_head_and_clean +++ b/switch_all_submodules_to_head_and_clean @@ -1,17 +1,29 @@ #!/bin/bash -if [[ ! -d .git ]]; then +if [[ ! -e .git ]] || + [[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then echo "This script can only be run from a top level git directory. Exiting..." exit 1 fi +branch=`git symbolic-ref -q HEAD | sed "s|^refs/heads/||"` +if [[ -z "$branch" ]] || + [[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then + echo "There is not active upstream branch. Exiting..." + exit 1 +fi + echo "Preparing $PWD for development use" if [[ $1 == "" ]]; then - read -p "Enter your TDE GIT username []: " -e gituser + gituser=`sed -n "/^\[remote \"origin\"\]/,/url/s/\turl = http:\/\/\([^@]*\)@.*/\1/p" <\`git rev-parse --git-dir\`/config | grep -v "\(anonymous\|system\)"` else gituser=$1 fi +if [[ $gituser == "" ]]; then + read -p "Enter your TDE GIT username []: " -e gituser +fi + if [[ $gituser == "" ]]; then gituser="anonymous" fi @@ -23,11 +35,15 @@ if [[ ! -e "$THISSCRIPT" ]]; then exit 1 fi -git reset --hard HEAD -git clean -dxf +if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then + git reset --hard HEAD + git clean -dxff +fi git pull -git reset --hard HEAD -git clean -dxf +if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then + git reset --hard HEAD + git clean -dxff +fi if [[ -e .gitmodules ]]; then if [[ $gituser == "anonymous" ]]; then @@ -38,9 +54,7 @@ if [[ -e .gitmodules ]]; then git submodule init git submodule update - git submodule foreach "git checkout master" - git submodule foreach "git pull" - git submodule foreach "$THISSCRIPT $gituser" + git submodule foreach "git checkout $branch && $THISSCRIPT $gituser" git checkout -- .gitmodules fi -- cgit v1.2.1