Code cleanup
[gc-utils.git] / src / gc-import.sh
blob3d70a86788c71617c3596f11a3ad9b6eb4ce746a
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 " -gn pass --no-cvs-direct to cvsps"
19 echo " -u do not write an ignore file"
20 echo " -V show version information"
21 echo " -r <remote> used refs/remotes/<remote>/ to import CVS branches into"
22 echo " default is 'cvs'"
23 echo
24 exit 127
27 check_git
29 verbose=
30 cvrtudsr=
31 dir=
32 quiet="-Q"
33 ignorefile="t"
34 remote="cvs"
35 opts=
36 while test $# != 0
38 case "$1" in
39 -u)
40 ignorefile=
42 -v)
43 verbose="-v"
44 quiet=
46 -r)
47 shift
48 remote="$1"
50 -d)
51 shift
52 dir="$1"
54 -gu)
55 cvrtudsr="-u"
57 -gn)
58 opts="-p '--no-cvs-direct'"
60 -h)
61 usage
63 -V)
64 version
65 exit
67 -*)
68 echo >&2 "Parameter $1 is not known."
69 usage
72 break
74 esac
75 shift
76 done
78 CVSROOT=$1
79 MODULE=$2
81 test $# != 2 && usage
83 echo "Repository: $CVSROOT"
84 echo "Module: $MODULE"
85 echo
87 test ${#dir} -eq 0 && dir="$MODULE"
89 if test -d "$dir/.cvs"
90 then
91 echo >&2 "It seems that you are trying to use gc-import on an allready tracked repository."
92 die "Please use gc-update instead"
95 test -d "$dir" && die "directory $dir exists"
97 mkdir $dir
99 git-cvsimport $opts -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
101 test $? != 0 && die "Failed."
103 if test -n "$ignorefile"
104 then
105 if test ! -f ".gitignore"
106 then
107 echo ".cvs" > ".gitignore" && echo "Create ignore file in $PWD/.gitignore"
108 else
109 echo ".cvs" >> ".gitignore" && echo "Add ignore entry to $PWD/.gitignore"