aboutsummaryrefslogtreecommitdiff
path: root/fastforwardotherbranch.sh
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-09-05 16:02:12 +0200
committermarha <marha@users.sourceforge.net>2012-09-05 16:02:12 +0200
commitaf1e359cc622a0c53d5632fb03ef9bd4c17de897 (patch)
treee56865636ac16a957be5091ceb15750f891f7714 /fastforwardotherbranch.sh
parent50fad5cd2be4cd105c99687e224da60233f81645 (diff)
downloadvcxsrv-af1e359cc622a0c53d5632fb03ef9bd4c17de897.tar.gz
vcxsrv-af1e359cc622a0c53d5632fb03ef9bd4c17de897.tar.bz2
vcxsrv-af1e359cc622a0c53d5632fb03ef9bd4c17de897.zip
Added script to fast forward a tracking branch that is not checked out
Diffstat (limited to 'fastforwardotherbranch.sh')
-rw-r--r--fastforwardotherbranch.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/fastforwardotherbranch.sh b/fastforwardotherbranch.sh
new file mode 100644
index 000000000..4b6d1e9a4
--- /dev/null
+++ b/fastforwardotherbranch.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+BRANCH=master
+NEWER=origin/master
+
+if [ $(git symbolic-ref HEAD) = "refs/heads/$BRANCH" ]
+then
+ echo "This doesn't make sense if you're already on the branch '$BRANCH'"
+ echo "Just run: git merge $NEWER"
+ exit 1
+fi
+
+BRANCH_HASH=$(git rev-parse $BRANCH)
+NEWER_HASH=$(git rev-parse $NEWER)
+MERGE_BASE=$(git merge-base $BRANCH_HASH $NEWER_HASH)
+
+if [ "$MERGE_BASE" = "$BRANCH_HASH" ]
+then
+ git update-ref "refs/heads/$BRANCH" "$NEWER_HASH" "$BRANCH_HASH"
+else
+ echo "$BRANCH can't be fast-forwarded to $NEWER"
+ exit 1
+fi