Index: /trunk/UTIL/git_init.sh
===================================================================
--- /trunk/UTIL/git_init.sh	(revision 3574)
+++ /trunk/UTIL/git_init.sh	(revision 3575)
@@ -14,12 +14,12 @@
 # echo "or download it in the git-trunk/ folder (and link with git-svn)."
 
-while true; do
-    read -p "Do you wish to continue? [Y/n] " yn
-    case $yn in
-        [Yy]* ) break;;
-        [Nn]* ) exit;;
-        * ) break;;
-    esac
-done
+# while true; do
+#     read -p "Do you wish to continue? [Y/n] " yn
+#     case $yn in
+#         [Yy]* ) break;;
+#         [Nn]* ) exit;;
+#         * ) break;;
+#     esac
+# done
 
 # URL=git@gitlab.in2p3.fr:la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk.git
@@ -40,4 +40,17 @@
 ### users push only commits in sync with svn
 
-cp UTIL/pre-push .git/hooks
+# save users hooks just in case
+echo "Saving old hooks in .git/hooks/save ..."
+mkdir -p .git/hooks
+if [ -d .git/hooks ];then
+    mkdir -p .git/hooks/save
+    mv .git/hooks/p* .git/hooks/save
+fi
+echo "Copying lmdz hooks in .git/hooks ..."
+cd .git/hooks
+for hook in ../../UTIL/hooks/*; do
+    file=$(basename $hook)
+    echo $file
+    ln -s $hook $file
+done
 
Index: /trunk/UTIL/hooks/post-checkout
===================================================================
--- /trunk/UTIL/hooks/post-checkout	(revision 3575)
+++ /trunk/UTIL/hooks/post-checkout	(revision 3575)
@@ -0,0 +1,58 @@
+if [ "$GITSVNLMDZ" != "true" ];then
+    export GITSVNLMDZ=true
+else
+    exit 0
+fi
+RED='\033[0;31m'
+NC='\033[0m' # No Color
+
+# check if on master
+local_branch=$(git branch --show-current)
+ROOT_DIR=$( git rev-parse --show-toplevel )
+
+echo Branch: $local_branch
+
+echo done
+if [ "${local_branch}" != "master" ]; then
+    exit 0 # if on other branch than master, do not sync with svn
+fi
+
+
+### check if git svn exists
+git svn info>/dev/null 2>&1
+GITSVN=$?
+if [ $GITSVN != 0 ]
+then
+    printf "${RED}You need to install git svn to use this script.${NC}\n"
+    exit $GITSVN
+fi
+
+if [ ! -f ${ROOT_DIR}/.git/refs/remotes/git-svn ];then
+    git svn init https://svn.lmd.jussieu.fr/Planeto/trunk
+    git update-ref refs/remotes/git-svn refs/remotes/origin/master # this could fail if git is not up-to-date with svn...
+fi
+
+# git update-ref refs/remotes/git-svn refs/remotes/origin/master # tell git-svn it's up-to-date with git remote master branch
+
+HEAD=$(git rev-list master|head -n 1)
+CUR=$(git rev-list master | wc -l)
+echo "Before svn rebase, master had $CUR commits"
+
+### get changes from svn
+git svn rebase
+REBASED=$?
+if [ $REBASED != 0 ] # check if rebase worked
+then
+    echo "${RED}git svn rebase failed.${NC}\n"
+    exit $REBASED
+fi
+POST=$(git rev-list master | wc -l)
+echo "After svn rebase, master has $POST commits"
+echo "Object counts were $CUR::$POST"
+
+echo "git svn rebase worked."
+if [ ! $CUR = $POST ] # check if there were changes from svn
+then
+    echo "${RED}You will need to push now.${NC}"
+fi
+
Index: /trunk/UTIL/hooks/post-merge
===================================================================
--- /trunk/UTIL/hooks/post-merge	(revision 3575)
+++ /trunk/UTIL/hooks/post-merge	(revision 3575)
@@ -0,0 +1,73 @@
+if [ "$GITSVNLMDZ" != "true" ];then
+    export GITSVNLMDZ=true
+else
+    exit 0
+fi
+RED='\033[0;31m'
+NC='\033[0m' # No Color
+
+# check if on master
+local_branch=$(git branch --show-current)
+ROOT_DIR=$( git rev-parse --show-toplevel )
+
+echo Branch: $local_branch
+
+echo done
+if [ ${local_branch} != "master" ]; then
+    # exit 0 # if on other branch than master, do not sync with svn
+    use_hook=false
+    while read local_ref local_oid remote_ref remote_oid; do
+        # echo $local_ref $local_oid $remote_ref $remote_oid
+        if test $local_ref = "refs/heads/master"; then
+            use_hook=true
+        fi
+    done
+    if test $use_hook = "false" ;then
+        echo "Sync with svn not necessary, no changes in master to be pushed."
+        echo "Continuing with push on $local_branch."
+        exit 0 # push only on local branch
+    fi
+    git checkout master
+fi
+
+
+### check if git svn exists
+git svn info>/dev/null 2>&1
+GITSVN=$?
+if [ $GITSVN != 0 ]
+then
+    printf "${RED}You need to install git svn to use this script.${NC}\n"
+    git checkout ${local_branch}
+    exit $GITSVN
+fi
+
+if [ ! -f ${ROOT_DIR}/.git/refs/remotes/git-svn ];then
+    git svn init https://svn.lmd.jussieu.fr/Planeto/trunk
+    git update-ref refs/remotes/git-svn refs/remotes/origin/master # this could fail if git is not up-to-date with svn...
+fi
+
+# git update-ref refs/remotes/git-svn refs/remotes/origin/master # tell git-svn it's up-to-date with git remote master branch
+
+HEAD=$(git rev-list master|head -n 1)
+CUR=$(git rev-list master | wc -l)
+echo "Before svn rebase, master had $CUR commits"
+
+### get changes from svn
+git svn rebase
+REBASED=$?
+if [ $REBASED != 0 ] # check if rebase worked
+then
+    echo "${RED}git svn rebase failed.${NC}\n"
+    git checkout ${local_branch}
+    exit $REBASED
+fi
+POST=$(git rev-list master | wc -l)
+echo "After svn rebase, master has $POST commits"
+echo "Object counts were $CUR::$POST"
+echo "git svn rebase worked."
+
+if [ ! $CUR = $POST ] # check if there were changes from svn
+then
+    echo "${RED}You will need to push now.${NC}"
+fi
+
Index: /trunk/UTIL/hooks/pre-push
===================================================================
--- /trunk/UTIL/hooks/pre-push	(revision 3575)
+++ /trunk/UTIL/hooks/pre-push	(revision 3575)
@@ -0,0 +1,110 @@
+if [ "$GITSVNLMDZ" != "true" ];then
+    export GITSVNLMDZ=true
+else
+    exit 0
+fi
+RED='\033[0;31m'
+NC='\033[0m' # No Color
+
+# check if on master
+local_branch=$(git branch --show-current)
+ROOT_DIR=$( git rev-parse --show-toplevel )
+
+echo Branch: $local_branch
+
+echo done
+if [ "${local_branch}" != "master" ]; then
+    # exit 0 # if on other branch than master, do not sync with svn
+    use_hook=false
+    while read local_ref local_oid remote_ref remote_oid; do
+        # echo $local_ref $local_oid $remote_ref $remote_oid
+        if test $local_ref = "refs/heads/master"; then
+            use_hook=true
+        fi
+    done
+    if test $use_hook = "false" ;then
+        echo "Sync with svn not necessary, no changes in master to be pushed."
+        echo "Continuing with push on $local_branch."
+        exit 0 # push only on local branch
+    fi
+    git checkout master
+    git pull --rebase origin master
+fi
+
+
+### check if git svn exists
+git svn info>/dev/null 2>&1
+GITSVN=$?
+if [ $GITSVN != 0 ]
+then
+    printf "${RED}You need to install git svn to use this script.${NC}\n"
+    git checkout ${local_branch}
+    exit $GITSVN
+fi
+
+if [ ! -f ${ROOT_DIR}/.git/refs/remotes/git-svn ];then
+    git svn init https://svn.lmd.jussieu.fr/Planeto/trunk
+    git update-ref refs/remotes/git-svn refs/remotes/origin/master # this could fail if git is not up-to-date with svn...
+fi
+
+# git update-ref refs/remotes/git-svn refs/remotes/origin/master # tell git-svn it's up-to-date with git remote master branch
+
+HEAD=$(git rev-list master|head -n 1)
+CUR=$(git rev-list master | wc -l)
+echo "Before rebase, master had $CUR commits"
+
+### get changes from svn
+git svn rebase
+REBASED=$?
+if [ $REBASED != 0 ] # check if rebase worked
+then
+    echo "${RED}git svn rebase failed.${NC}\n"
+    git checkout ${local_branch}
+    exit $REBASED
+fi
+POST=$(git rev-list master | wc -l)
+echo "After rebase, master has $POST commits"
+echo "Object counts were $CUR::$POST"
+# if [ ! $CUR = $POST ] # check if there were changes from svn
+# then
+#     # do not push yet, check if everything is good
+#     echo "Got changes from SVN, please ensure the history is clean."
+#     echo "Once satisfied, you can push again!"
+#     exit 1
+# fi
+echo "git svn rebase worked."
+
+### commit changes to svn
+git svn dcommit < /dev/tty
+COMMITED=$?
+if [ $COMMITED != 0 ] # check if rebase worked
+then
+    printf "${RED}git svn dcommit failed.${NC}\n"
+    printf "${RED}It might just be 'normal' git-svn sync.${NC}\n"
+    printf "${RED}You may try to push a second time.${NC}\n"
+    printf "${RED}Be sure to check the status of all branches otherwise.${NC}\n"
+    git checkout ${local_branch}
+    exit $COMMITED
+fi
+echo "git svn dcommit worked"
+
+### check if svn was up to date with local changes before push (git svn dcommit changes hashes)
+GITSVN=$(git rev-parse git-svn)
+echo "local is at $HEAD"
+echo "svn   is at $GITSVN"
+if [ "$HEAD" != "$GITSVN" ] # check if dcommit changed hashes
+then
+    echo "svn and local git not at same revision."
+    printf "${RED}Please check the status of all branches${NC}\n"
+    printf "${RED}with git log for example.${NC}\n"
+    printf "${RED}And synchronize svn and git.${NC}\n"
+    printf "${RED}You will need to push again after.${NC}\n"
+    git checkout ${local_branch}
+    exit 1
+fi
+
+echo "No changes between svn and local changes. Pushing..."
+
+# push only if svn was already up to date with local master
+git checkout ${local_branch}
+exit 0
