Created
June 10, 2010 03:06
-
-
Save jgoulah/432516 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/sh | |
| # pull - rebase master into current branch | |
| # push - squash, merge to master, and dcommit current branch back to svn | |
| run_args="$0 <pull|push>" | |
| type=$1 | |
| case "$type" in | |
| push) | |
| echo -n "Are you sure you want to push (N/y)? " | |
| read ok <&1 | |
| if [ "${ok}" != 'y' ]; then | |
| echo "Canceling push request..."; | |
| exit 1 | |
| fi | |
| ;; | |
| pull) | |
| ;; | |
| *) | |
| echo $run_args; | |
| exit 1 | |
| esac | |
| git_repo_dir=`pwd` | |
| dot_git="$git_repo_dir/.git" | |
| if [ ! -d $dot_git ]; then | |
| echo "git home is not correct, can't find .git file" | |
| echo $run_args; | |
| exit 1 | |
| fi | |
| export GIT_DIR=$dot_git | |
| cd $git_repo_dir | |
| if [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]]; then | |
| echo "some files not stash or committed" | |
| exit 1 | |
| fi | |
| cur_branch=$(git branch 2>/dev/null|grep -e ^* | tr -d \*) | |
| if [ $cur_branch = 'master' ]; then | |
| echo "current branch is master" | |
| exit 1 | |
| fi | |
| # all the main checks done now do the push or pull | |
| if [ $type = 'pull' ]; then | |
| echo "attempting to merge master into $cur_branch" | |
| echo "checking out master" | |
| status=`git checkout master | awk '{print $1}'` | |
| if [[ ! "${status}" =~ error ]]; then | |
| echo "running git svn rebase in master" | |
| git svn rebase | |
| echo "checking out branch $cur_branch" | |
| git checkout ${cur_branch} | |
| echo "rebasing master" | |
| git rebase master | |
| fi | |
| else | |
| echo "attempting to merge into master and dcommit to svn" | |
| echo "rebasing master into $cur_branch" | |
| git rebase -i master | |
| echo "checking out master" | |
| status=`git checkout master | awk '{print $1}'` | |
| if [[ ! "${status}" =~ error ]]; then | |
| echo "merging branch $cur_branch into master" | |
| git merge ${cur_branch} | |
| echo "running svn dcommit" | |
| git svn dcommit | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment