]> git.xonotic.org Git - xonotic/div0-gittools.git/blobdiff - git-recurse
call merge tool properly
[xonotic/div0-gittools.git] / git-recurse
index e77c632223bc7853bcc4e4227724b524485f54c4..17959bdae1215094cf30c65d674d803b946bb5bd 100755 (executable)
@@ -3,11 +3,15 @@
 SEPARATOR=@@
 
 # TODO this logic should probably rather be in rev-parse itself
+# what it does:
+#   whenever an expression foo@@bar is used as an argument
+#   it checks whether foo is a valid reference, and if not, bar is used instead
 processarg()
 {
        prefix=
        suffix=
        case "$1" in
+               # have to detect some rev-parse syntax
                *..*)
                        first=${1%%..*}
                        rest=${1#*..}
@@ -44,6 +48,7 @@ processarg()
                        first=`processarg "$first"`
                        echo "^$first"
                        ;;
+               # handle foo@@bar so that if foo exists, foo stays, otherwise bar
                *$SEPARATOR*)
                        first=${1%%$SEPARATOR*}
                        rest=${1#*$SEPARATOR}
@@ -53,6 +58,7 @@ processarg()
                                processarg "$rest"
                        fi
                        ;;
+               # other args stay as is
                *)
                        echo "$1"
                        ;;
@@ -69,10 +75,25 @@ processargs()
                fi
                set -- "$@" "`processarg "$X"`"
        done
+       echo >&2 "In `pwd`: $*"
        "$@"
 }
 
+# save stdin
+exec 3<&0
+
 # recurse through all sub-repos
-find . -type d -name \*.git | while IFS= read -r GITDIR; do
-       processargs git --git-dir="$GITDIR" --work-tree="${GITDIR%/.git}" "$@"
+status=0
+# TODO is there a better way to identify all sub-repos?
+find . -type d -name \*.git -prune | while IFS= read -r GITDIR; do
+       # TODO I would LIKE to do this, but then some commands (like pull) fail
+       #export GIT_DIR="$GITDIR"
+       #export GIT_WORK_TREE="${GITDIR%/.git}"
+       # so I will have to chdir instead
+
+       ( cd "$GITDIR/.." && processargs git "$@" <&3 3<&- ) # use restored stdin
+       if [ "$?" -gt "$status" ]; then
+               status=$?
+       fi
 done
+exit "$status"