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