@@ -28,12 +28,13 @@ cd "${KUBE_ROOT}"
2828declare -r STARTINGBRANCH=$( git symbolic-ref --short HEAD)
2929declare -r REBASEMAGIC=" ${KUBE_ROOT} /.git/rebase-apply"
3030
31- if [[ " $# " -ne 2 ]]; then
32- echo " ${0} <pr-number> < remote branch>: cherry pick <pr> onto <remote branch> and leave instructions for proposing pull request"
31+ if [[ " $# " -lt 2 ]]; then
32+ echo " ${0} <remote branch> <pr-number>... : cherry pick one or more <pr> onto <remote branch> and leave instructions for proposing pull request"
3333 echo " "
34- echo " Checks out <remote branch> and handles the cherry-pick of <pr> for you."
35- echo " Example:"
36- echo " $0 12345 upstream/release-3.14"
34+ echo " Checks out <remote branch> and handles the cherry-pick of <pr> (possibly multiple) for you."
35+ echo " Examples:"
36+ echo " $0 upstream/release-3.14 12345 # Cherry-picks PR 12345 onto upstream/release-3.14 and proposes that as a PR."
37+ echo " $0 upstream/release-3.14 12345 56789 # Cherry-picks PR 12345, then 56789 and proposes the combination as a single PR."
3738 exit 2
3839fi
3940
@@ -47,8 +48,14 @@ if [[ -e "${REBASEMAGIC}" ]]; then
4748 exit 1
4849fi
4950
50- declare -r PULL=" ${1} "
51- declare -r BRANCH=" ${2} "
51+ declare -r BRANCH=" $1 "
52+ shift 1
53+ declare -r PULLS=( " $@ " )
54+
55+ function join { local IFS=" $1 " ; shift ; echo " $* " ; }
56+ declare -r PULLDASH=$( join - " ${PULLS[@]/#/ \# } " ) # Generates something like "#12345-#56789"
57+ declare -r PULLSUBJ=$( join " " " ${PULLS[@]/#/ \# } " ) # Generates something like "#12345 #56789"
58+
5259echo " +++ Updating remotes..."
5360git remote update
5461
@@ -58,11 +65,8 @@ if ! git log -n1 --format=%H "${BRANCH}" >/dev/null 2>&1; then
5865 exit 1
5966fi
6067
61- echo " +++ Downloading patch to /tmp/${PULL} .patch (in case you need to do this again)"
62-
63- curl -o " /tmp/${PULL} .patch" -sSL " https://github.com/GoogleCloudPlatform/kubernetes/pull/${PULL} .patch"
64-
65- declare -r NEWBRANCH=" $( echo automated-cherry-pick-of-#${PULL} -on-${BRANCH} | sed ' s/\//-/g' ) "
68+ declare -r NEWBRANCHREQ=" automated-cherry-pick-of-${PULLDASH} " # "Required" portion for tools.
69+ declare -r NEWBRANCH=" $( echo ${NEWBRANCHREQ} -${BRANCH} | sed ' s/\//-/g' ) "
6670declare -r NEWBRANCHUNIQ=" ${NEWBRANCH} -$( date +%s) "
6771echo " +++ Creating local branch ${NEWBRANCHUNIQ} "
6872
@@ -84,35 +88,39 @@ trap return_to_kansas EXIT
8488git checkout -b " ${NEWBRANCHUNIQ} " " ${BRANCH} "
8589cleanbranch=" ${NEWBRANCHUNIQ} "
8690
87- echo
88- echo " +++ About to attempt cherry pick of PR. To reattempt:"
89- echo " $ git am -3 /tmp/${PULL} .patch"
90- echo
9191gitamcleanup=true
92- git am -3 " /tmp/${PULL} .patch" || {
93- conflicts=false
94- while unmerged=$( git status --porcelain | grep ^U) && [[ -n ${unmerged} ]] \
95- || [[ -e " ${REBASEMAGIC} " ]]; do
96- conflicts=true # <-- We should have detected conflicts once
97- echo
98- echo " +++ Conflicts detected:"
99- echo
100- (git status --porcelain | grep ^U) || echo " !!! None. Did you git am --continue?"
101- echo
102- echo " +++ Please resolve the conflicts in another window (and remember to 'git add / git am --continue')"
103- read -p " +++ Proceed (anything but 'y' aborts the cherry-pick)? [y/n] " -r
104- echo
105- if ! [[ " ${REPLY} " =~ ^[yY]$ ]]; then
106- echo " Aborting." >&2
92+ for pull in " ${PULLS[@]} " ; do
93+ echo " +++ Downloading patch to /tmp/${pull} .patch (in case you need to do this again)"
94+ curl -o " /tmp/${pull} .patch" -sSL " https://github.com/GoogleCloudPlatform/kubernetes/pull/${pull} .patch"
95+ echo
96+ echo " +++ About to attempt cherry pick of PR. To reattempt:"
97+ echo " $ git am -3 /tmp/${pull} .patch"
98+ echo
99+ git am -3 " /tmp/${pull} .patch" || {
100+ conflicts=false
101+ while unmerged=$( git status --porcelain | grep ^U) && [[ -n ${unmerged} ]] \
102+ || [[ -e " ${REBASEMAGIC} " ]]; do
103+ conflicts=true # <-- We should have detected conflicts once
104+ echo
105+ echo " +++ Conflicts detected:"
106+ echo
107+ (git status --porcelain | grep ^U) || echo " !!! None. Did you git am --continue?"
108+ echo
109+ echo " +++ Please resolve the conflicts in another window (and remember to 'git add / git am --continue')"
110+ read -p " +++ Proceed (anything but 'y' aborts the cherry-pick)? [y/n] " -r
111+ echo
112+ if ! [[ " ${REPLY} " =~ ^[yY]$ ]]; then
113+ echo " Aborting." >&2
114+ exit 1
115+ fi
116+ done
117+
118+ if [[ " ${conflicts} " != " true" ]]; then
119+ echo " !!! git am failed, likely because of an in-progress 'git am' or 'git rebase'"
107120 exit 1
108121 fi
109- done
110-
111- if [[ " ${conflicts} " != " true" ]]; then
112- echo " !!! git am failed, likely because of an in-progress 'git am' or 'git rebase'"
113- exit 1
114- fi
115- }
122+ }
123+ done
116124gitamcleanup=false
117125
118126if git remote -v | grep ^origin | grep GoogleCloudPlatform/kubernetes.git; then
@@ -123,7 +131,10 @@ if git remote -v | grep ^origin | grep GoogleCloudPlatform/kubernetes.git; then
123131 echo
124132 echo " where REMOTE is your personal fork (maybe 'upstream'? Consider swapping those.)."
125133 echo " Then propose ${NEWBRANCH} as a pull against ${BRANCH} (NOT MASTER)."
126- echo " Use this exact subject: 'Automated cherry pick of #${PULL} ' and include a justification."
134+ echo " Use this subject: 'Automated cherry pick of ${PULLSUBJ} ' and include a justification."
135+ echo " "
136+ echo " Note: the tools actually scrape the branch name you just pushed, so don't worry about"
137+ echo " the subject too much, but DO keep at least ${NEWBRANCHREQ} in the remote branch name."
127138 cleanbranch=" "
128139 exit 0
129140fi
@@ -143,5 +154,8 @@ git push origin -f "${NEWBRANCHUNIQ}:${NEWBRANCH}"
143154
144155echo
145156echo " +++ Now you must propose ${NEWBRANCH} as a pull against ${BRANCH} (NOT MASTER)."
146- echo " You must use this exact subject: 'Automated cherry pick of #${PULL} ' and include a justification."
157+ echo " Use this subject: 'Automated cherry pick of ${PULLSUBJ} ' and include a justification."
158+ echo " "
159+ echo " Note: the tools actually scrape the branch name you just pushed, so don't worry about"
160+ echo " the subject too much, but DO keep at least ${NEWBRANCHREQ} in the remote branch name."
147161echo
0 commit comments