Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 97 lines (84 sloc) 2.45 KB
#!/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
args=$@
## commit in submodules first
if [[ "$args" != *--non-recursive* ]]; 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
else
## remove --non-recursive from $args
args=${args//--non-recursive/}
fi
## check for --all or -a argument
a=0
while test $# != 0
do
case "$1" in
-a|--all)
a=1
break
;;
--)
break
;;
--*)
;;
-*) ## option like -qa
if [[ "$1" == *a* ]]; then
a=1
break
fi
;;
esac
shift
done
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.
Use "git rcheckout <branchname>" to attach HEAD.
List branches with "git branch -v".
EOF
exit 1
fi
echo "Committing in $PWD..."
git commit -q "$args"
if [ -f $(git rev-parse --show-toplevel)/.gitmodules ]; then
## Syncronize submodules if necessary
git converge-submodules -q
fi
fi