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