aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README22
-rwxr-xr-xbranch.sh18
-rwxr-xr-xcheckout.sh23
-rwxr-xr-xcommit.sh55
-rwxr-xr-xdiff.sh26
-rwxr-xr-xfetch.sh18
-rwxr-xr-xgc.sh18
-rwxr-xr-xmerge.sh40
-rwxr-xr-xpull.sh18
-rwxr-xr-xpush.sh31
-rwxr-xr-xrebase.sh23
-rwxr-xr-xremote.sh18
-rwxr-xr-xstash.sh27
-rwxr-xr-xstat.sh18
-rwxr-xr-xtag.sh23
15 files changed, 378 insertions, 0 deletions
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<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
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