diff options
-rw-r--r-- | README | 22 | ||||
-rwxr-xr-x | branch.sh | 18 | ||||
-rwxr-xr-x | checkout.sh | 23 | ||||
-rwxr-xr-x | commit.sh | 55 | ||||
-rwxr-xr-x | diff.sh | 26 | ||||
-rwxr-xr-x | fetch.sh | 18 | ||||
-rwxr-xr-x | gc.sh | 18 | ||||
-rwxr-xr-x | merge.sh | 40 | ||||
-rwxr-xr-x | pull.sh | 18 | ||||
-rwxr-xr-x | push.sh | 31 | ||||
-rwxr-xr-x | rebase.sh | 23 | ||||
-rwxr-xr-x | remote.sh | 18 | ||||
-rwxr-xr-x | stash.sh | 27 | ||||
-rwxr-xr-x | stat.sh | 18 | ||||
-rwxr-xr-x | tag.sh | 23 |
15 files changed, 378 insertions, 0 deletions
@@ -0,0 +1,22 @@ +Set of git helper scripts for working with multi-repository projects. + +Setup: + +1. There needs to be etc/git/modules file that defines all the + repositories. + +2. You would normall checkout the repository with these scripts + next to your other repositories in the project and then add + it to the modules file above (so that when you do ./pull.sh, + you get script updates as well). + +3. In the root of your project (i.e., where you have git, etc, + and your project-specific repositories), create sym-links + to the scripts. E.g., + + ln -s git/*.sh ./ + + You may want to remove the symlink to stash.sh so that stat.sh + (the most frequently ran command) auto-completes on 's' (i.e., + you run it by typing "./a<TAB><ENTER>"). In this case you would + run stash.sh as git/shash.sh. diff --git a/branch.sh b/branch.sh new file mode 100755 index 0000000..8b2dda2 --- /dev/null +++ b/branch.sh @@ -0,0 +1,18 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +for i in $modules; do + echo "branch $i" 1>&2 + cd $i + git branch $* + + if [ $? -ne 0 ]; then + echo "branch FAILED" 1>&2 + exit 1 + fi + + cd $wd +done diff --git a/checkout.sh b/checkout.sh new file mode 100755 index 0000000..cb51879 --- /dev/null +++ b/checkout.sh @@ -0,0 +1,23 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +if [ "$1" = "" ]; then + echo "branch name expected" 1>&2 + exit 1 +fi + +for i in $modules; do + echo "checkout $i" 1>&2 + cd $i + git checkout $* + + if [ $? -ne 0 ]; then + echo "checkout FAILED" 1>&2 + exit 1 + fi + + cd $wd +done diff --git a/commit.sh b/commit.sh new file mode 100755 index 0000000..6a0e401 --- /dev/null +++ b/commit.sh @@ -0,0 +1,55 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +if [ "$1" = "-i" ]; then + add=n +else + add=y +fi + +if [ "$EDITOR" = "" ]; then + echo "no editor specified with the EDITOR variable" 1>&2 + exit 1 +fi + +msg_file=`mktemp -p /tmp` +$EDITOR "$msg_file" + +if [ $? -ne 0 ]; then + echo "$EDITOR failed" 1>&2 + rm -f $msg_file + exit 1 +fi + +if test ! -s "$msg_file"; then + echo "commit message is empty" 1>&2 + rm -f $msg_file + exit 1 +fi + +for i in $modules; do + echo "commit $i" 1>&2 + cd $i + if [ "$add" = "y" ]; then + git add . + + if [ $? -ne 0 ]; then + echo "add FAILED" 1>&2 + exit 1 + fi + + fi + git commit -F $msg_file + +# if [ $? -ne 0 ]; then +# echo "commit FAILED" 1>&2 +# exit 1 +# fi + + cd $wd +done + +rm -f $msg_file @@ -0,0 +1,26 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +for i in $modules; do + echo "diff $i" 1>&2 + cd $i + + git --no-pager diff + + if [ $? -ne 0 ]; then + echo "diff FAILED" 1>&2 + exit 1 + fi + + git --no-pager diff --check + + if [ $? -ne 0 ]; then + echo "diff --check FAILED" 1>&2 + exit 1 + fi + + cd $wd +done diff --git a/fetch.sh b/fetch.sh new file mode 100755 index 0000000..d41278a --- /dev/null +++ b/fetch.sh @@ -0,0 +1,18 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +for i in $modules; do + echo "fetch $i" 1>&2 + cd $i + git fetch $* + + if [ $? -ne 0 ]; then + echo "fetch FAILED" 1>&2 + exit 1 + fi + + cd $wd +done @@ -0,0 +1,18 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +for i in $modules; do + echo "gc $i" 1>&2 + cd $i + git gc + + if [ $? -ne 0 ]; then + echo "gc FAILED" 1>&2 + exit 1 + fi + + cd $wd +done diff --git a/merge.sh b/merge.sh new file mode 100755 index 0000000..50ed00a --- /dev/null +++ b/merge.sh @@ -0,0 +1,40 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +if [ "$1" = "" ]; then + echo "source branch name expected" 1>&2 + exit 1 +fi + +for i in $modules; do + echo "merge $i" 1>&2 + cd $i + + br=`git symbolic-ref -q HEAD` + br=`echo $br | sed -e 's%^refs/heads/%%'` + + # Only allow fast-forward merges into master. + # + if [ "$br" = "master" ]; then + git merge --ff-only $* + else + git merge $* + fi + + if [ $? -ne 0 ]; then + echo 1>&2 + echo "merge FAILED" 1>&2 + echo 1>&2 + + # Merge failures (conflicts) into non-master branches are ok. + # + if [ "$br" = "master" ]; then + exit 1 + fi + fi + + cd $wd +done @@ -0,0 +1,18 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +for i in $modules; do + echo "pull $i" 1>&2 + cd $i + git pull $* + + if [ $? -ne 0 ]; then + echo "pull FAILED" 1>&2 + exit 1 + fi + + cd $wd +done @@ -0,0 +1,31 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` +br=$1 + +for i in $modules; do + echo "push $i" 1>&2 + cd $i + + if [ -z "$1" ]; then + br=`git symbolic-ref -q HEAD` + br=`echo $br | sed -e 's%^refs/heads/%%'` + fi + + # Also push tags if we are pushing master. + # + if [ "$br" = "master" ]; then + git push --tags origin master + else + git push $ops origin $1 + fi + + if [ $? -ne 0 ]; then + echo "push FAILED" 1>&2 + exit 1 + fi + + cd $wd +done diff --git a/rebase.sh b/rebase.sh new file mode 100755 index 0000000..bad9f65 --- /dev/null +++ b/rebase.sh @@ -0,0 +1,23 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +if [ "$1" = "" ]; then + echo "source branch name expected" 1>&2 + exit 1 +fi + +for i in $modules; do + echo "rebase $i" 1>&2 + cd $i + git rebase $* + + if [ $? -ne 0 ]; then + echo "rebase FAILED" 1>&2 + exit 1 + fi + + cd $wd +done diff --git a/remote.sh b/remote.sh new file mode 100755 index 0000000..a31ce34 --- /dev/null +++ b/remote.sh @@ -0,0 +1,18 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +for i in $modules; do + echo "remote $i" 1>&2 + cd $i + git remote $* + + if [ $? -ne 0 ]; then + echo "remote FAILED" 1>&2 + exit 1 + fi + + cd $wd +done diff --git a/stash.sh b/stash.sh new file mode 100755 index 0000000..999f37e --- /dev/null +++ b/stash.sh @@ -0,0 +1,27 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +for i in $modules; do + echo "stash $i" 1>&2 + cd $i + + if [ "$1" = "pop" -o "$1" = "apply" ]; then + l=`git stash list` + if [ -z "$l" ]; then + cd $wd + continue + fi + fi + + git stash $* + + if [ $? -ne 0 ]; then + echo "stash FAILED" 1>&2 + exit 1 + fi + + cd $wd +done @@ -0,0 +1,18 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +for i in $modules; do + echo "stat $i" 1>&2 + cd $i + git status + + if [ $? -ne 0 ]; then + echo "stat FAILED" 1>&2 + exit 1 + fi + + cd $wd +done @@ -0,0 +1,23 @@ +#! /bin/sh + +. etc/git/modules + +wd=`pwd` + +if [ "$1" = "" ]; then + echo "missing version" 1>&2 + exit 1 +fi + +for i in $modules; do + echo "tag $i" 1>&2 + cd $i + git tag -a $1 -m "Tag version $1" + + if [ $? -ne 0 ]; then + echo "tag FAILED" 1>&2 + exit 1 + fi + + cd $wd +done |