-
-
Save judoole/1186096 to your computer and use it in GitHub Desktop.
Ship script inspired by this blog: http://reinh.com/blog/2008/08/27/hack-and-and-ship.html
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
_git_branches() | |
{ | |
local cur | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
CURRENT=`git branch | grep '^*' | awk '{print $2}'` | |
local versions=$(git branch | grep -v $CURRENT) | |
COMPREPLY=($(compgen -W "${versions}" $cur)) | |
} | |
complete -F _git_branches ship |
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
# SHIP | |
#!/bin/bash | |
# | |
# Do a check if you have uncommited changes | |
# | |
GIT_NOT_COMMITED=`git status | grep 'nothing to commit' | awk '{print $2}'` | |
if [ -z "$GIT_NOT_COMMITED" ]; then | |
echo "Current branch has uncommited changes" | |
exit | |
fi | |
# | |
# Oy! Checking if the branch to ship to really exists | |
# | |
TO_SHIP_TO=$1 | |
CURRENT=`git branch | grep '\*' | awk '{print $2}'` | |
if [ -z $TO_SHIP_TO ]; then | |
echo "First argument has to be one of these branches:" | |
git branch | grep -v $CURRENT | |
exit 1 | |
fi | |
# | |
# Checkout to the ship branch | |
# | |
STATUS=`git checkout $TO_SHIP_TO | awk '{print $1}'` | |
if [[ "${STATUS}" =~ error ]]; then | |
echo "Something went terribly wrong! ${STATUS}" | |
git checkout ${CURRENT} | |
exit 1 | |
fi | |
# | |
# Pull the latest from origin into ship-branch | |
# | |
echo "Pulling ${TO_SHIP_TO} from origin" | |
STATUS=`git pull | awk '{print $1}'` | |
if [[ "${STATUS}" =~ error ]]; then | |
echo "Something went terribly wrong! ${STATUS}" | |
git checkout ${CURRENT} | |
exit 1 | |
fi | |
# | |
# Merge into whatever youre shipping to wit --no-ff | |
# | |
echo "Merging ${CURRENT} into ${TO_SHIP_TO}" | |
STATUS=`git merge --no-ff ${CURRENT} | awk '{print $1}'` | |
if [[ "${STATUS}" =~ error ]]; then | |
echo "Something went terribly wrong with the merge! ${STATUS}" | |
exit 1 | |
fi | |
# | |
# Pushing | |
# | |
GIT_NOT_COMMITED=`git status | grep 'nothing to commit' | awk '{print $2}'` | |
if [ -z "$GIT_NOT_COMMITED" ]; then | |
echo "Current branch has uncommited changes" | |
exit | |
else | |
echo "Pushing to origin ${TO_SHIP_TO}" | |
git push && \ | |
git checkout ${CURRENT} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Codecompletion for usage in your .bashrc og .profile