]> git.rm.cloudns.org Git - xonotic/div0-gittools.git/commitdiff
git-recurse: nice tool to recurse through sub-clones
authorRudolf Polzer <divverent@alientrap.org>
Wed, 20 Oct 2010 14:09:40 +0000 (16:09 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Wed, 20 Oct 2010 14:09:40 +0000 (16:09 +0200)
git-recurse [new file with mode: 0755]

diff --git a/git-recurse b/git-recurse
new file mode 100755 (executable)
index 0000000..e77c632
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+SEPARATOR=@@
+
+# TODO this logic should probably rather be in rev-parse itself
+processarg()
+{
+       prefix=
+       suffix=
+       case "$1" in
+               *..*)
+                       first=${1%%..*}
+                       rest=${1#*..}
+                       first=`processarg "$first"`
+                       rest=`processarg "$rest"`
+                       echo "$first..$rest"
+                       ;;
+               *@\{*)
+                       first=${1%%@\{*}
+                       rest=${1#*@\{}
+                       first=`processarg "$first"`
+                       echo "$first@{$rest"
+                       ;;
+               *^*)
+                       first=${1%%^*}
+                       rest=${1#*^}
+                       first=`processarg "$first"`
+                       echo "$first^$rest"
+                       ;;
+               *~*)
+                       first=${1%%~*}
+                       rest=${1#*~}
+                       first=`processarg "$first"`
+                       echo "$first~$rest"
+                       ;;
+               *:*)
+                       first=${1%%:*}
+                       rest=${1#*:}
+                       first=`processarg "$first"`
+                       echo "$first:$rest"
+                       ;;
+               ^*)
+                       first=${1#^}
+                       first=`processarg "$first"`
+                       echo "^$first"
+                       ;;
+               *$SEPARATOR*)
+                       first=${1%%$SEPARATOR*}
+                       rest=${1#*$SEPARATOR}
+                       if git rev-parse "$first" >/dev/null 2>&1; then
+                               echo "$first"
+                       else
+                               processarg "$rest"
+                       fi
+                       ;;
+               *)
+                       echo "$1"
+                       ;;
+       esac
+}
+processargs()
+{
+       first=true
+       for X in "$@"; do
+               if $first; then
+                       first=false
+                       # clear arg list
+                       set --
+               fi
+               set -- "$@" "`processarg "$X"`"
+       done
+       "$@"
+}
+
+# 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}" "$@"
+done