CVS add

Just learning my way around CVS - is this missing anything? It seems to
work, but that’s just programming by coincidence :slight_smile:

recursive cvs add

require ‘find’

def cvs_addable?(file)
!([’.’,’…’,‘CVS’].include?(File.basename(file)))
end

dirs = []
Find.find (ARGV[0]) {|file|
if FileTest.directory?(file)
a << file if cvs_addable?(file)
end
}

dirs.each {|dir|
Dir.chdir(dir)
puts "cd #{dir}"
Dir.foreach(’.’) {|file|
system(“cvs add #{file}”) if cvs_addable?(file)
}
}

Just learning my way around CVS - is this missing anything? It seems to
work, but that’s just programming by coincidence :slight_smile:

Normally when adding a whole existing project to CVS you’d use ‘cvs import’.
I do that so rarely that I can’t remember the exact details, but after doing
it I think you just checkout the entire project again so that you have all
the ‘CVS’ subdirectories.

Then, when at a later time you want to make sure the repository is in sync
with the files in your working directory, you run ‘cvs update’. It shows
recursively for each file a status flag:

? – file is in working directory but not in respository; a possible
candidate for ‘cvs add’
A – file was added with ‘cvs add’ but not committed yet
M – file has been modified, commit will write it to repository
U – file had changed in repository, your local copy has been brought
into sync (updated)

So in practice I’ve not found a need to run a script which does ‘cvs add’
recursively across all directories. On the odd occasion when I want to add a
new subdirectory of files, I do
cvs add subdir
cvs add subdir/*

Regards,

Brian.

···

On Sun, Aug 10, 2003 at 04:13:51PM +0900, Martin DeMello wrote:

recursive cvs add

require ‘find’

def cvs_addable?(file)
!([‘.’,‘…’,‘CVS’].include?(File.basename(file)))
end

dirs =
Find.find (ARGV[0]) {|file|
if FileTest.directory?(file)
a << file if cvs_addable?(file)
end
}

dirs.each {|dir|
Dir.chdir(dir)
puts “cd #{dir}”
Dir.foreach(‘.’) {|file|
system(“cvs add #{file}”) if cvs_addable?(file)
}
}

Just learning my way around CVS - is this missing anything? It seems to
work, but that’s just programming by coincidence :slight_smile:

Normally when adding a whole existing project to CVS you’d use ‘cvs import’.

I thought of that, but a friend advised against it. Quoting him:

Never use cvs import on existing files. you’ll get lost in a maze
of vendor ids and repository ids all alike.

do the following: suppose your project name is foo.

mkdir tmp; cd tmp # any empty directory
cvs import foo foo start # will prompt for message, can leave blank
cd …; rmdir tmp
cvs co foo # creates foo and foo/CVS and stuff inside it
cd foo
cp whatever_existing_project_files_and_dirs .
cvs add *
cvs commit # this is your real importing

And when I went to do that, I found out that CVS had no recursive add.

martin

···

Brian Candler B.Candler@pobox.com wrote:

On Sun, Aug 10, 2003 at 04:13:51PM +0900, Martin DeMello wrote:

I thought of that, but a friend advised against it. Quoting him:

Never use cvs import on existing files. you’ll get lost in a maze
of vendor ids and repository ids all alike.

That’s a new one on me. I’ve done many, many cvs imports without
experiencing problems… although I would agree that the documentation
for the cvs import command can be a bit confusing. The really odd thing
about “cvs import” is that you have to be in the directory that you’re
importing. So if you’ve got a project foo:

foo/
src/
lib/
doc/
tests/

and you want to import it, you have to cd to inside the foo directory
and then run a:

cvs import -m “Importing the code” foo tom start

It’s pretty counter-intuitive… but once you memorize it it’s OK :slight_smile:

Yours,

Tom