source: trunk/UTIL/pre-push @ 3414

Last change on this file since 3414 was 3414, checked in by afalco, 10 months ago

git init in UTIL/ dir + README. AF

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