]> git.xonotic.org Git - xonotic/div0-gittools.git/blob - git-recurse
git-recurse: nice tool to recurse through sub-clones
[xonotic/div0-gittools.git] / git-recurse
1 #!/bin/sh
2
3 SEPARATOR=@@
4
5 # TODO this logic should probably rather be in rev-parse itself
6 processarg()
7 {
8         prefix=
9         suffix=
10         case "$1" in
11                 *..*)
12                         first=${1%%..*}
13                         rest=${1#*..}
14                         first=`processarg "$first"`
15                         rest=`processarg "$rest"`
16                         echo "$first..$rest"
17                         ;;
18                 *@\{*)
19                         first=${1%%@\{*}
20                         rest=${1#*@\{}
21                         first=`processarg "$first"`
22                         echo "$first@{$rest"
23                         ;;
24                 *^*)
25                         first=${1%%^*}
26                         rest=${1#*^}
27                         first=`processarg "$first"`
28                         echo "$first^$rest"
29                         ;;
30                 *~*)
31                         first=${1%%~*}
32                         rest=${1#*~}
33                         first=`processarg "$first"`
34                         echo "$first~$rest"
35                         ;;
36                 *:*)
37                         first=${1%%:*}
38                         rest=${1#*:}
39                         first=`processarg "$first"`
40                         echo "$first:$rest"
41                         ;;
42                 ^*)
43                         first=${1#^}
44                         first=`processarg "$first"`
45                         echo "^$first"
46                         ;;
47                 *$SEPARATOR*)
48                         first=${1%%$SEPARATOR*}
49                         rest=${1#*$SEPARATOR}
50                         if git rev-parse "$first" >/dev/null 2>&1; then
51                                 echo "$first"
52                         else
53                                 processarg "$rest"
54                         fi
55                         ;;
56                 *)
57                         echo "$1"
58                         ;;
59         esac
60 }
61 processargs()
62 {
63         first=true
64         for X in "$@"; do
65                 if $first; then
66                         first=false
67                         # clear arg list
68                         set --
69                 fi
70                 set -- "$@" "`processarg "$X"`"
71         done
72         "$@"
73 }
74
75 # recurse through all sub-repos
76 find . -type d -name \*.git | while IFS= read -r GITDIR; do
77         processargs git --git-dir="$GITDIR" --work-tree="${GITDIR%/.git}" "$@"
78 done