forked from kollerma/git-submodule-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-rcommit
executable file
·102 lines (90 loc) · 2.6 KB
/
git-rcommit
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash -e
## Recursive commit
## accepts the same arguments as commit
## but does a commit in each submodule as well
## read input, display help if necessary
if [[ "$@" == *--help* ]]; then
cat<<EOF
Recursive commit
This command executes a recursive commit. It begins with the innermost
submodules and works its way back. It is recommended to use the option
-a, otherwise the script will not commit the change in a submodule
pointer which changed because of a commit therein. Commit messages can
be supplied using the options -m <message> or -F <file>. See also
"git commit --help".
Usage:
git rcommit [--non-recursive] ...
--non-recursive: do not recurse into submodules
...: same arguments as git-commit
EOF
exit 0;
fi
## from the git mailinglist:
function git
{
LC_MESSAGES=C command git "$@"
}
export git
args=""
recursive=1
a=0
## build quoted $args and check non-recursive and [-a|--all] args
for arg in "$@"
do
## skip --non-recursive
if [[ "$arg" != "--non-recursive" ]]; then
args="$args '$arg'"
else
recursive=0
fi
## check for -a or --all
case "$arg" in
-a|--all)
a=1
;;
--)
;;
--*)
;;
-*) ## option like -qa
if [[ "$arg" == *a* ]]; then
a=1
fi
;;
esac
done
## commit in submodules first
if [[ $recursive -eq 1 ]]; then
if [ -f $(git rev-parse --show-toplevel)/.gitmodules ]; then
#git submodule --quiet foreach "git rcommit \"$COMMIT_ARGS\"" || exit 1
CMD='cd "$1"; git rcommit '"$args"
git submodule --quiet foreach 'echo "$toplevel/$path"' |
xargs -r -n1 -P1 bash -c "$CMD" xargs || exit 1
fi
fi
if [ $a -ne 1 ] && ! (git check-clean --unstaged --unmerged --exit-code --ignore-submodules=dirty) ; then
cat >&2 <<EOF
Warning in $PWD:
Unstaged changes to files under version control.
To add, use option -a to stage or add files manually with git add <file>.
EOF
fi
## commit if dirty (or --allow-empty is given)
if [[ "$args" == *--allow-empty* ]] || ([ $a -eq 1 ] && ! (git check-clean --unstaged --unmerged --exit-code --ignore-submodules=dirty)) || ! (git check-clean --uncommitted --exit-code --ignore-submodules=dirty) ;
then
## check for detached head
if ! (git symbolic-ref -q HEAD > /dev/null) ; then
cat >&2 <<EOF
Error in $PWD:
Refused to commit in detached head state.
See "git attach-head --help" for help on attaching the HEAD.
EOF
exit 1
fi
echo "Committing in $PWD..."
bash -c "git commit -q $args"
if [ -f $(git rev-parse --show-toplevel)/.gitmodules ]; then
## Syncronize submodules if necessary
git converge-submodules -q
fi
fi