Rebase only the master and save the current branch to go back to it after rebasing
[gc-utils.git] / gc-commit.sh
blobf41bafeb3a66115ab22e60a4cd7d5e2cb5d121a7
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] <sha1>"
47 echo "Options are:"
48 echo " -h show help"
49 echo " -C run a cvsclean. "
50 echo " WARNING: this will run cvs up -C"
51 echo " and then remove all found .#* files"
52 echo " -c commit to cvs if no errors occured"
53 echo " -f force patching in case of an unclean"
54 echo " cvs repository"
55 echo " -V show version information"
56 echo
57 exit 127
60 check_git
62 cvsclean=
63 commit=
64 force=
65 while test $# != 0
66 do
67 case "$1" in
68 -c)
69 commit="-c"
71 -C)
72 cvsclean=t
74 -f)
75 force="-f"
77 -h)
78 usage
80 -V)
81 version
82 exit
84 -*)
85 echo >&2 "Parameter $1 is not known."
86 usage
89 break
91 esac
92 shift
93 done
95 if test $# = 0 ; then
96 usage
99 locate_git_repo
101 if test "$cvsclean" = "t"
102 then
103 cd ".cvs" && cvs up -C && find . -iname ".#*" -exec rm '{}' \;
106 if test -d ".git" -a -d ".cvs"
107 then
108 cd ".cvs"
109 GIT_DIR="../.git" git-cvsexportcommit -v $force $commit -u $1
110 else
111 if test -d ".git"
112 then
113 echo >&2 "Not a git repository"
116 if test -d ".cvs"
117 then
118 echo >&2 "No cvs repository found in .cvs. "
119 echo >&2 "Make sure you follow the standards"
123 cd $OLDPWD