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 | fi |
---|
32 | |
---|
33 | |
---|
34 | ### check if git svn exists |
---|
35 | git svn info>/dev/null 2>&1 |
---|
36 | GITSVN=$? |
---|
37 | if [ $GITSVN != 0 ] |
---|
38 | then |
---|
39 | printf "${RED}You need to install git svn to use this script.${NC}\n" |
---|
40 | git checkout ${local_branch} |
---|
41 | exit $GITSVN |
---|
42 | fi |
---|
43 | |
---|
44 | if [ ! -f ${ROOT_DIR}/.git/refs/remotes/git-svn ];then |
---|
45 | git svn init https://svn.lmd.jussieu.fr/Planeto/trunk |
---|
46 | git update-ref refs/remotes/git-svn refs/remotes/origin/master # this could fail if git is not up-to-date with svn... |
---|
47 | fi |
---|
48 | |
---|
49 | # git update-ref refs/remotes/git-svn refs/remotes/origin/master # tell git-svn it's up-to-date with git remote master branch |
---|
50 | |
---|
51 | HEAD=$(git rev-list master|head -n 1) |
---|
52 | CUR=$(git rev-list master | wc -l) |
---|
53 | echo "Before svn rebase, master had $CUR commits" |
---|
54 | |
---|
55 | ### get changes from svn |
---|
56 | git svn rebase |
---|
57 | REBASED=$? |
---|
58 | if [ $REBASED != 0 ] # check if rebase worked |
---|
59 | then |
---|
60 | echo "${RED}git svn rebase failed.${NC}\n" |
---|
61 | git checkout ${local_branch} |
---|
62 | exit $REBASED |
---|
63 | fi |
---|
64 | POST=$(git rev-list master | wc -l) |
---|
65 | echo "After svn rebase, master has $POST commits" |
---|
66 | echo "Object counts were $CUR::$POST" |
---|
67 | echo "git svn rebase worked." |
---|
68 | |
---|
69 | if [ ! $CUR = $POST ] # check if there were changes from svn |
---|
70 | then |
---|
71 | echo "${RED}You will need to push now.${NC}" |
---|
72 | fi |
---|
73 | |
---|