Created
July 22, 2015 03:31
-
-
Save evilmarty/3f55f7ed0acbaedb6f74 to your computer and use it in GitHub Desktop.
git pull request workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!/bin/bash | |
PULL_REQUEST_TEMPLATE="\n# Please enter the message for your pull request. Lines starting\n# with '#' will be ignored, and an empty message aborts the commit.\n# On branch %s" | |
branch=$(git rev-parse --abbrev-ref HEAD); | |
if [ "$branch" = "master" ]; then | |
echo "Cannot create pull request on master branch"; | |
exit 1; | |
fi | |
dirty=$(git diff-index --name-only HEAD --); | |
if [ -n "$dirty" ]; then | |
git commit -a; | |
if [ $? -ne 0 ]; then | |
echo "Cancelling pull request"; | |
exit 1; | |
fi | |
fi | |
message=$(git log -1 --format="%s"); | |
git push origin $branch 2> /dev/null | |
if [ $? -ne 0 ]; then | |
echo "Aborting pull request. Failed to push branch to origin."; | |
exit 1; | |
fi | |
tmpmsg=$(mktemp /tmp/GIT_PULL_REQUEST_MESSAGE.XXXXXX); | |
echo $message > $tmpmsg | |
printf "$PULL_REQUEST_TEMPLATE" "$branch" >> $tmpmsg | |
vim -c "set syntax=gitcommit" $tmpmsg; | |
if [ $? -ne 0 ]; then | |
echo "Cancelling pull request"; | |
exit 1; | |
fi | |
message=$(sed 's:^#.*$::g' "$tmpmsg"); | |
url=$(echo "$message" | hub pull-request -F -); | |
exit_status=$? | |
rm $tmpmsg > /dev/null | |
if [ $exit_status -eq 0 ]; then | |
echo $url | pbcopy; | |
echo "Pull request created. Copied URL $url"; | |
exit 0; | |
else | |
echo "Cancelling pull request"; | |
exit 1; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment