source: trunk/UTIL/pre-push @ 3443

Last change on this file since 3443 was 3440, checked in by afalco, 2 months ago

general: interactive git svn dcommit.
AF

  • Property svn:executable set to *
File size: 2.3 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    # exit 0 # if on other branch than master, do not sync with svn
8    git checkout master
9    git pull origin master
10fi
11# git update-ref refs/remotes/git-svn refs/remotes/origin/master # what's this supposed to do?
12
13### check if git svn exists
14git svn info>/dev/null 2>&1
15GITSVN=$?
16if [ $GITSVN != 0 ]
17then
18    printf "${RED}You need to install git svn to use this script.${NC}\n"
19    git checkout ${local_branch}
20    exit $GITSVN
21fi
22
23HEAD=$(git rev-list master|head -n 1)
24CUR=$(git rev-list master | wc -l)
25echo "Before rebase, master had $CUR commits"
26
27### get changes from svn
28git svn rebase
29REBASED=$?
30if [ $REBASED != 0 ] # check if rebase worked
31then
32    echo "${RED}git svn rebase failed.${NC}\n"
33    git checkout ${local_branch}
34    exit $REBASED
35fi
36POST=$(git rev-list master | wc -l)
37echo "After rebase, master has $POST commits"
38echo "Object counts were $CUR::$POST"
39# if [ ! $CUR = $POST ] # check if there were changes from svn
40# then
41#     # do not push yet, check if everything is good
42#     echo "Got changes from SVN, please ensure the history is clean."
43#     echo "Once satisfied, you can push again!"
44#     exit 1
45# fi
46echo "git svn rebase worked."
47
48### commit changes to svn
49git svn dcommit < /dev/tty
50COMMITED=$?
51if [ $COMMITED != 0 ] # check if rebase worked
52then
53    printf "${RED}git svn dcommit failed.${NC}\n"
54    git checkout ${local_branch}
55    exit $COMMITED
56fi
57echo "git svn dcommit worked"
58
59### check if svn was up to date with local changes before push (git svn dcommit changes hashes)
60GITSVN=$(git rev-parse git-svn)
61echo "local is at $HEAD"
62echo "svn   is at $GITSVN"
63if [ "$HEAD" != "$GITSVN" ] # check if dcommit changed hashes
64then
65    echo "svn and local git not at same revision."
66    printf "${RED}Please check the status of all branches${NC}\n"
67    printf "${RED}with git log for example.${NC}\n"
68    printf "${RED}And synchronize svn and git.${NC}\n"
69    printf "${RED}You will need to push again after.${NC}\n"
70    git checkout ${local_branch}
71    exit 1
72fi
73
74echo "No changes between svn and local changes. Pushing..."
75
76# push only if svn was already up to date with local master
77git checkout ${local_branch}
78exit 0
Note: See TracBrowser for help on using the repository browser.