[3413] | 1 | RED='\033[0;31m' |
---|
| 2 | NC='\033[0m' # No Color |
---|
| 3 | |
---|
| 4 | # check if on master |
---|
[3415] | 5 | local_branch=$(git branch --show-current) |
---|
| 6 | if [ ${local_branch} != "master" ]; then |
---|
[3440] | 7 | # exit 0 # if on other branch than master, do not sync with svn |
---|
| 8 | git checkout master |
---|
| 9 | git pull origin master |
---|
[3413] | 10 | fi |
---|
| 11 | # git update-ref refs/remotes/git-svn refs/remotes/origin/master # what's this supposed to do? |
---|
| 12 | |
---|
| 13 | ### check if git svn exists |
---|
| 14 | git svn info>/dev/null 2>&1 |
---|
| 15 | GITSVN=$? |
---|
| 16 | if [ $GITSVN != 0 ] |
---|
| 17 | then |
---|
| 18 | printf "${RED}You need to install git svn to use this script.${NC}\n" |
---|
[3415] | 19 | git checkout ${local_branch} |
---|
[3413] | 20 | exit $GITSVN |
---|
| 21 | fi |
---|
| 22 | |
---|
| 23 | HEAD=$(git rev-list master|head -n 1) |
---|
| 24 | CUR=$(git rev-list master | wc -l) |
---|
| 25 | echo "Before rebase, master had $CUR commits" |
---|
| 26 | |
---|
| 27 | ### get changes from svn |
---|
| 28 | git svn rebase |
---|
| 29 | REBASED=$? |
---|
| 30 | if [ $REBASED != 0 ] # check if rebase worked |
---|
| 31 | then |
---|
| 32 | echo "${RED}git svn rebase failed.${NC}\n" |
---|
[3415] | 33 | git checkout ${local_branch} |
---|
[3413] | 34 | exit $REBASED |
---|
| 35 | fi |
---|
| 36 | POST=$(git rev-list master | wc -l) |
---|
| 37 | echo "After rebase, master has $POST commits" |
---|
| 38 | echo "Object counts were $CUR::$POST" |
---|
| 39 | # if [ ! $CUR = $POST ] # check if there were changes from svn |
---|
| 40 | # then |
---|
| 41 | # # do not push yet, check if everything is good |
---|
| 42 | # echo "Got changes from SVN, please ensure the history is clean." |
---|
| 43 | # echo "Once satisfied, you can push again!" |
---|
| 44 | # exit 1 |
---|
| 45 | # fi |
---|
| 46 | echo "git svn rebase worked." |
---|
| 47 | |
---|
| 48 | ### commit changes to svn |
---|
[3440] | 49 | git svn dcommit < /dev/tty |
---|
[3413] | 50 | COMMITED=$? |
---|
| 51 | if [ $COMMITED != 0 ] # check if rebase worked |
---|
| 52 | then |
---|
| 53 | printf "${RED}git svn dcommit failed.${NC}\n" |
---|
[3415] | 54 | git checkout ${local_branch} |
---|
[3413] | 55 | exit $COMMITED |
---|
| 56 | fi |
---|
| 57 | echo "git svn dcommit worked" |
---|
| 58 | |
---|
| 59 | ### check if svn was up to date with local changes before push (git svn dcommit changes hashes) |
---|
| 60 | GITSVN=$(git rev-parse git-svn) |
---|
| 61 | echo "local is at $HEAD" |
---|
[3414] | 62 | echo "svn is at $GITSVN" |
---|
[3413] | 63 | if [ "$HEAD" != "$GITSVN" ] # check if dcommit changed hashes |
---|
| 64 | then |
---|
| 65 | echo "svn and local git not at same revision." |
---|
| 66 | printf "${RED}Please check the status of all branches${NC}\n" |
---|
| 67 | printf "${RED}with git log for example.${NC}\n" |
---|
| 68 | printf "${RED}And synchronize svn and git.${NC}\n" |
---|
| 69 | printf "${RED}You will need to push again after.${NC}\n" |
---|
[3415] | 70 | git checkout ${local_branch} |
---|
[3413] | 71 | exit 1 |
---|
| 72 | fi |
---|
| 73 | |
---|
| 74 | echo "No changes between svn and local changes. Pushing..." |
---|
| 75 | |
---|
| 76 | # push only if svn was already up to date with local master |
---|
[3415] | 77 | git checkout ${local_branch} |
---|
[3413] | 78 | exit 0 |
---|