1 | if [ "$GITSVNLMDZ" != "true" ];then |
---|
2 | export GITSVNLMDZ=true |
---|
3 | else |
---|
4 | exit 0 |
---|
5 | fi |
---|
6 | RED='\033[0;31m' |
---|
7 | NC='\033[0m' # No Color |
---|
8 | |
---|
9 | # check if on master |
---|
10 | local_branch=$(git branch --show-current) |
---|
11 | ROOT_DIR=$( git rev-parse --show-toplevel ) |
---|
12 | |
---|
13 | echo Branch: $local_branch |
---|
14 | |
---|
15 | echo done |
---|
16 | if [ "${local_branch}" != "master" ]; then |
---|
17 | # exit 0 # if on other branch than master, do not sync with svn |
---|
18 | use_hook=false |
---|
19 | while read local_ref local_oid remote_ref remote_oid; do |
---|
20 | # echo $local_ref $local_oid $remote_ref $remote_oid |
---|
21 | if test $local_ref = "refs/heads/master"; then |
---|
22 | use_hook=true |
---|
23 | fi |
---|
24 | done |
---|
25 | if test $use_hook = "false" ;then |
---|
26 | echo "Sync with svn not necessary, no changes in master to be pushed." |
---|
27 | echo "Continuing with push on $local_branch." |
---|
28 | exit 0 # push only on local branch |
---|
29 | fi |
---|
30 | git checkout master |
---|
31 | git pull --rebase origin master |
---|
32 | fi |
---|
33 | |
---|
34 | |
---|
35 | ### check if git svn exists |
---|
36 | git svn info>/dev/null 2>&1 |
---|
37 | GITSVN=$? |
---|
38 | if [ $GITSVN != 0 ] |
---|
39 | then |
---|
40 | printf "${RED}You need to install git svn to use this script.${NC}\n" |
---|
41 | git checkout ${local_branch} |
---|
42 | exit $GITSVN |
---|
43 | fi |
---|
44 | |
---|
45 | if [ ! -f ${ROOT_DIR}/.git/refs/remotes/git-svn ];then |
---|
46 | git svn init https://svn.lmd.jussieu.fr/Planeto/trunk |
---|
47 | git update-ref refs/remotes/git-svn refs/remotes/origin/master # this could fail if git is not up-to-date with svn... |
---|
48 | fi |
---|
49 | |
---|
50 | # git update-ref refs/remotes/git-svn refs/remotes/origin/master # tell git-svn it's up-to-date with git remote master branch |
---|
51 | |
---|
52 | HEAD=$(git rev-list master|head -n 1) |
---|
53 | CUR=$(git rev-list master | wc -l) |
---|
54 | echo "Before rebase, master had $CUR commits" |
---|
55 | |
---|
56 | ### get changes from svn |
---|
57 | git svn rebase |
---|
58 | REBASED=$? |
---|
59 | if [ $REBASED != 0 ] # check if rebase worked |
---|
60 | then |
---|
61 | echo "${RED}git svn rebase failed.${NC}\n" |
---|
62 | git checkout ${local_branch} |
---|
63 | exit $REBASED |
---|
64 | fi |
---|
65 | POST=$(git rev-list master | wc -l) |
---|
66 | echo "After rebase, master has $POST commits" |
---|
67 | echo "Object counts were $CUR::$POST" |
---|
68 | # if [ ! $CUR = $POST ] # check if there were changes from svn |
---|
69 | # then |
---|
70 | # # do not push yet, check if everything is good |
---|
71 | # echo "Got changes from SVN, please ensure the history is clean." |
---|
72 | # echo "Once satisfied, you can push again!" |
---|
73 | # exit 1 |
---|
74 | # fi |
---|
75 | echo "git svn rebase worked." |
---|
76 | |
---|
77 | ### commit changes to svn |
---|
78 | git svn dcommit < /dev/tty |
---|
79 | COMMITED=$? |
---|
80 | if [ $COMMITED != 0 ] # check if rebase worked |
---|
81 | then |
---|
82 | printf "${RED}git svn dcommit failed.${NC}\n" |
---|
83 | printf "${RED}It might just be 'normal' git-svn sync.${NC}\n" |
---|
84 | printf "${RED}You may try to push a second time.${NC}\n" |
---|
85 | printf "${RED}Be sure to check the status of all branches otherwise.${NC}\n" |
---|
86 | git checkout ${local_branch} |
---|
87 | exit $COMMITED |
---|
88 | fi |
---|
89 | echo "git svn dcommit worked" |
---|
90 | |
---|
91 | ### check if svn was up to date with local changes before push (git svn dcommit changes hashes) |
---|
92 | GITSVN=$(git rev-parse git-svn) |
---|
93 | echo "local is at $HEAD" |
---|
94 | echo "svn is at $GITSVN" |
---|
95 | if [ "$HEAD" != "$GITSVN" ] # check if dcommit changed hashes |
---|
96 | then |
---|
97 | echo "svn and local git not at same revision." |
---|
98 | printf "${RED}Please check the status of all branches${NC}\n" |
---|
99 | printf "${RED}with git log for example.${NC}\n" |
---|
100 | printf "${RED}And synchronize svn and git.${NC}\n" |
---|
101 | printf "${RED}You will need to push again after.${NC}\n" |
---|
102 | git checkout ${local_branch} |
---|
103 | exit 1 |
---|
104 | fi |
---|
105 | |
---|
106 | echo "No changes between svn and local changes. Pushing..." |
---|
107 | |
---|
108 | # push only if svn was already up to date with local master |
---|
109 | git checkout ${local_branch} |
---|
110 | exit 0 |
---|