From 75cb85e0cfa66480492b80ada19bd5a02ea12305 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 29 May 2015 18:31:08 +0200 Subject: Add git helper scripts --- README | 22 ++++++++++++++++++++++ branch.sh | 18 ++++++++++++++++++ checkout.sh | 23 +++++++++++++++++++++++ commit.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff.sh | 26 ++++++++++++++++++++++++++ fetch.sh | 18 ++++++++++++++++++ gc.sh | 18 ++++++++++++++++++ merge.sh | 40 ++++++++++++++++++++++++++++++++++++++++ pull.sh | 18 ++++++++++++++++++ push.sh | 31 +++++++++++++++++++++++++++++++ rebase.sh | 23 +++++++++++++++++++++++ remote.sh | 18 ++++++++++++++++++ stash.sh | 27 +++++++++++++++++++++++++++ stat.sh | 18 ++++++++++++++++++ tag.sh | 23 +++++++++++++++++++++++ 15 files changed, 378 insertions(+) create mode 100644 README create mode 100755 branch.sh create mode 100755 checkout.sh create mode 100755 commit.sh create mode 100755 diff.sh create mode 100755 fetch.sh create mode 100755 gc.sh create mode 100755 merge.sh create mode 100755 pull.sh create mode 100755 push.sh create mode 100755 rebase.sh create mode 100755 remote.sh create mode 100755 stash.sh create mode 100755 stat.sh create mode 100755 tag.sh diff --git a/README b/README new file mode 100644 index 0000000..68e1a01 --- /dev/null +++ b/README @@ -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"). 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 diff --git a/diff.sh b/diff.sh new file mode 100755 index 0000000..b952807 --- /dev/null +++ b/diff.sh @@ -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 diff --git a/gc.sh b/gc.sh new file mode 100755 index 0000000..bd9bc5f --- /dev/null +++ b/gc.sh @@ -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 diff --git a/pull.sh b/pull.sh new file mode 100755 index 0000000..d20c704 --- /dev/null +++ b/pull.sh @@ -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 diff --git a/push.sh b/push.sh new file mode 100755 index 0000000..60ac2da --- /dev/null +++ b/push.sh @@ -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 diff --git a/stat.sh b/stat.sh new file mode 100755 index 0000000..8a73bd4 --- /dev/null +++ b/stat.sh @@ -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 diff --git a/tag.sh b/tag.sh new file mode 100755 index 0000000..04a8826 --- /dev/null +++ b/tag.sh @@ -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 -- cgit v1.1