scripts for managing demo sites and their pristines
[civicrm-core.git] / tools / scripts / merge-forward
1 #!/bin/bash
2 set -e
3
4 RELPATH="$1"
5 REMOTE="$2"
6 MAINTBRANCH="$3"
7 DEVBRANCH="$4"
8 TMPBRANCH=$MAINTBRANCH-$DEVBRANCH-$(date "+%Y-%m-%d-%H-%M-%S")
9
10 if [ -z "$RELPATH" -o -z "$REMOTE" -o -z "$MAINTBRANCH" -o -z "$DEVBRANCH" ] ; then
11 PROG=$(basename $0)
12 echo "Merge any changes from the maintenance-branch into the development-branch."
13 echo "If there are no conflicts, then push the changes."
14 echo ""
15 echo "Usage: $PROG <relpath> <remote> <maintenance-branch> <development-branch>"
16 echo ""
17 echo "Example: $PROG drupal upstream 7.x-4.3 7.x-master"
18 exit 1
19 fi
20
21 pushd "$RELPATH" >> /dev/null
22 TMPFILE=$(mktemp)
23
24 set -x
25 git fetch $REMOTE
26 git checkout -b $TMPBRANCH $REMOTE/$DEVBRANCH
27 git merge $REMOTE/$MAINTBRANCH | tee $TMPFILE
28 set +x
29
30 if grep -q CONFLICT "$TMPFILE" ; then
31 echo ""
32 echo "==> Conflicted merge. Please resolve conflicts and then push with:"
33 echo ""
34 echo "git push $REMOTE $TMPBRANCH:$DEVBRANCH"
35 elif grep -q "Already up-to-date." "$TMPFILE" ; then
36 echo ""
37 echo "==> No update needed"
38 echo ""
39 else
40 echo ""
41 echo "==> Clean merge; proceeding with push"
42 echo ""
43 set -x
44 git push $REMOTE $TMPBRANCH:$DEVBRANCH
45 git fetch $REMOTE
46 git checkout $REMOTE/$DEVBRANCH
47 git branch -d $TMPBRANCH
48 set +x
49 fi
50
51 /bin/rm -f "$TMPFILE"
52 popd >> /dev/null