Remove the .cvsps cache in the home directory if it exists and use a global CVSMODULE...
[gc-utils.git] / gc-update.sh
blob58942aefd4f184b925603414a4704d8df0662082
1 #!/bin/sh
2 # Copyright (c) 2007 David Soria Parra <dsp at php dot net>
4 # Licensed under the terms of the MIT License
5 # See /usr/share/doc/gcutils/copyright
6 # or http://www.opensource.org/licenses/mit-license.php
7 VERSION="$VERSION$"
8 PROGNAME="$PROGNAME$"
10 check_git ()
13 git --version > /dev/null
15 if test $? != 0
16 then
17 echo >&2 "Git not found. It's either not installed or not in \$PATH"
18 exit 127
21 version=`git --version | grep -o "[12]\.[5-9]\.[0-9]"`
22 if test -z "$version"
23 then
24 echo "Wrong git version. $prog needs git 1.5.0 or higher, but "`git --version`" found."
25 exit 127
29 version ()
31 echo "$PROGNAME: "`basename $0`-$VERSION
34 locate_git_repo () {
35 gitdir=`git-rev-parse --git-dir 2> /dev/null`
36 if test "$gitdir" = ""
37 then
38 echo >&2 "Please use this command from a git working tree."
39 exit 127
41 cd $gitdir/..
44 usage ()
46 echo "Usage: "`basename $0`" [OPTIONS]"
47 echo "Options are:"
48 echo " -h show help"
49 echo " -v verbosity"
50 echo " -m use merge strategy instead of rebasing"
51 echo " -cn do not update the cvs repository"
52 echo " -V show version information"
53 echo
54 exit 127
57 check_git
59 cvsupdate=t
60 verbose=
61 quiet="-q"
62 do_rebase="-i"
63 while test $# != 0
65 case "$1" in
66 -m)
67 do_rebase=
69 -v)
70 verbose="-v"
71 quiet=""
73 -cn)
74 cvsupdate=""
76 -h)
77 usage
79 -V)
80 version
81 exit
83 -*)
84 echo >&2 "Parameter $1 is not known."
85 usage
87 esac
88 shift
89 done
92 locate_git_repo
94 branch=`git branch | grep "^* " | cut -c 3-`
96 if test ! ".cvs" -o ! -d ".cvs/CVS/"
97 then
98 echo >&2 "Cannot found .cvs directory"
99 exit 127
102 CVSROOT=`cat .cvs/CVS/Root`
103 MODULE=`cat .cvs/CVS/Repository`
105 echo "Repository: $CVSROOT"
106 echo "Module: $MODULE"
107 echo "GIT Branch: $branch"
108 echo ""
110 # first stash away our local changes
111 echo "Stashing local changes"
112 git stash save "stashed by gcutils"
113 echo ""
115 # if -m is not specified we do a rebase instead of a merge
116 # therefore git cvsimport will be called -i ($do_rebase)
117 git-cvsimport $do_rebase $verbose -a -m -k -d $CVSROOT "$MODULE"
119 if test -n "$do_rebase"
120 then
121 # we actually did not yet merged back into master but we try to rebase
122 git-rebase origin master
123 if test $? -ne 0
124 then
125 git-rebase --abort
126 echo "Rebasing failed."
127 echo "Please use rebase to rebase the origin branch or use merge to"
128 echo "do a merge instead. Notice that merge might result in duplicated commits"
129 echo
130 echo "gc utils aborted the rebase"
132 git-checkout $branch 1>/dev/null 2>/dev/null
134 # reapply our stashed dirty changes
135 echo ""
136 echo "Reapplying local changes"
138 test -n "$verbose" && git-stash pop
139 test -z "$verbose" && git-stash pop 2>/dev/null 1>/dev/null
141 exit 127
144 git-checkout $branch 1>/dev/null 2>/dev/null
146 # reapply our stashed dirty changes
147 echo ""
148 echo "Reapplying local changes"
149 test -n "$verbose" && git-stash pop
150 test -z "$verbose" && git-stash pop 2>/dev/null 1>/dev/null
154 if test -n "$cvsupdate"
155 then
156 cd .cvs
157 cvs $quiet update