aboutsummaryrefslogtreecommitdiff
path: root/fastforwardotherbranch.sh
diff options
context:
space:
mode:
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