Use die shortcut instead of echo >&2 && exit 127
[gc-utils.git] / gc-import.sh
blobaabaf84e3a5ed7df5a951bb3eaf98345cce1b9c2
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] <cvsroot> <module>"
13 echo "Options are:"
14 echo " -h show help"
15 echo " -v verbosity"
16 echo " -d <dir> directory for checkout"
17 echo " -gu convert underscores during gitimport"
18 echo " -u do not write an ignore file"
19 echo " -V show version information"
20 echo " -r <remote> used refs/remotes/<remote>/ to import CVS branches into"
21 echo " default is 'cvs'"
22 echo
23 exit 127
26 check_git
28 verbose=
29 cvrtudsr=
30 dir=
31 quiet="-Q"
32 ignorefile="t"
33 remote="cvs"
34 while test $# != 0
35 do
36 case "$1" in
37 -u)
38 ignorefile=
40 -v)
41 verbose="-v"
42 quiet=
44 -r)
45 shift
46 remote="$1"
48 -d)
49 shift
50 dir="$1"
52 -gu)
53 cvrtudsr="-u"
55 -h)
56 usage
58 -V)
59 version
60 exit
62 -*)
63 echo >&2 "Parameter $1 is not known."
64 usage
67 break
69 esac
70 shift
71 done
73 CVSROOT=$1
74 MODULE=$2
76 if test $# != 2
77 then
78 usage
81 echo "Repository: $CVSROOT"
82 echo "Module: $MODULE"
83 echo
85 if test ${#dir} -eq 0
86 then
87 dir="$MODULE"
90 if test -d "$dir/.cvs"
91 then
92 echo >&2 "It seems that you are trying to use gc-import on an allready tracked repository."
93 die "Please use gc-update instead"
96 test -d "$dir" && die "directory $dir exists"
98 mkdir $dir
100 git-cvsimport -r "$remote" -a -k $verbose $cvrtudsr -m -d$CVSROOT -C "$dir" $MODULE && cd "$dir" && git-config gc-utils.remote "$remote" && echo "Initialize CVS repository in $PWD/.cvs" && cvs -d$CVSROOT $quiet -z 9 co -d ".cvs" $MODULE
102 if test $? != 0
103 then
104 die "Failed."
107 if test -n "$ignorefile"
108 then
109 if test ! -f ".gitignore"
110 then
111 echo ".cvs" > ".gitignore" && echo "Create ignore file in $PWD/.gitignore"
112 else
113 echo ".cvs" >> ".gitignore" && echo "Add ignore entry to $PWD/.gitignore"