Skip to content

Instantly share code, notes, and snippets.

@spiderr
Created July 4, 2010 18:07
Show Gist options
  • Save spiderr/463628 to your computer and use it in GitHub Desktop.
Save spiderr/463628 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Shell Script for super-respositores that executes git on all sub-repositories
# Homepage at http://www.bitweaver.org/wiki/supergit
# Licensed under the GPL
# Authors: github.com/spiderr
function usage {
appName=`basename $0`
echo "Welcome to $appName. It acts on all directories in your project as if they were sub-respositories. For most commands, you simply type what you would normally for git, however you simply type $appName with desired parameters in the super-repository root of your project. For example:"
echo "-- To clone, type '$appName git@github.com:bitweaver/bitweaver.git -b DEV testbw' which will clone, then intiliaze + update submodules and checkout the master branch for each submodule"
echo "-- To diff, in the super repo root, type '$appName diff'"
echo "-- To commit, in the super repo root, type '$appName commit -a'"
echo "-- To pull, in the super repo root, type '$appName pull'"
echo "-- To push, in the super repo root, type '$appName push origin'"
}
function apush() {
var=$1; shift;
if [ -n "$var" ]; then
eval "$var+=(\"\$@\")"
fi
}
function git_exec_subs {
rootDir=$1
shift
echo "executing on all subrepositories: git $@"
for repo in $(find $rootDir -name ".git" -exec dirname {} \;); do
echo "# cd $repo; git $@"
cd "$repo"; git $@
done
}
case "$1" in
"clone")
eval moduleName=\$$#
moduleName=`basename $moduleName`
cloneParams=$@
if [ -z $moduleName ]; then
moduleName='source';
cloneParams="$cloneParams $moduleName"
fi
TOP_DIR="`pwd`/$moduleName";
echo $TOP_DIR
echo $1 to $moduleName;
git $cloneParams
cd $TOP_DIR
git submodule init
git submodule update
for repo in $(find $TOP_DIR -name ".git" -exec dirname {} \;); do
git_exec_subs $repo submodule init
git_exec_subs $repo submodule update
git_exec_subs $repo checkout master
done
;;
"")
usage;
;;
*)
git_exec_subs `pwd` $@;
;;
esac
Copy link

ghost commented Jul 4, 2010

    for i in `find -name ".git" -exec dirname {} \;`; do pushd $i ; git pull ; popd ; done

Copy link

ghost commented Jul 4, 2010

    for i in `find -name ".git" -exec dirname {} \;`; do pushd $i ; git pull ; popd ; done

@spiderr
Copy link
Author

spiderr commented Jul 4, 2010

Thanks Markus, the find for .git dirs is a much better plan, and get's all nested sub-repos nicely regardless of depth. I suppose this only handles one level of nested sub-repos. Somone smarter than I can figure out some awesome bash recursion to handle that efficiently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment