Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
44beb98f
Commit
44beb98f
authored
Jul 29, 2016
by
Paul Morie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add dry run capability to cherry_pick_pull.sh
parent
d9ca9e8c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
28 deletions
+53
-28
cherry_pick_pull.sh
hack/cherry_pick_pull.sh
+53
-28
No files found.
hack/cherry_pick_pull.sh
View file @
44beb98f
...
@@ -16,7 +16,8 @@
...
@@ -16,7 +16,8 @@
# Checkout a PR from GitHub. (Yes, this is sitting in a Git tree. How
# Checkout a PR from GitHub. (Yes, this is sitting in a Git tree. How
# meta.) Assumes you care about pulls from remote "upstream" and
# meta.) Assumes you care about pulls from remote "upstream" and
# checks thems out to a branch named pull_12345.
# checks thems out to a branch named:
# automated-cherry-pick-of-<pr>-<target branch>-<timestamp>
set
-o
errexit
set
-o
errexit
set
-o
nounset
set
-o
nounset
...
@@ -27,6 +28,7 @@ cd "${KUBE_ROOT}"
...
@@ -27,6 +28,7 @@ cd "${KUBE_ROOT}"
declare
-r
STARTINGBRANCH
=
$(
git symbolic-ref
--short
HEAD
)
declare
-r
STARTINGBRANCH
=
$(
git symbolic-ref
--short
HEAD
)
declare
-r
REBASEMAGIC
=
"
${
KUBE_ROOT
}
/.git/rebase-apply"
declare
-r
REBASEMAGIC
=
"
${
KUBE_ROOT
}
/.git/rebase-apply"
DRY_RUN
=
${
DRY_RUN
:-
""
}
if
[[
-z
${
GITHUB_USER
:-}
]]
;
then
if
[[
-z
${
GITHUB_USER
:-}
]]
;
then
echo
"Please export GITHUB_USER=<your-user> (or GH organization, if that's where your fork lives)"
echo
"Please export GITHUB_USER=<your-user> (or GH organization, if that's where your fork lives)"
...
@@ -40,11 +42,15 @@ fi
...
@@ -40,11 +42,15 @@ fi
if
[[
"$#"
-lt
2
]]
;
then
if
[[
"$#"
-lt
2
]]
;
then
echo
"
${
0
}
<remote branch> <pr-number>...: cherry pick one or more <pr> onto <remote branch> and leave instructions for proposing pull request"
echo
"
${
0
}
<remote branch> <pr-number>...: cherry pick one or more <pr> onto <remote branch> and leave instructions for proposing pull request"
echo
""
echo
echo
" Checks out <remote branch> and handles the cherry-pick of <pr> (possibly multiple) for you."
echo
" Checks out <remote branch> and handles the cherry-pick of <pr> (possibly multiple) for you."
echo
" Examples:"
echo
" Examples:"
echo
"
$0
upstream/release-3.14 12345 # Cherry-picks PR 12345 onto upstream/release-3.14 and proposes that as a PR."
echo
"
$0
upstream/release-3.14 12345 # Cherry-picks PR 12345 onto upstream/release-3.14 and proposes that as a PR."
echo
"
$0
upstream/release-3.14 12345 56789 # Cherry-picks PR 12345, then 56789 and proposes the combination as a single PR."
echo
"
$0
upstream/release-3.14 12345 56789 # Cherry-picks PR 12345, then 56789 and proposes the combination as a single PR."
echo
echo
" Set the DRY_RUN environment var to skip git push and creating PR."
echo
" This is useful for creating patches to a release branch without making a PR."
echo
" When DRY_RUN is set the script will leave you in a branch containing the commits you cherry-picked."
exit
2
exit
2
fi
fi
...
@@ -67,7 +73,7 @@ declare -r PULLDASH=$(join - "${PULLS[@]/#/#}") # Generates something like "#123
...
@@ -67,7 +73,7 @@ declare -r PULLDASH=$(join - "${PULLS[@]/#/#}") # Generates something like "#123
declare
-r
PULLSUBJ
=
$(
join
" "
"
${
PULLS
[@]/#/#
}
"
)
# Generates something like "#12345 #56789"
declare
-r
PULLSUBJ
=
$(
join
" "
"
${
PULLS
[@]/#/#
}
"
)
# Generates something like "#12345 #56789"
echo
"+++ Updating remotes..."
echo
"+++ Updating remotes..."
git remote update
git remote update
upstream origin
if
!
git log
-n1
--format
=
%H
"
${
BRANCH
}
"
>
/dev/null 2>&1
;
then
if
!
git log
-n1
--format
=
%H
"
${
BRANCH
}
"
>
/dev/null 2>&1
;
then
echo
"!!! '
${
BRANCH
}
' not found. The second argument should be something like upstream/release-0.21."
echo
"!!! '
${
BRANCH
}
' not found. The second argument should be something like upstream/release-0.21."
...
@@ -84,21 +90,46 @@ cleanbranch=""
...
@@ -84,21 +90,46 @@ cleanbranch=""
prtext
=
""
prtext
=
""
gitamcleanup
=
false
gitamcleanup
=
false
function
return_to_kansas
{
function
return_to_kansas
{
echo
""
echo
"+++ Returning you to the
${
STARTINGBRANCH
}
branch and cleaning up."
if
[[
"
${
gitamcleanup
}
"
==
"true"
]]
;
then
if
[[
"
${
gitamcleanup
}
"
==
"true"
]]
;
then
echo
echo
"+++ Aborting in-progress git am."
git am
--abort
>
/dev/null 2>&1
||
true
git am
--abort
>
/dev/null 2>&1
||
true
fi
fi
git checkout
-f
"
${
STARTINGBRANCH
}
"
>
/dev/null 2>&1
||
true
if
[[
-n
"
${
cleanbranch
}
"
]]
;
then
# return to the starting branch and delete the PR text file
git branch
-D
"
${
cleanbranch
}
"
>
/dev/null 2>&1
||
true
if
[[
-z
"
${
DRY_RUN
}
"
]]
;
then
fi
echo
if
[[
-n
"
${
prtext
}
"
]]
;
then
echo
"+++ Returning you to the
${
STARTINGBRANCH
}
branch and cleaning up."
rm
"
${
prtext
}
"
git checkout
-f
"
${
STARTINGBRANCH
}
"
>
/dev/null 2>&1
||
true
if
[[
-n
"
${
cleanbranch
}
"
]]
;
then
git branch
-D
"
${
cleanbranch
}
"
>
/dev/null 2>&1
||
true
fi
if
[[
-n
"
${
prtext
}
"
]]
;
then
rm
"
${
prtext
}
"
fi
fi
fi
}
}
trap
return_to_kansas EXIT
trap
return_to_kansas EXIT
function
make-a-pr
()
{
local
rel
=
"
$(
basename
"
${
BRANCH
}
"
)
"
echo
echo
"+++ Creating a pull request on GitHub at
${
GITHUB_USER
}
:
${
NEWBRANCH
}
"
# This looks like an unnecessary use of a tmpfile, but it avoids
# https://github.com/github/hub/issues/976 Otherwise stdin is stolen
# when we shove the heredoc at hub directly, tickling the ioctl
# crash.
prtext
=
"
$(
mktemp
-t
prtext.XXXX
)
"
# cleaned in return_to_kansas
cat
>
"
${
prtext
}
"
<<
EOF
Automated cherry pick of
${
PULLSUBJ
}
Cherry pick of
${
PULLSUBJ
}
on
${
rel
}
.
EOF
hub pull-request
-F
"
${
prtext
}
"
-h
"
${
GITHUB_USER
}
:
${
NEWBRANCH
}
"
-b
"kubernetes:
${
rel
}
"
}
git checkout
-b
"
${
NEWBRANCHUNIQ
}
"
"
${
BRANCH
}
"
git checkout
-b
"
${
NEWBRANCHUNIQ
}
"
"
${
BRANCH
}
"
cleanbranch
=
"
${
NEWBRANCHUNIQ
}
"
cleanbranch
=
"
${
NEWBRANCHUNIQ
}
"
...
@@ -137,23 +168,17 @@ for pull in "${PULLS[@]}"; do
...
@@ -137,23 +168,17 @@ for pull in "${PULLS[@]}"; do
done
done
gitamcleanup
=
false
gitamcleanup
=
false
function
make-a-pr
()
{
if
[[
-n
"
${
DRY_RUN
}
"
]]
;
then
local
rel
=
"
$(
basename
"
${
BRANCH
}
"
)
"
echo
"!!! Skipping git push and PR creation because you set DRY_RUN."
echo
"+++ Creating a pull request on GitHub at
${
GITHUB_USER
}
:
${
NEWBRANCH
}
"
echo
"To return to the branch you were in when you invoked this script:"
echo
# This looks like an unnecessary use of a tmpfile, but it avoids
echo
" git checkout
${
STARTINGBRANCH
}
"
# https://github.com/github/hub/issues/976 Otherwise stdin is stolen
echo
# when we shove the heredoc at hub directly, tickling the ioctl
echo
"To delete this branch:"
# crash.
echo
prtext
=
"
$(
mktemp
-t
prtext.XXXX
)
"
# cleaned in return_to_kansas
echo
" git branch -D
${
NEWBRANCHUNIQ
}
"
cat
>
"
${
prtext
}
"
<<
EOF
exit
0
Automated cherry pick of
${
PULLSUBJ
}
fi
Cherry pick of
${
PULLSUBJ
}
on
${
rel
}
.
EOF
hub pull-request
-F
"
${
prtext
}
"
-h
"
${
GITHUB_USER
}
:
${
NEWBRANCH
}
"
-b
"kubernetes:
${
rel
}
"
}
if
git remote
-v
|
grep
^origin |
grep
kubernetes/kubernetes.git
;
then
if
git remote
-v
|
grep
^origin |
grep
kubernetes/kubernetes.git
;
then
echo
"!!! You have 'origin' configured as your kubernetes/kubernetes.git"
echo
"!!! You have 'origin' configured as your kubernetes/kubernetes.git"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment