From 23b93659967d82494207e8804b8091cb031126f6 Mon Sep 17 00:00:00 2001 From: Remi Bergsma Date: Mon, 24 Aug 2015 11:52:03 +0200 Subject: [PATCH 1/4] Improve error/help message in case of missing git remote --- tools/git/git-pr | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/git/git-pr b/tools/git/git-pr index 0dca134da19..48b81685165 100755 --- a/tools/git/git-pr +++ b/tools/git/git-pr @@ -47,6 +47,7 @@ fi # Check the arguments if [ -z ${prId} ]; then echo "Usage: git pr pool-request-number [ --force ]" + echo "For instructions, see: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61311655" clean_up_and_exit 1 fi @@ -178,8 +179,16 @@ fi github_remote=$(git remote -v | grep "apache/cloudstack.git" | head -n 1 | cut -f1) if [ ${#github_remote} -eq 0 ]; then echo "ERROR: We couldn't find a git remote pointing to 'apache/cloudstack.git' to merge the PR from." - echo "INFO: Current remotes:" + echo "INFO: Currently, your configured remotes are:" + echo "INFO: ***********************************************************************************" git remote -v + echo "INFO: ***********************************************************************************" + echo "INFO: To merge a PR, we need access to two remotes: " + echo "INFO: 1. Read-only access to GitHub mirror" + echo "INFO: 2. Read/write access to Apache git" + echo "INFO: Please add a remote like this: 'git remote add github https://github.com/apache/cloudstack.git'" + echo "INFO: For more help, visit: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61311655" + echo "INFO: Once done, run this script again." clean_up_and_exit 1 fi From fed5c2b06a7d7aa5d9715ab1430492ab3146a4fc Mon Sep 17 00:00:00 2001 From: Remi Bergsma Date: Mon, 24 Aug 2015 11:59:24 +0200 Subject: [PATCH 2/4] make it work with any Apache repository mirrored on GitHub --- tools/git/git-pr | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/git/git-pr b/tools/git/git-pr index 48b81685165..49eee799e97 100755 --- a/tools/git/git-pr +++ b/tools/git/git-pr @@ -47,6 +47,7 @@ fi # Check the arguments if [ -z ${prId} ]; then echo "Usage: git pr pool-request-number [ --force ]" + echo "Works for any Apache repository mirrored on GitHub'" echo "For instructions, see: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61311655" clean_up_and_exit 1 fi @@ -54,13 +55,14 @@ fi # Vars we need jsonTmp="${PWD}/${prId}.json" tmpMessageFile="${PWD}/.git-tmp-message.txt" +repoName=$(basename `git rev-parse --show-toplevel`) # We need UTF-8 to support the GitHub '...' 3-dots-in-1-char, for example. export LANG="en_EN.UTF-8" if [ "${prId}" -eq "${prId}" 2>/dev/null ]; then # Get json data from Github API - curl -s https://api.github.com/repos/apache/cloudstack/pulls/${prId} > ${jsonTmp} + curl -s https://api.github.com/repos/apache/${repoName}/pulls/${prId} > ${jsonTmp} else echo "ERROR: Pull-request id must be an integer, not '${prId}'" clean_up_and_exit 1 @@ -176,9 +178,9 @@ elif [ "${prMergeableState}" != "clean" ] && [ ${force} -eq 1 ]; then echo "WARNING: You used --force to merge a PR with non-clean merge state '${prMergeableState}'." fi -github_remote=$(git remote -v | grep "apache/cloudstack.git" | head -n 1 | cut -f1) +github_remote=$(git remote -v | grep -E "apache/${repoName}(.git)?" | head -n 1 | cut -f1) if [ ${#github_remote} -eq 0 ]; then - echo "ERROR: We couldn't find a git remote pointing to 'apache/cloudstack.git' to merge the PR from." + echo "ERROR: We couldn't find a git remote pointing to 'apache/${repoName}.git' to merge the PR from." echo "INFO: Currently, your configured remotes are:" echo "INFO: ***********************************************************************************" git remote -v @@ -186,13 +188,13 @@ if [ ${#github_remote} -eq 0 ]; then echo "INFO: To merge a PR, we need access to two remotes: " echo "INFO: 1. Read-only access to GitHub mirror" echo "INFO: 2. Read/write access to Apache git" - echo "INFO: Please add a remote like this: 'git remote add github https://github.com/apache/cloudstack.git'" + echo "INFO: Please add a remote like this: 'git remote add github https://github.com/apache/${repoName}.git'" echo "INFO: For more help, visit: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61311655" echo "INFO: Once done, run this script again." clean_up_and_exit 1 fi -echo "INFO: Using remote repository '${github_remote}' to fetch PR (should point to github.com/apache/cloudstack.git)" +echo "INFO: Using remote repository '${github_remote}' to fetch PR (should point to github.com/apache/${repoName}.git)" echo "INFO: PR #${prId} against branch '${prDestinationBranch}' from '${prAuthor}': '${prTitle}'" echo "INFO: has state '${prState}' and mergable state '${prMergeableState}', about to be merged in branch '${currentBranch}'." @@ -220,6 +222,7 @@ if [ $? -eq 0 ]; then else echo "ERROR: Merge failed, aborting." git merge --abort + clean_up_and_exit 1 fi # What's next From 9a24109f9545b024e916b297a403bdd299ecba11 Mon Sep 17 00:00:00 2001 From: Remi Bergsma Date: Mon, 24 Aug 2015 13:42:48 +0200 Subject: [PATCH 3/4] fix bug where the countdown would be on multiple lines Example of problem: ATTENTION: Merging pull request #731 from remibergsma/centos7-kvm into 'master' branch in 5 seconds. CTRL+c to abort.. -n 5 -n 4 -n 3 -n 2 -n 1 -n 0 Should be compatible with more environments if printf is used instead. --- tools/git/git-pr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/git/git-pr b/tools/git/git-pr index 49eee799e97..2e0b275e86a 100755 --- a/tools/git/git-pr +++ b/tools/git/git-pr @@ -207,10 +207,11 @@ echo "${prTitle}${prBody}" >> ${tmpMessageFile} echo "ATTENTION: Merging pull request #${prId} from ${prOriginBranch} into '${currentBranch}' branch in 5 seconds. CTRL+c to abort.." sec=5 while [ $sec -ge 0 ]; do - echo -n "${sec} " + printf "${sec} " sec=$((sec-1)) sleep 1 done +echo echo "INFO: Executing the merge now.. Git output below:" echo "INFO: ***********************************************************************************" From 1e6df1b77500dff40c24245227658f7c85c1835c Mon Sep 17 00:00:00 2001 From: Remi Bergsma Date: Mon, 24 Aug 2015 16:16:16 +0200 Subject: [PATCH 4/4] fixed hardcoded merge message location This would be empty if run from another directory, resulting in a merge message with only a 'signed-off by' line. --- tools/git/git-pr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/git/git-pr b/tools/git/git-pr index 2e0b275e86a..2bd58f689eb 100755 --- a/tools/git/git-pr +++ b/tools/git/git-pr @@ -217,7 +217,7 @@ echo "INFO: ******************************************************************** # Do the actual merge git fetch ${github_remote} pull/${prId}/head:pr/${prId} -git merge --no-ff --log -m "$(cat .git-tmp-message.txt)" pr/${prId} +git merge --no-ff --log -m "$(cat ${tmpMessageFile})" pr/${prId} if [ $? -eq 0 ]; then git commit --amend -s --allow-empty-message -m '' else