header

Torsten Curdt’s weblog

Recursively adding files to CVS

The following commands can become handy if you are still stuck with cvs and cannot use the excellent eclipse cvs client.


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

  • weblogger
    This is awesome! I created a perl script to automate this process. hope it helps:

    use Expect;
    sub addFiles {

    my ($ip, $user, $pass, $dir, $cvsPass ) = @_;
    my $exp = new Expect;
    $self->{_ExpHnd} = $exp;

    $exp->raw_pty(1);
    $exp->spawn("ssh $ip\r");
    $exp->expect(15,"password: ");
    $exp->send("$pass\r");
    $exp->expect(15,"# ");
    $exp->send("cd $dir\r");
    $exp->expect(15,"# ");
    #add Directory
    $exp->send("find . -type d -print | grep -v CVS | xargs -n1 cvs add\r");
    $exp->expect(10,
    [ qr/password: /, sub { my $self = shift;
    $exp->send("$cvsPass\r");
    exp_continue; }],
    "# ");
    #add Files
    $exp->send("find . -type f -print | grep -v CVS | xargs -n1 cvs add\r");
    $exp->expect(10,
    [ qr/password: /, sub { my $self = shift;
    $exp->send("$cvsPass\r");
    exp_continue; }],
    "# ");
    #Commit should be done manually to ensure that user will add logs.
    print "All files in $dir has been added to module. Please commit Files.";
    return $exp;

    }

    addFiles('192.168.1.1','username','password','/home/user/FOLDER','cvspassword');
  • Dagguh
    THANKS :*
  • swarup
    slight modification for non-unix type file/dir names (aka with spaces)

    find . -type d -print | grep -v CVS | xargs -ifoo cvs add "foo"
    find . -type f -print | grep -v CVS | xargs -ifoo cvs add "foo"
  • dudoanbongda
    I think so ....
  • testo
    Happy, not being the only one still using cvs.
    Great hint!
  • Max
    Sweet, I use this all the time.
  • James
    -iregex is a gnu find only extension (as is -!, use \! instead), and really unnecessary since -iname \*CVS\* is the same as the .*CVS.* regex
  • fooball
    sorry copy the wrong line :)

    find . -type f -! -iregex ".*CVS.*" -exec cvs add {} \;
  • fooball
    kinda the same solutions but w/o so much wasted pipes ;-)

    find . -type d -! -name CVS -! -name '.' -exec cvs add {} \;
    find . -type f -! -name CVS -! -name '.' -exec cvs add {} \;
  • Be aware that the command uses "grep" and you might have grep aliased to some command lines. For example, as a programmer, I find this useful:

    alias grep='grep -n -i --color=auto'

    However, it fails the above commands. So you have to type "unalias grep" first.
  • Todd
    I love it.

    Thanks!
  • cowgod
    thank you, thank you, thank you. awesome.
  • Thanks guys this is just what I needed. Don't have eclipse setup on my mac. :(
  • Nikolaus
    Thanks, this is fantastic

    It did not work for me as specified under bash on OS X, I had to use the following, and note the -n1 parameter for xargs:

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

    the -n1 ensures that cvs add is called only for a single file each time. That's required because while cvs add can be called with a number of files as argument, if one of the arguments "aborts" the add, the others won't be added. I found that to happen with the first line which adds the directories. If a directory is already there, cvs add aborts instead of just skipping it like it does with files.

    So it would do a cvs add dir1 dir2 dir3, but because dir1 was already in the repository, it would not add dir 2 and 3. I am not sure it's required for files, but it can't hurt.
  • Amit
    It is really a great solution. Thanks a lot for reducing my work.
blog comments powered by Disqus