I just updated the function I wrote about yesterday, making two big changes:
- Vim is no longer opened just so that I can reuse the last commit message for the PR Message
- The browser no longer opens the PR page; instead the URL for the PR is copied to the clipboard so that I can paste it into Slack.
The new usage is simply $ pr
if I want to PR into develop
or $ pr target-branch
if I want to PR into target-branch
.
Here is the new version, which can also be found on GitHub:
function pr -d 'Quickly make a PR of the current branch into `develop` or the branch of your choosing'
# Reuse the last commit message as the PR message
git log -1 --pretty=%B > msg.txt
set targetbranch 'develop'
if test -n "$argv"
set targetbranch $argv[1]
end
git push; and git pull-request -b $targetbranch -F msg.txt | pbcopy
rm msg.txt
echo 'You can find your PR at' (pbpaste)
echo ' (That URL has been copied to your clipboard, as well)'
end
I’m outputting the last commit message to a temp file, msg.txt
, because this seems like a good way to support multi-line messages. The message is then used with the pull-request -F
flag. In my first attempt I stored the value of git log -1 --pretty=%B
in a var to then pass to pull-request -m
but that choked on commits that were more than a single line.