-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgit-exec-all.sh
More file actions
executable file
·62 lines (55 loc) · 1.1 KB
/
git-exec-all.sh
File metadata and controls
executable file
·62 lines (55 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
function usage() {
cat >&2 <<EOF
Usage: $0 [-v] [-b BASEDIR] [git subcommand]
If no subcommand is specified, 'branch' is invoked.
EOF
exit 1
}
while getopts "b:dvh" flag; do
case "$flag" in
b) BASE="$OPTARG";;
v) VERBOSE=1;;
d) set -o xtrace;;
h) usage;;
\?) usage;;
esac
done
shift $(( $OPTIND - 1 ))
function exec_branch_show() {
local d=$1
local p=$(pwd)
local ref branch head base
cd $d
base=$(basename $d)
if cat .git/HEAD | grep 'ref:' >/dev/null; then
ref=$(git symbolic-ref HEAD)
branch=${ref##refs/heads/}
head=$(git show-branch --sha1-name $branch | cut -d ' ' -f 1)
else
branch=
head=$(cat .git/HEAD)
fi
printf "%-30s: %s %s\n" $base $head $branch
if [ -n "$VERBOSE" ]; then
git branch | grep -vE "^\* $branch$"
fi
cd $p
}
function exec_command() {
local d=$1
shift
local p=$(pwd)
cd $d
echo "----- $d -----"
git $*
cd $p
}
for d in `find $BASE -type d -name .git | sort`; do
d=$(dirname $d) # strip trailing "/.git"
if [ -n "$1" ]; then
exec_command $d $*
else
exec_branch_show $d
fi
done