Skip to content

Instantly share code, notes, and snippets.

@whitekid
Last active December 17, 2015 04:49
Show Gist options
  • Save whitekid/5553143 to your computer and use it in GitHub Desktop.
Save whitekid/5553143 to your computer and use it in GitHub Desktop.
git submodule commit / push script
#!/bin/bash
# submodule commit/push
set -e
submodules=`git submodule status | awk '{print $2}'`
command="$1"
shift
args="$@"
function apply_here(){
case $command in
commit)
! git status | grep -q '^nothing to commit'
;;
push)
git status | grep -q '# Your branch is ahead of '
;;
*)
echo "command $command not supported"
exit
;;
esac
}
for submodule in $submodules; do
echo "==== submodule $submodule ===="
pushd `pwd` > /dev/null
cd $submodule
if apply_here; then
popd > /dev/null
continue
fi
git $command $args
popd > /dev/null
done
# vim: ai nu aw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment