RED='\033[0;31m' NC='\033[0m' # No Color # check if on master local_branch=$(git branch --show-current) if [ ${local_branch} != "master" ]; then git checkout master # ensure master is in sync with svn fi # git update-ref refs/remotes/git-svn refs/remotes/origin/master # what's this supposed to do? ### check if git svn exists git svn info>/dev/null 2>&1 GITSVN=$? if [ $GITSVN != 0 ] then printf "${RED}You need to install git svn to use this script.${NC}\n" git checkout ${local_branch} exit $GITSVN fi HEAD=$(git rev-list master|head -n 1) CUR=$(git rev-list master | wc -l) echo "Before rebase, master had $CUR commits" ### get changes from svn git svn rebase REBASED=$? if [ $REBASED != 0 ] # check if rebase worked then echo "${RED}git svn rebase failed.${NC}\n" git checkout ${local_branch} exit $REBASED fi POST=$(git rev-list master | wc -l) echo "After rebase, master has $POST commits" echo "Object counts were $CUR::$POST" # if [ ! $CUR = $POST ] # check if there were changes from svn # then # # do not push yet, check if everything is good # echo "Got changes from SVN, please ensure the history is clean." # echo "Once satisfied, you can push again!" # exit 1 # fi echo "git svn rebase worked." ### commit changes to svn git svn dcommit COMMITED=$? if [ $COMMITED != 0 ] # check if rebase worked then printf "${RED}git svn dcommit failed.${NC}\n" git checkout ${local_branch} exit $COMMITED fi echo "git svn dcommit worked" ### check if svn was up to date with local changes before push (git svn dcommit changes hashes) GITSVN=$(git rev-parse git-svn) echo "local is at $HEAD" echo "svn is at $GITSVN" if [ "$HEAD" != "$GITSVN" ] # check if dcommit changed hashes then echo "svn and local git not at same revision." printf "${RED}Please check the status of all branches${NC}\n" printf "${RED}with git log for example.${NC}\n" printf "${RED}And synchronize svn and git.${NC}\n" printf "${RED}You will need to push again after.${NC}\n" git checkout ${local_branch} exit 1 fi echo "No changes between svn and local changes. Pushing..." # push only if svn was already up to date with local master git checkout ${local_branch} exit 0