Created
August 15, 2014 18:57
-
-
Save cshireman/38d9299db41291f2fbec to your computer and use it in GitHub Desktop.
BASH: Phabricator workflow bash functions
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
RELEASE_BRANCH=release/v2.0.0 | |
# Shortcut replacement for fetching and rebasing into your current branch. This can be used either as a substitute for git pull, or a way to rebase changes from the primary branch into your local feature/bug branch. | |
# $1 = either 'dev' or 'rel' depending on which branch you want to rebase into your branch. If it is neither 'dev' or 'rel' then it should be a remote branch you want to rebase into your branch (e.g. origin/branch_name) | |
# | |
# Example usage: gitup dev | |
# Example usage: gitup rel | |
# Example usage: gitup origin/branch_name | |
gitup() | |
{ | |
if [ "$#" -ne "1" ] # If there isn't exactly one argument | |
then | |
echo "Usage: 'gitup [dev/rel]' or 'gitup {branch-name}'" # Bail out with bad arguments | |
kill -INT $$ | |
fi | |
if [ "$1" = "dev" ] # If they specify development | |
then | |
git fetch && git rebase origin/develop | |
elif [ "$1" = "rel" ] # If they specify release | |
then | |
git fetch && git rebase origin/$RELEASE_BRANCH | |
else # Otherwise they should have specified a remote branch | |
git fetch && git rebase $1 | |
fi | |
} | |
# Shortcut replacement for creating a new branch. | |
# $1 = new branch name | |
# $2 = either 'dev' or 'rel' depending on which branch you want to rebase into your branch. If it is neither 'dev' or 'rel' then it should be a remote branch you want to rebase into your branch (e.g. origin/branch_name) | |
# | |
# Example usage: gitcb branch_name origin/develop | |
gitcb() | |
{ | |
if [ "$#" -ne "2" ] # If there isn't exactly one argument | |
then | |
echo "Usage: 'gitcb {new-branch} [dev/rel]' or 'gitcb {new-branch} {master-branch-name}'" # Bail out with bad argument | |
kill -INT $$ | |
fi | |
git fetch # Fetch latest data from the repo | |
if [ "$2" = "dev" ] # If they specify development | |
then | |
git checkout -b $1 origin/develop | |
elif [ "$2" = "rel" ] # If they specify release | |
then | |
git checkout -b $1 origin/$RELEASE_BRANCH | |
else # Otherwise they should have specified a remote branch | |
git checkout -b $1 $2 | |
fi | |
} | |
# Shortcut for creating a codereview in Phabricator | |
# $1 = either 'dev' or 'rel' depending on which branch you want to rebase into your branch. If it is neither 'dev' or 'rel' then it should be a remote branch you want to rebase into your branch (e.g. origin/branch_name) | |
# | |
# Example usage: cr dev | |
# Example usage: cr rel | |
# Example usage: cr origin/branch_name | |
cr() | |
{ | |
if [ "$#" -ne "1" ] # If there isn't exactly one argument | |
then | |
echo "Usage: 'cr [dev/rel]' or 'cr {branch-name}'" # Bail out with bad argument | |
kill -INT $$ | |
fi | |
gitup $1 # Update local branch to the most recent stuff from the remote branch | |
if [ "$1" = "dev" ] # If they specify development | |
then | |
arc diff origin/develop | |
elif [ "$1" = "rel" ] # If they specify release | |
then | |
arc diff origin/$RELEASE_BRANCH | |
else # Otherwise they should have specified a remote branch | |
arc diff $1 | |
fi | |
} | |
# Shortcut for the merge command we must do to bring our latest changes on the release branch into develop | |
# You must still do a push after executing this command | |
reltodev() | |
{ | |
git checkout develop | |
gitup dev | |
git merge --no-ff $RELEASE_BRANCH -m "Release Fix: Merge from $RELEASE_BRANCH" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to DJM for cleaning this up and making it more user friendly