Created
November 8, 2010 10:54
-
-
Save motemen/667573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
root=`git rev-parse --show-toplevel` | |
echo=/bin/echo | |
git ls-files --stage | grep '^160000 ' | | |
while read mode sha1 stage path | |
do | |
$echo -n "Submodule path '$path': "; | |
cd $root; cd $path | |
track_branch=`git config --file $root/.gitmodules submodule.$path.track` | |
if [ -z "$track_branch" ]; then | |
$echo 'tracking branch not found; skip.' | |
else | |
$echo -n "track $track_branch... " | |
current_branch=`git symbolic-ref --quiet HEAD | sed 's#^refs/heads/##'` | |
local_branch=${track_branch#*/} | |
if [ "$current_branch" = "$local_branch" ]; then | |
$echo "already on $current_branch." | |
git pull | |
else | |
if git rev-parse --quiet --verify $local_branch > /dev/null; then | |
$echo "checkout existing branch $local_branch." | |
git checkout $local_branch && git pull | |
else | |
$echo "start tracking $track_branch." | |
git fetch && git checkout --track $track_branch | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment