source: trunk/UTIL/pre-push @ 3430

Last change on this file since 3430 was 3415, checked in by afalco, 3 months ago

git-svn: pre-push hook launched from other branches too. AF

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1RED='\033[0;31m'
2NC='\033[0m' # No Color
3
4# check if on master
5local_branch=$(git branch --show-current)
6if [ ${local_branch} != "master" ]; then
7    git checkout master # ensure master is in sync with svn
8fi
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
12git svn info>/dev/null 2>&1
13GITSVN=$?
14if [ $GITSVN != 0 ]
15then
16    printf "${RED}You need to install git svn to use this script.${NC}\n"
17    git checkout ${local_branch}
18    exit $GITSVN
19fi
20
21HEAD=$(git rev-list master|head -n 1)
22CUR=$(git rev-list master | wc -l)
23echo "Before rebase, master had $CUR commits"
24
25### get changes from svn
26git svn rebase
27REBASED=$?
28if [ $REBASED != 0 ] # check if rebase worked
29then
30    echo "${RED}git svn rebase failed.${NC}\n"
31    git checkout ${local_branch}
32    exit $REBASED
33fi
34POST=$(git rev-list master | wc -l)
35echo "After rebase, master has $POST commits"
36echo "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
44echo "git svn rebase worked."
45
46### commit changes to svn
47git svn dcommit
48COMMITED=$?
49if [ $COMMITED != 0 ] # check if rebase worked
50then
51    printf "${RED}git svn dcommit failed.${NC}\n"
52    git checkout ${local_branch}
53    exit $COMMITED
54fi
55echo "git svn dcommit worked"
56
57### check if svn was up to date with local changes before push (git svn dcommit changes hashes)
58GITSVN=$(git rev-parse git-svn)
59echo "local is at $HEAD"
60echo "svn   is at $GITSVN"
61if [ "$HEAD" != "$GITSVN" ] # check if dcommit changed hashes
62then
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
70fi
71
72echo "No changes between svn and local changes. Pushing..."
73
74# push only if svn was already up to date with local master
75git checkout ${local_branch}
76exit 0
Note: See TracBrowser for help on using the repository browser.