Merge branch 'maint'
[gc-utils.git] / gc-update.sh
blobc2b69277c8e37ddd7183fafea5d6fb1712b44f21
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
8 . $LIBDIR$/gc-sh-setup
10 usage ()
12 echo "Usage: "`basename $0`" [OPTIONS]"
13 echo "Options are:"
14 echo " -h show help"
15 echo " -v verbosity"
16 echo " -m use merge strategy instead of rebasing"
17 echo " -cn do not update the cvs repository"
18 echo " -V show version information"
19 echo
20 exit 127
23 check_git
25 cvsupdate=t
26 verbose=
27 quiet="-q"
28 do_rebase="-i"
29 while test $# != 0
31 case "$1" in
32 -m)
33 do_rebase=
35 -v)
36 verbose="-v"
37 quiet=""
39 -cn)
40 cvsupdate=""
42 -h)
43 usage
45 -V)
46 version
47 exit
49 -*)
50 echo >&2 "Parameter $1 is not known."
51 usage
53 esac
54 shift
55 done
58 locate_git_repo
60 if test ! ".cvs" -o ! -d ".cvs/CVS/"
61 then
62 echo >&2 "CVS working directory not found."
63 die "Make sure you imported your CVS repository using gc-import."
66 branch=`git branch | grep "^* " | cut -c 3-`
68 CVSROOT=`cat .cvs/CVS/Root`
69 MODULE=`cat .cvs/CVS/Repository`
71 echo "Repository: $CVSROOT"
72 echo "Module: $MODULE"
73 echo "GIT Branch: $branch"
74 echo ""
76 # first stash away our local changes
77 echo "Stashing local changes"
78 test -n "$verbose" && git stash save "stashed by gcutils"
79 test -z "$verbose" && git stash save "stashed by gcutils" 2>/dev/null 1>/dev/null
80 echo ""
82 echo "Updating"
84 remote=`git-config gc-utils.remote`
86 if test -n "$remote"
87 then
88 refspec="refs/remotes/$remote/master"
89 remote="-r $remote"
90 else
91 refspec="refs/heads/origin"
92 remote=""
95 # if -m is not specified we do a rebase instead of a merge
96 # therefore git cvsimport will be called -i ($do_rebase)
97 git-cvsimport $remote $do_rebase $verbose -a -m -k -d $CVSROOT "$MODULE"
99 if test -n "$do_rebase"
100 then
101 # we actually did not yet merged back into master but we try to rebase
102 git-rebase `git show-ref -s $refspec` master
103 if test $? -ne 0
104 then
105 git-rebase --abort
106 echo "Rebasing failed."
107 echo "Please use rebase to rebase the origin branch or use merge to"
108 echo "do a merge instead. Notice that merge might result in duplicated commits"
109 echo
110 echo "gc utils aborted the rebase"
112 git-checkout $branch 1>/dev/null 2>/dev/null
114 # reapply our stashed dirty changes
115 echo ""
116 echo "Reapplying local changes"
118 test -n "$verbose" && git-stash pop
119 test -z "$verbose" && git-stash pop 2>/dev/null 1>/dev/null
121 exit 127
125 git-checkout $branch 1>/dev/null 2>/dev/null
127 # reapply our stashed dirty changes
128 echo ""
129 echo "Reapplying local changes"
130 test -n "$verbose" && git-stash pop
131 test -z "$verbose" && git-stash pop 2>/dev/null 1>/dev/null
133 if test -n "$cvsupdate"
134 then
135 echo "Running cvs update"
136 cd .cvs
137 cvs $quiet update -d -P