METRON-1500 Enhance 'prepare-commit' to Support Feature Branches (nickwallen) closes apache/metron#971
Project: http://git-wip-us.apache.org/repos/asf/metron/repo Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/9e95d4b6 Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/9e95d4b6 Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/9e95d4b6 Branch: refs/heads/feature/METRON-1211-extensions-parsers-gradual Commit: 9e95d4b61410c8033f0a4ea51e831566d5d933d3 Parents: 5ed9631 Author: nickwallen <n...@nickallen.org> Authored: Fri Mar 23 12:23:34 2018 -0400 Committer: nickallen <nickal...@apache.org> Committed: Fri Mar 23 12:23:34 2018 -0400 ---------------------------------------------------------------------- dev-utilities/committer-utils/prepare-commit | 27 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/metron/blob/9e95d4b6/dev-utilities/committer-utils/prepare-commit ---------------------------------------------------------------------- diff --git a/dev-utilities/committer-utils/prepare-commit b/dev-utilities/committer-utils/prepare-commit index 67116cb..ae8d7ab 100755 --- a/dev-utilities/committer-utils/prepare-commit +++ b/dev-utilities/committer-utils/prepare-commit @@ -19,9 +19,9 @@ # not likely to change METRON_UPSTREAM="https://git-wip-us.apache.org/repos/asf/metron.git" BRO_PLUGIN_UPSTREAM="https://git-wip-us.apache.org/repos/asf/metron-bro-plugin-kafka.git" -BASE_BRANCH=master CONFIG_FILE=~/.metron-prepare-commit GITHUB_REMOTE="origin" +BASE_BRANCH=master # does a config file already exist? if [ -f $CONFIG_FILE ]; then @@ -114,6 +114,11 @@ if [ ! -d "$WORK" ]; then read -p " origin repo [$ORIGIN]: " INPUT [ -n "$INPUT" ] && ORIGIN=$INPUT + # what branch did the PR get submitted against? could be a feature branch + BASE_BRANCH=`curl -s https://api.github.com/repos/apache/${CHOSEN_REPO}/pulls/$PR | python -c 'import sys, json; print json.load(sys.stdin)["base"]["ref"]'` + read -p " base branch to merge into [$BASE_BRANCH]: " INPUT + [ -n "$INPUT" ] && BASE_BRANCH=$INPUT + # clone the repository and fetch updates mkdir -p $WORK git clone $ORIGIN $WORK @@ -125,11 +130,23 @@ if [ ! -d "$WORK" ]; then # fetch any changes from upstream git remote add upstream $UPSTREAM - git fetch upstream $BASE_BRANCH + if git fetch upstream "$BASE_BRANCH"; then + + if [ $BASE_BRANCH = "master" ]; then + # merge any changes from upstream + git checkout $BASE_BRANCH + git merge upstream/$BASE_BRANCH - # merge any changes from upstream - git checkout $BASE_BRANCH - git merge upstream/$BASE_BRANCH + else + # create a local branch from the remote feature branch + git checkout -B $BASE_BRANCH upstream/$BASE_BRANCH + + fi + + else + # unable to fetch the base branch + exit $? + fi else