source: trunk/UTIL/hooks/post-checkout @ 3575

Last change on this file since 3575 was 3575, checked in by afalco, 17 hours ago

git-svn: added hooks on other operations such as merge and checkout, to synchronize git and svn more often (not just git push).

Unfortunately, "git pull" will still not call the hook if there are no changes on git remote master.
AF

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1if [ "$GITSVNLMDZ" != "true" ];then
2    export GITSVNLMDZ=true
3else
4    exit 0
5fi
6RED='\033[0;31m'
7NC='\033[0m' # No Color
8
9# check if on master
10local_branch=$(git branch --show-current)
11ROOT_DIR=$( git rev-parse --show-toplevel )
12
13echo Branch: $local_branch
14
15echo done
16if [ "${local_branch}" != "master" ]; then
17    exit 0 # if on other branch than master, do not sync with svn
18fi
19
20
21### check if git svn exists
22git svn info>/dev/null 2>&1
23GITSVN=$?
24if [ $GITSVN != 0 ]
25then
26    printf "${RED}You need to install git svn to use this script.${NC}\n"
27    exit $GITSVN
28fi
29
30if [ ! -f ${ROOT_DIR}/.git/refs/remotes/git-svn ];then
31    git svn init https://svn.lmd.jussieu.fr/Planeto/trunk
32    git update-ref refs/remotes/git-svn refs/remotes/origin/master # this could fail if git is not up-to-date with svn...
33fi
34
35# git update-ref refs/remotes/git-svn refs/remotes/origin/master # tell git-svn it's up-to-date with git remote master branch
36
37HEAD=$(git rev-list master|head -n 1)
38CUR=$(git rev-list master | wc -l)
39echo "Before svn rebase, master had $CUR commits"
40
41### get changes from svn
42git svn rebase
43REBASED=$?
44if [ $REBASED != 0 ] # check if rebase worked
45then
46    echo "${RED}git svn rebase failed.${NC}\n"
47    exit $REBASED
48fi
49POST=$(git rev-list master | wc -l)
50echo "After svn rebase, master has $POST commits"
51echo "Object counts were $CUR::$POST"
52
53echo "git svn rebase worked."
54if [ ! $CUR = $POST ] # check if there were changes from svn
55then
56    echo "${RED}You will need to push now.${NC}"
57fi
58
Note: See TracBrowser for help on using the repository browser.