3 # Copyright © 2008-2011 Nick Bowler
5 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
6 # This is free software: you are free to do what the fuck you want to.
7 # There is NO WARRANTY, to the extent permitted by law.
9 # List all commits that have not yet been committed to CVS. (run this command
10 # from the root of the CVS repository)
11 git-cvs-commitlist() {
12 if [[ -z "$1" ]]; then
13 echo "usage: git-cvs-commitlist <git_dir> [origin]" 1>&2
17 [[ -z "$2" ]] && 2="remotes/CVS/master"
18 [[ -d "$1/.git" ]] && 1="$1/.git"
20 GIT_DIR="$1" git cherry -v "$2"
23 # Commit a specified commit to CVS (run this command from the root of the CVS
26 if [[ -z "$1" || -z "$2" ]]; then
27 echo "usage: git-cvs-commit <git_dir> <commit>" 1>&2
31 [[ -d "$1/.git" ]] && 1="$1/.git"
33 GIT_DIR="$1" git cvsexportcommit -cvp "$2"
36 # Commit all commits that are not yet in CVS to CVS.
37 # (run this command from the root of the CVS repository).
38 git-cvs-commit-all() {
39 if [[ -z "$1" ]]; then
40 echo "usage: git-cvs-commit-all <git_dir>" 1>&2
44 git-cvs-commitlist $1 | while read i; do
45 local commit=$(echo $i | cut -d ' ' -f 2)
46 git-cvs-commit $1 $commit || return $?
50 # Import the latest and greatest changes into a git repository (will create
51 # a new repository if run outside of any git repo).
53 # The details used to fetch from CVS are recorded so that running
54 # git-cvs-fetch with no arguments will repeat the same fetch as last time.
55 # Currently, some arguments which don't make sense to record are recorded
56 # anyway, so you may need to manually edit .git/config afterwards...
58 local tmp cvsroot cvsmod cvsopts
60 cvsroot=${$(git config cvs.root):-$CVSROOT}
61 cvsopts=${$(git config cvs.opts):-'$@'}
62 eval "cvsopts=($cvsopts)"
64 # Extract a CVS root from opts, if any.
65 while [[ $((tmp=${cvsopts[(i)-d*]})) -le $#cvsopts ]]; do
66 cvsroot=${cvsopts[$tmp]#-d}
67 cvsopts=($cvsopts[1,$tmp-1] $cvsopts[$tmp+1,-1])
68 if [[ -z $cvsroot ]]; then
69 cvsroot=${cvsopts[$tmp]}
70 cvsopts=($cvsopts[1,$tmp-1] $cvsopts[$tmp+1,-1])
74 if ! cvsmod=$(git config cvs.module); then
76 cvsopts=($cvsopts[1,-2])
79 # By this point, we must have a CVS root and module.
80 if [[ -z $cvsroot ]]; then
81 printf '%s: no CVS root set.\n' $0 1>&2
85 if [[ -z $cvsmod ]]; then
86 printf '%s: no CVS module set.\n' $0 1>&2
90 GIT_DIR=`git rev-parse --git-dir 2>/dev/null` git cvsimport \
91 -air CVS -d $cvsroot $cvsopts $cvsmod || return 1
93 # Store the settings for this run.
94 git config cvs.root $cvsroot
95 git config cvs.module $cvsmod
96 [[ $#cvsopts -gt 0 ]] && git config cvs.opts ${(j: :)${(qq)cvsopts}}
100 # Generate an excludes file, suitable for writing to .git/info/exclude, based
101 # on .cvsignore files found in the repository. Run this command from the git
103 git-cvs-genexclude() {
104 local dir i j cvsdefaults work
106 work=`git rev-parse --show-toplevel` || return 1
107 if test -z $work; then
108 printf '%s: must be run from the work tree\n' $0 1>&2
112 printf '#\n# Automatically generated by %s\n#\n' "$0 $*"
114 # CVS ignores a number of patterns by default.
116 'RCS' 'SCCS' 'CVS' 'CVS.adm' 'RCSLOG' 'cvslog.*'
117 'tags' 'TAGS' '.make.state' '.nse_depinfo'
118 '*~' '#*' '.#*' ',*' '_$*' '*$'
119 '*.old' '*.bak' '*.BAK' '*.orig' '*.rej' '.del-*'
120 '*.a' '*.olb' '*.o' '*.obj' '*.so' '*.exe'
121 '*.Z' '*.elc' '*.ln' 'core'
123 printf '%s\n' $cvsdefaults
125 find $work -name .cvsignore | while read i; do
126 dir=${$(dirname $i)#$work}
128 < $i while read j; do
129 printf '%s/%s\n' $dir $j
134 # For executable-like invocation...
136 # It would be nice if we could detect whether we are invoked as an executable
137 # and print a usage message if not given any arguments. I have yet to find
138 # a clean way to do this, however.
140 if [ $# -gt 0 ]; then
141 func="git-cvs-${1#git-cvs-}"