From 1853dea1b9277f2d5a8911bd2d20277158e221b7 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 11 Mar 2013 16:06:32 +0200 Subject: Script for merging changes from a bugfix branch into master (#11299) * Supports "Merge: no" for changesets which should be skipped, e.g. release notes updates. * Supports "Merge: manual" which will causes the merge to stop, requiring somebody to manually merge to change before continuing Change-Id: If5d1291ec77f4c1e31b3afb8420a45ecceedfa15 --- scripts/automerge7.sh | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 scripts/automerge7.sh (limited to 'scripts') diff --git a/scripts/automerge7.sh b/scripts/automerge7.sh new file mode 100755 index 0000000000..8f8ed9a785 --- /dev/null +++ b/scripts/automerge7.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +FROM=origin/7.0 +TO=master +PUSH="origin HEAD:refs/for/master" + +show() { + sCommit=$1 + if [ "$sCommit" == "" ] + then + echo "show() missing commit id" + exit 1 + fi + git show -s $sCommit +} +merge() { + mCommit=$1 + if [ "$mCommit" == "" ] + then + echo "merge() missing commit id" + exit 1 + fi + +# echo "merge($mCommit)" + + git merge $mCommit $2 + if [ "$?" != "0" ] + then + echo "Merge failed for commit $mCommit" + echo "Manual merge is needed" + exit 2 + fi + # Add a change id using git hook + git commit --amend --no-edit + +} + +pushMerged() { +# echo "pushMerged()" + git push $PUSH + if [ "$?" != "0" ] + then + echo "Push failed!" + exit 2 + fi +} + +maybe_commit_and_push() { +# echo "maybe_commit_and_push()" + cpCommit=$1 + if [ "$cpCommit" == "" ] + then + # Nothing to merge currently + return + fi +# echo "maybe_commit_and_push: Merging $cpCommit" + merge $cpCommit + pushMerged +} + +git checkout $TO +git pull --rebase + +pending=`git log $TO..$FROM --reverse|grep "^commit "|sed "s/commit //"` + +pendingCommit= +for commit in $pending +do + echo "Checking $commit..." + mergeDirective=`git log -n 1 --format=%B $commit|grep "^Merge:"|sed "s/Merge: //"` + if [ "$mergeDirective" == "" ] + then + pendingCommit=$commit + elif [ "$mergeDirective" == "no" ] + then + maybe_commit_and_push $pendingCommit + pendingCommit= + echo + echo "Doing a no-op merge for $commit because of Merge: no" + # Do a no-op merge + git merge $commit -s ours + pushMerged + elif [ "$mergeDirective" == "manual" ] + then + maybe_commit_and_push $pendingCommit + pendingCommit= + echo + echo "Stopping merge at $commit (merge: manual)" + echo "The following commit must be manually merged." + show $commit + exit 3 + else + maybe_commit_and_push $pendingCommit + pendingCommit= + echo + echo "Commit $commit contains an unknown merge directive, Merge: $mergeDirective" + echo "Stopping merge." + show $commit + exit 3 + fi +done + +# Push any pending merges +maybe_commit_and_push $pendingCommit -- cgit v1.2.3 From 33e114bd3bb6e764e0e503a69c305ec4322aaa6a Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 23 Apr 2013 15:03:24 +0300 Subject: Ensure no-op merges get a change id Change-Id: Icda1db985b3a0654fa1274e700cddfe2f990df12 --- scripts/automerge7.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/automerge7.sh b/scripts/automerge7.sh index 8f8ed9a785..d64f98a185 100755 --- a/scripts/automerge7.sh +++ b/scripts/automerge7.sh @@ -76,9 +76,12 @@ do maybe_commit_and_push $pendingCommit pendingCommit= echo - echo "Doing a no-op merge for $commit because of Merge: no" + echo "Doing a no-op merge because of Merge: no for $commit" + git log -n 1 --format=%B $commit + echo # Do a no-op merge git merge $commit -s ours + git commit --amend --no-edit pushMerged elif [ "$mergeDirective" == "manual" ] then -- cgit v1.2.3 From 5a5066a8c3f229874f310008ef4cd33e4fae55de Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 23 Apr 2013 16:27:37 +0300 Subject: Include commit id and message in merge commit message Change-Id: I2557eddcb4fbd4fd1ec5c608a0d73c7fa1b243b6 --- scripts/automerge7.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/automerge7.sh b/scripts/automerge7.sh index d64f98a185..33f0462267 100755 --- a/scripts/automerge7.sh +++ b/scripts/automerge7.sh @@ -53,48 +53,62 @@ maybe_commit_and_push() { # Nothing to merge currently return fi + cpCommitMsg=$2 + if [ "$cpCommitMsg" == "" ] + then + echo "Internal error, no commit message passed to maybe_commit_and_push()" + exit 1; + fi # echo "maybe_commit_and_push: Merging $cpCommit" merge $cpCommit + echo -e "Merge changes from $FROM\n\n$cpCommitMsg"|git commit --amend -F - pushMerged } git checkout $TO -git pull --rebase +git fetch pending=`git log $TO..$FROM --reverse|grep "^commit "|sed "s/commit //"` pendingCommit= +pendingCommitMessage= for commit in $pending do echo "Checking $commit..." mergeDirective=`git log -n 1 --format=%B $commit|grep "^Merge:"|sed "s/Merge: //"` + commitMsg=`git log -n 1 --format=oneline --abbrev-commit $commit` if [ "$mergeDirective" == "" ] then pendingCommit=$commit + pendingCommitMessage=$pendingCommitMessage"$commitMsg\n" + echo pendingCommitMessage: $pendingCommitMessage elif [ "$mergeDirective" == "no" ] then - maybe_commit_and_push $pendingCommit + maybe_commit_and_push $pendingCommit "$pendingCommitMessage" pendingCommit= + pendingCommitMessage= echo echo "Doing a no-op merge because of Merge: no for $commit" git log -n 1 --format=%B $commit echo # Do a no-op merge git merge $commit -s ours - git commit --amend --no-edit + echo -e "No-op merge from $FROM\n\n$commitMsg"|git commit --amend -F - pushMerged elif [ "$mergeDirective" == "manual" ] then - maybe_commit_and_push $pendingCommit + maybe_commit_and_push $pendingCommit "$pendingCommitMessage" pendingCommit= + pendingCommitMessage= echo echo "Stopping merge at $commit (merge: manual)" echo "The following commit must be manually merged." show $commit exit 3 else - maybe_commit_and_push $pendingCommit + maybe_commit_and_push $pendingCommit "$pendingCommitMessage" pendingCommit= + pendingCommitMessage= echo echo "Commit $commit contains an unknown merge directive, Merge: $mergeDirective" echo "Stopping merge." @@ -104,4 +118,4 @@ do done # Push any pending merges -maybe_commit_and_push $pendingCommit +maybe_commit_and_push $pendingCommit "$pendingCommitMessage" -- cgit v1.2.3 From 888d34c55c15f244f0d68f82ae2c46fae24da630 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 6 May 2013 14:24:04 +0300 Subject: Update merge script to merge 7.0 to 7.1 * Refactor so that source and target branches are defined in variables in the beginning of the script. * Pass a dummy commit message to the merge to avoid opening an editor while running the script Merge: manual Change-Id: I76c001b3bfcfd2dbb1ce2e9ec1b730641df31a77 --- scripts/automerge7.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/automerge7.sh b/scripts/automerge7.sh index 33f0462267..524b0ff912 100755 --- a/scripts/automerge7.sh +++ b/scripts/automerge7.sh @@ -1,8 +1,10 @@ #!/bin/bash -FROM=origin/7.0 -TO=master -PUSH="origin HEAD:refs/for/master" +FROM=7.0 +TO=7.1 + +FROM_HEAD=origin/$FROM +PUSH="origin HEAD:refs/for/$TO" show() { sCommit=$1 @@ -23,7 +25,7 @@ merge() { # echo "merge($mCommit)" - git merge $mCommit $2 + git merge -m "Should be overwritten by merge script" $mCommit $2 if [ "$?" != "0" ] then echo "Merge failed for commit $mCommit" @@ -61,14 +63,14 @@ maybe_commit_and_push() { fi # echo "maybe_commit_and_push: Merging $cpCommit" merge $cpCommit - echo -e "Merge changes from $FROM\n\n$cpCommitMsg"|git commit --amend -F - + echo -e "Merge changes from $FROM_HEAD\n\n$cpCommitMsg"|git commit --amend -F - pushMerged } git checkout $TO git fetch -pending=`git log $TO..$FROM --reverse|grep "^commit "|sed "s/commit //"` +pending=`git log $TO..$FROM_HEAD --reverse|grep "^commit "|sed "s/commit //"` pendingCommit= pendingCommitMessage= @@ -93,7 +95,7 @@ do echo # Do a no-op merge git merge $commit -s ours - echo -e "No-op merge from $FROM\n\n$commitMsg"|git commit --amend -F - + echo -e "No-op merge from $FROM_HEAD\n\n$commitMsg"|git commit --amend -F - pushMerged elif [ "$mergeDirective" == "manual" ] then -- cgit v1.2.3 From d09b586ecee2c178882c917546d6d6cb6600fa85 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 6 May 2013 14:54:41 +0300 Subject: Don't start merging if there are uncommitted changes Change-Id: Ic1211e914162be6910caae10fcfc7deebc5b4ad3 --- scripts/automerge7.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'scripts') diff --git a/scripts/automerge7.sh b/scripts/automerge7.sh index 524b0ff912..ea83b2e52c 100755 --- a/scripts/automerge7.sh +++ b/scripts/automerge7.sh @@ -67,6 +67,14 @@ maybe_commit_and_push() { pushMerged } +nothingToCommit=`git status | grep "nothing to commit"` +if [ "$nothingToCommit" == "" ] +then + git status + echo "Can not merge when there are unstaged changes." + exit 1; +fi + git checkout $TO git fetch -- cgit v1.2.3