source: trunk/UTIL/pre-push @ 3557

Last change on this file since 3557 was 3524, checked in by afalco, 5 weeks ago

git-svn: better message if git svn dcommit failed.
AF

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