source: trunk/UTIL/hooks/post-merge @ 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: 2.0 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
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
31fi
32
33
34### check if git svn exists
35git svn info>/dev/null 2>&1
36GITSVN=$?
37if [ $GITSVN != 0 ]
38then
39    printf "${RED}You need to install git svn to use this script.${NC}\n"
40    git checkout ${local_branch}
41    exit $GITSVN
42fi
43
44if [ ! -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...
47fi
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
51HEAD=$(git rev-list master|head -n 1)
52CUR=$(git rev-list master | wc -l)
53echo "Before svn rebase, master had $CUR commits"
54
55### get changes from svn
56git svn rebase
57REBASED=$?
58if [ $REBASED != 0 ] # check if rebase worked
59then
60    echo "${RED}git svn rebase failed.${NC}\n"
61    git checkout ${local_branch}
62    exit $REBASED
63fi
64POST=$(git rev-list master | wc -l)
65echo "After svn rebase, master has $POST commits"
66echo "Object counts were $CUR::$POST"
67echo "git svn rebase worked."
68
69if [ ! $CUR = $POST ] # check if there were changes from svn
70then
71    echo "${RED}You will need to push now.${NC}"
72fi
73
Note: See TracBrowser for help on using the repository browser.