How to add CVS directories recursively
Asked Answered
I

14

40

I've played with CVS a little bit and am not the most familiar with all of its capabilities, but a huge annoyance for me is trying to add new directories that contain more directories in them. Running "cvs add" only adds the contents of the current directory, and using "cvs import" didn't look like the right thing either since it's still all code I'm producing (this howto claimed import is for 3rd party sources)

Do you guys know any way to recursively add everything in a given directory to the current CVS project (or if SVN or git makes this notably easier)?

Inhospitality answered 7/8, 2008 at 18:5 Comment(1)
yes, both SVN and git are notably easier for recursively including directories.Intratelluric
E
11

Ah, spaces. This will work with spaces:

find . -type f -print0| xargs -0 cvs add
Entomophagous answered 7/8, 2008 at 20:22 Comment(2)
You actually have to make sure you don't add directories named 'CVS' to cvs, for some reason cvs sometimes catches this, sometimes it doesn't. Run this instead: find . \! -name "CVS" -and \! -name "Entries" -and \! -name "Repository" -and \! -name "Root" -tyInhospitality
Although this is a good start, it needs a lot of exclusions to be fully useful.Pepys
T
75

I found this worked pretty effectively:

First, add all the directories, but not any named "CVS":

find . -type d \! -name CVS -exec cvs add '{}' \;

Then add all the files, excluding anything in a CVS directory:

find . \( -type d -name CVS -prune \) -o \( -type f -exec cvs add '{}' \; \)

Now, if anyone has a cure for the embarrassment of using CVS in this day and age...

Tarryn answered 1/3, 2011 at 17:31 Comment(2)
I used it on a directory hierarchy with hundreds of directories and thousands of files, worked like a charm. Thanks!Heber
cvs is just easy to use for simple easy or 1 or 2 person non-branching "backup" and "share" source controlPepys
E
11

Ah, spaces. This will work with spaces:

find . -type f -print0| xargs -0 cvs add
Entomophagous answered 7/8, 2008 at 20:22 Comment(2)
You actually have to make sure you don't add directories named 'CVS' to cvs, for some reason cvs sometimes catches this, sometimes it doesn't. Run this instead: find . \! -name "CVS" -and \! -name "Entries" -and \! -name "Repository" -and \! -name "Root" -tyInhospitality
Although this is a good start, it needs a lot of exclusions to be fully useful.Pepys
M
11

I use this:

First add recursively all directories less the CVS ones:

$> find . -type d \! -name CVS -exec cvs add '{}' \;

Second add all files, less ones the CVS directories:

 find . \( -type d -name CVS -prune \) -o \( -type f -exec cvs add '{}' \; \)

Third do “commit” recursively like "first version" comment:

 find . \( -type d -name CVS -prune \) -o \( -type f -exec cvs commit -m "first version" '{}' \; \)

Last tagging all recursively:

 find . \( -type d -name CVS -prune \) -o \( -type f -exec cvs tag -F MY_CVS_TAG '{}' \; \)
Metalloid answered 17/7, 2014 at 8:21 Comment(3)
On Mac: find . ( -type d -name CVS -prune ) -o ( -type f ! -name '.DS_Store' -exec cvs add '{}' \; )Lotuseater
Very useful commands, but in what case CVS commit recursively is required as "cvs commit" will commit all files?Lacreshalacrimal
I used it when I had to upload an existing project to a repositoryMetalloid
P
6

First add all directories to CVS

find . -type d -print0| xargs -0 cvs add

Then add all the files in the directories to CVS

find . -type f | grep -v CVS | xargs cvs add

Worked for me

Pistole answered 5/10, 2010 at 8:46 Comment(1)
Does not exclude files in CVS folders.Pancratium
K
2

cvs import is not just for 3rd-party sources. In fact, directories are not versioned by CVS, so they are not a subject to branch policies. As long as you import empty directories, it is fine.

Kierakieran answered 29/8, 2008 at 21:28 Comment(0)
P
2

Note that you can only use cvs add on files and folders that are located inside an already checked out working copy, otherwise you will get the "Cannot open CVS/Entries for reading" message. A technique for creating a new "root module" using cvs add is explained in this WinCVS FAQ item: http://cvsgui.sourceforge.net/newfaq.htm#add_rootmodule

If you are on Windows, both TortoiseCVS and WinCVS support recursive addition (and optional commit) of multiple files in a single operation. In WinCvs look for the macro Add>Recursive Add (auto-commit)... In Tortoise use the Add Contents command on a directory. Both will allow you to select which files to add and what keyword expansion modes to use for them (mostly used for defining which files are binary).

For further info about recursive add in WinCvs look here: http://cvsgui.sourceforge.net/newfaq.htm#cvs-add_recursive


Apart from that cvs import is well suited for mass-additions. However, the way cvs import is implemented in vanilla CVS has two drawbacks (because it was originally written for third-party code):

  • it creates a mandatory branch with special semantics.
  • it does not create the repository meta-data (i.e. the hidden CVS directories) needed to establish the imported code as a checked out working copy, which means that in order to actually work with the imported files you first have to check them out of the repository

If you are using CVSNT you can avoid both drawbacks by specifying the -nC option on import. -n is for avoiding the "vendor" branch and -C is for creating the CVS directories.

Prostatitis answered 6/11, 2008 at 10:38 Comment(0)
M
2

This answer from Mark was usefull (find . -type f -print0| xargs -0 cvs add) but I solved some problem that occured when the cvs add try to add his own files like Tag, Entries, ect..

  1. Add your most high level folder called NEW_FOLDER
cvs add NEW_FOLDER
  1. Use the previous command with some exclusion to add all sub-folders tree

find NEW_FOLDER/ -type d ! -name "CVS" -and ! -name "Tag" -and ! -name "Entries.Log" -and ! -name "Entries" -and ! -name "Repository" -and ! -name "Root" -print0 | xargs -0 cvs add

  1. Use the previous command with some exclusion to add all files

find NEW_FOLDER/ -type f ! -name "CVS" -and ! -name "Tag" -and ! -name "Entries.Log" -and ! -name "Entries" -and ! -name "Repository" -and ! -name "Root" -print0 | xargs -0 cvs add

Myron answered 7/6, 2016 at 9:29 Comment(0)
E
1

I think this is what I did back in my CVS days:

find . -type f | xargs cvs add
Entomophagous answered 7/8, 2008 at 18:25 Comment(0)
D
1

First add all directories to CVS

find . -type d -print0| xargs -0 cvs add

Then add all the files in the directories to CVS

find . -type f -print0| xargs -0 cvs add
Diffract answered 29/8, 2008 at 18:6 Comment(0)
S
1

I'm using this simple shell script, which should be started from an already checked-out CVS directory. It will stupidly try to add/commit any files and directories it finds upon its recursive search, so in the end you should end up with a fully commit tree.

Simply save this as something like /usr/bin/cvsadd and don't forget to chmod +x /usr/bin/cvsadd.

#!/bin/sh
# @(#) add files and directories recursively to the current CVS directory
# (c) 2009 by Dirk Jagdmann 

if [ -z "$1" ] ; then
    echo "usage: cvsadd 'import message'"
    exit 1
fi

if [ -d "$2" ] ; then
    cvs add "$2"
    cd "$2" || exit 1
fi

if [ ! -d CVS ] ; then
    echo "current directory needs to contain a CVS/ directory"
    exit 1
fi

XARGS="xargs -0 -r -t -L 1"

# first add all files in current directory
find . -maxdepth 1 -type f -print0 | $XARGS cvs add
find . -maxdepth 1 -type f -print0 | $XARGS cvs ci -m "$1"

# then add all directories
find . -maxdepth 1 -type d -not -name CVS -a -not -name . -print0 | $XARGS "$0" "$1"
Saffian answered 30/12, 2009 at 11:39 Comment(0)
T
1

Already discussed methods will do recursive lookup, but it will fail if you perform same action again (if you want to add subtree to existed tree) For that reason you need to check that your directories was not added yet and then add only files which not added yet. To do that we use output of cvs up to see which elements was not added yet - its will have question mark at start of line.

We use options -0, -print0 and -zZ to be sure that we correctly process spaces in filenames. We also using --no-run-if-empty to avoid run if nothing need to be added.

CVS_PATTERN=/tmp/cvs_pattern
cvs -z3 -q up | egrep '^\?.*' | sed -e 's/^? //' > $CVS_PATTERN
find . -type d \! -name CVS -print0 | grep -zZf $CVS_PATTERN | xargs -0 --no-run-if-empty cvs add
find . \( -type d  -name CVS -prune \) -o \( -type f  -print0 \) | grep -zZf $CVS_PATTERN | xargs -0 --no-run-if-empty cvs add
cvs commit -m 'commiting tree recursively'

With this approach we will avoid such errors:

cvs add: cannot add special file `.'; skipping
cvs [add aborted]: there is a version in ./dirname1 already

and

cvs add: `./dirname2/filename' already exists, with version number 1.1.1.1
Tabethatabib answered 3/7, 2014 at 7:58 Comment(0)
I
0

Mark's solution resolves the spaces issue, but produces this issue:

cvs add: cannot open CVS/Entries for reading: No such file or directory
cvs [add aborted]: no repository

To fix it, the actual command to use is:

find . -type f -exec cvs add {} \;
Inhospitality answered 7/8, 2008 at 21:18 Comment(0)
V
0

i like to do (as directory's need an add to)

cvs status 2>/dev/null | awk '{if ($1=="?")system("cvs add "$2)}'

you might need to run this multiple times(first for directory's then for its children) until there is no output

Venenose answered 18/7, 2013 at 10:20 Comment(0)
F
-2

SVN definitely makes this trivial task, using a GUI like Tortoise is even easier, however.

This might be a good place to start: http://www-mrsrl.stanford.edu/~brian/cvstutorial/

Fuji answered 7/8, 2008 at 18:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.