Last active
July 11, 2017 14:49
-
-
Save sukima/c192066bae728441971b8fea893337b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# GistID: c192066bae728441971b8fea893337b1 | |
die() { | |
local CODE=$1 | |
shift | |
echo "$*" >&2 | |
exit $CODE | |
} | |
if [[ -z $1 || $1 == "-h" || $1 == "--help" ]]; then | |
die 0 "Usage: git quick-pr BRANCH_NAME [OPTIONS]" | |
fi | |
if ! git status --porcelain | grep "^[MADRCU]" > /dev/null 2>&1; then | |
die 0 "Nothing staged." | |
fi | |
BRANCH=$1 | |
shift | |
if [[ $1 == "-b" ]]; then | |
ROOT=$2 | |
shift | |
shift | |
else | |
ROOT=master | |
fi | |
git commit "$@" || die 127 "git commit failed" | |
if git status --porcelain | grep "^??" > /dev/null 2>&1; then | |
git stash || die 127 "git stash failed" | |
is_stashed=1 | |
fi | |
git branch $BRANCH || die 127 "git branch failed" | |
git reset --hard HEAD^ || die 127 "git reset failed" | |
git checkout $BRANCH || die 127 "git checkout failed" | |
git push -u origin HEAD || die 127 "git push failed" | |
hub pull-request -b $ROOT || die 127 "hub pull-request failed" | |
git checkout - || die 127 "git checkout - failed" | |
if [[ $is_stashed == 1 ]]; then | |
git stash pop || die 127 "git stash pop failed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment