diff options
author | isaacs <i@izs.me> | 2019-08-05 02:17:38 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2019-08-05 02:17:38 +0300 |
commit | 46181cb490ebb7732e806d6f4f0771bf42e6fa50 (patch) | |
tree | 029411f2cdcf41581fec6a9ef9eff6d4656d0eaf /scripts | |
parent | 0f980f55e8f16c58cf63872b5babcd401ba04b10 (diff) |
dev: make the pr script a little friendlier with conflicts
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/pr | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/scripts/pr b/scripts/pr index dfaf6e4db..30a3b05ff 100755 --- a/scripts/pr +++ b/scripts/pr @@ -8,6 +8,12 @@ # pr <url|number> [<upstream remote>=origin] main () { + if [ "$1" = "finish" ]; then + shift + finish "$@" + return $? + fi + local url="$(prurl "$@")" local num=$(basename $url) local prpath="${url#git@github.com:}" @@ -49,10 +55,53 @@ main () { git pull --rebase origin pull/$num/head fi - # add the PR-URL to the last commit, after squashing - git rebase -i $curbranch # squash and test + if [ $? -eq 0 ]; then + finish "${curbranch}" + else + echo "resolve conflicts and run: $0 finish "'"'${curbranch}'"' + fi +} + +# add the PR-URL to the last commit, after squashing +finish () { + if [ $# -eq 0 ]; then + echo "Usage: $0 finish <branch> (while on a PR-### branch)" >&2 + return 1 + fi + + local curbranch="$1" + local ref=$(cat .git/HEAD) + local prnum + case $ref in + "ref: refs/heads/PR-"*) + prnum=${ref#ref: refs/heads/PR-} + ;; + *) + echo "not on the PR-## branch any more!" >&2 + return 1 + ;; + esac + + local me=$(git config github.user || git config user.name) + if [ "$me" == "" ]; then + echo "run 'git config --add github.user <username>'" >&2 + return 1 + fi + + set -x + + local url="$(prurl "$prnum")" + local num=$prnum + local prpath="${url#git@github.com:}" + local repo=${prpath%/pull/$num} + local prweb="https://github.com/$prpath" + local root="$(prroot "$url")" + + local api="https://api.github.com/repos/${repo}/pulls/${num}" + local user=$(curl -s $api | json user.login) + local lastmsg="$(git log -1 --pretty=%B)" local newmsg="${lastmsg} @@ -63,9 +112,11 @@ Reviewed-by: @${me} " git commit --amend -m "$newmsg" git checkout $curbranch - git merge $branch --ff-only + git merge PR-${prnum} --ff-only + set +x } + prurl () { local url="$1" if [ "$url" == "" ] && type pbpaste &>/dev/null; then |