Add tools/scripts/merge-forward
authorTim Otten <totten@civicrm.org>
Thu, 11 Apr 2013 06:58:10 +0000 (02:58 -0400)
committerTim Otten <totten@civicrm.org>
Thu, 11 Apr 2013 06:58:10 +0000 (02:58 -0400)
tools/scripts/merge-forward [new file with mode: 0755]

diff --git a/tools/scripts/merge-forward b/tools/scripts/merge-forward
new file mode 100755 (executable)
index 0000000..f7939fd
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/bash
+set -e
+
+RELPATH="$1"
+REMOTE="$2"
+MAINTBRANCH="$3"
+DEVBRANCH="$4"
+TMPBRANCH=$MAINTBRANCH-$DEVBRANCH-$(date "+%Y-%m-%d-%H-%M-%S")
+
+if [ -z "$RELPATH" -o  -z "$REMOTE" -o  -z "$MAINTBRANCH" -o  -z "$DEVBRANCH" ] ; then
+  PROG=$(basename $0)
+  echo "Merge any changes from the maintenance-branch into the development-branch."
+  echo "If there are no conflicts, then push the changes."
+  echo ""
+  echo "Usage: $PROG <relpath> <remote> <maintenance-branch> <development-branch>"
+  echo ""
+  echo "Example: $PROG drupal upstream 7.x-4.3 7.x-master"
+  exit 1
+fi
+
+pushd "$RELPATH" >> /dev/null
+  TMPFILE=$(mktemp)
+
+  set -x
+  git fetch $REMOTE
+  git checkout -b $TMPBRANCH $REMOTE/$DEVBRANCH
+  git merge $REMOTE/$MAINTBRANCH | tee $TMPFILE
+  set +x
+
+  if grep -q CONFLICT "$TMPFILE" ; then
+    echo ""
+    echo "==> Conflicted merge. Please resolve conflicts and then push with:"
+    echo ""
+    echo "git push $REMOTE $TMPBRANCH:$DEVBRANCH"
+  elif grep -q "Already up-to-date." "$TMPFILE" ; then
+    echo ""
+    echo "==> No update needed"
+    echo ""
+  else
+    echo ""
+    echo "==> Clean merge; proceeding with push"
+    echo ""
+    set -x
+    git push $REMOTE $TMPBRANCH:$DEVBRANCH
+    git fetch $REMOTE
+    git checkout $REMOTE/$DEVBRANCH
+    git branch -d $TMPBRANCH
+    set +x
+  fi
+
+  /bin/rm -f "$TMPFILE"
+popd  >> /dev/null