province abbreviation patch - issue 724
[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 ## OS X: mktemp requires "-t prefix" argument
23 ## GNU: mktemp accepts optional -t pattern" argument
24 ## The string "merge-forward-XXXXXX" works as a prefix or pattern
25 TMPFILE=$(mktemp -t merge-forward-XXXXXX)
26
27 set -x
28 git fetch $REMOTE
29 git checkout -b $TMPBRANCH $REMOTE/$DEVBRANCH
30 git merge $REMOTE/$MAINTBRANCH | tee $TMPFILE
31 set +x
32
33 if grep -q CONFLICT "$TMPFILE" ; then
34 echo ""
35 echo "==> Conflicted merge. Please resolve conflicts and then push with:"
36 echo ""
37 echo "git push $REMOTE $TMPBRANCH:$DEVBRANCH"
38 elif grep -q "Already up-to-date." "$TMPFILE" ; then
39 echo ""
40 echo "==> No update needed"
41 echo ""
42 else
43 echo ""
44 echo "==> Clean merge; proceeding with push"
45 echo ""
46 set -x
47 git push $REMOTE $TMPBRANCH:$DEVBRANCH
48 git fetch $REMOTE
49 git checkout $REMOTE/$DEVBRANCH
50 git branch -d $TMPBRANCH
51 set +x
52 fi
53
54 /bin/rm -f "$TMPFILE"
55 popd >> /dev/null