From ecb1a7316229f28832c94063c45f9b81b229b61f Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Tue, 9 Oct 2018 09:14:17 -0400 Subject: [PATCH] cherry_pick_pull should work for non-k/k repos Change-Id: If13277d082dd6febadd58f78b7b5710c4fcb2988 --- hack/cherry_pick_pull.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/hack/cherry_pick_pull.sh b/hack/cherry_pick_pull.sh index f75694cc334..e7b440e2a3f 100755 --- a/hack/cherry_pick_pull.sh +++ b/hack/cherry_pick_pull.sh @@ -16,22 +16,26 @@ # Checkout a PR from GitHub. (Yes, this is sitting in a Git tree. How # meta.) Assumes you care about pulls from remote "upstream" and -# checks thems out to a branch named: +# checks them out to a branch named: # automated-cherry-pick-of--- set -o errexit set -o nounset set -o pipefail -declare -r KUBE_ROOT="$(dirname "${BASH_SOURCE}")/.." -cd "${KUBE_ROOT}" +REPO_ROOT="$(git rev-parse --show-toplevel)" +declare -r REPO_ROOT +cd "${REPO_ROOT}" -declare -r STARTINGBRANCH=$(git symbolic-ref --short HEAD) -declare -r REBASEMAGIC="${KUBE_ROOT}/.git/rebase-apply" +STARTINGBRANCH=$(git symbolic-ref --short HEAD) +declare -r STARTINGBRANCH +declare -r REBASEMAGIC="${REPO_ROOT}/.git/rebase-apply" DRY_RUN=${DRY_RUN:-""} REGENERATE_DOCS=${REGENERATE_DOCS:-""} UPSTREAM_REMOTE=${UPSTREAM_REMOTE:-upstream} FORK_REMOTE=${FORK_REMOTE:-origin} +MAIN_REPO_ORG=${MAIN_REPO_ORG:-$(git remote get-url "$UPSTREAM_REMOTE" | awk -F'[@:./]' 'NR==1{print $4}')} +MAIN_REPO_NAME=${MAIN_REPO_NAME:-$(git remote get-url "$UPSTREAM_REMOTE" | awk -F'[@:./]' 'NR==1{print $5}')} if [[ -z ${GITHUB_USER:-} ]]; then echo "Please export GITHUB_USER= (or GH organization, if that's where your fork lives)" @@ -140,7 +144,7 @@ Cherry pick of ${PULLSUBJ} on ${rel}. ${numandtitle} EOF - hub pull-request -F "${prtext}" -h "${GITHUB_USER}:${NEWBRANCH}" -b "kubernetes:${rel}" +hub pull-request -F "${prtext}" -h "${GITHUB_USER}:${NEWBRANCH}" -b "${MAIN_REPO_ORG}:${rel}" } git checkout -b "${NEWBRANCHUNIQ}" "${BRANCH}" @@ -149,7 +153,8 @@ cleanbranch="${NEWBRANCHUNIQ}" gitamcleanup=true for pull in "${PULLS[@]}"; do echo "+++ Downloading patch to /tmp/${pull}.patch (in case you need to do this again)" - curl -o "/tmp/${pull}.patch" -sSL "http://pr.k8s.io/${pull}.patch" + + curl -o "/tmp/${pull}.patch" -sSL "https://github.com/${MAIN_REPO_ORG}/${MAIN_REPO_NAME}/pull/${pull}.patch" echo echo "+++ About to attempt cherry pick of PR. To reattempt:" echo " $ git am -3 /tmp/${pull}.patch" @@ -211,8 +216,8 @@ if [[ -n "${DRY_RUN}" ]]; then exit 0 fi -if git remote -v | grep ^${FORK_REMOTE} | grep kubernetes/kubernetes.git; then - echo "!!! You have ${FORK_REMOTE} configured as your kubernetes/kubernetes.git" +if git remote -v | grep ^${FORK_REMOTE} | grep ${MAIN_REPO_ORG}/${MAIN_REPO_NAME}.git; then + echo "!!! You have ${FORK_REMOTE} configured as your ${MAIN_REPO_ORG}/${MAIN_REPO_NAME}.git" echo "This isn't normal. Leaving you with push instructions:" echo echo "+++ First manually push the branch this script created:"