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