[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: Why do commands fail when a file is unknown to svn?

From: <terry_at_eatoni.com>
Date: 2004-03-05 00:49:51 CET

>>>>> "James" == James Goodall <jgoodall@dmetrix.com> writes:

James> You could do this:
James> --- Begin file isversioncontrolled ---
James> #/bin/bash
James> svn info $1 &>/dev/null
James> --- End of file

James> svn ci $( find . -name Makefile -exec isversioncontrolled {} \; -print )

I'm not sure how/why this works, because, unfortunately, svn info
exits with status 0 even when the file is not under version control.
This should probably be changed.

Meanwhile, you can get around it with grep -q as below.

  $ find . -name Makefile | xargs check-in-if-under-svn

With a check-in-if-under-svn script looking like this

  --- Begin file check-in-if-under-svn ---
  #!/bin/bash
  for i in "$@"
  do
      svn info "$i" 2>&1 | grep -q -i 'Not a versioned resource' || svn ci "$i"
  done
  --- End of file ---

I still wouldn't recommend this (it's slow because it fires up
potentially many svn processes). Also, I have a feeling (and people
who've actually used svn for more than a week, unlike me, will have to
confirm) that it's somehow nicer if you do all the checkins at once,
creating one new change set in svn.

So better (but more involved):

  $ find . -name Makefile | xargs check-in-if-under-svn.pl

Where check-in-if-under-svn.pl looks like this:

----------------------------------------------
#!/usr/bin/perl -w

use strict;

my $svn = '/usr/local/bin/svn';
my $echo = '';
my %invalid;

if ($ARGV[0] eq '-n'){
    $echo = 'echo ';
    shift;
}

exit(0) unless @ARGV;

open(INFO, sprintf("$svn info %s |", join(' ', map { "'$_'" } @ARGV))) or die;

map { $invalid{$1} = undef if /^([^:]+):\s*\(Not a versioned resource\)$/ } <INFO>;

my @ci = grep { ! exists $invalid{$_} } @ARGV;

exit(0) unless @ci;

system("$echo$svn ci " . join(' ', map { "'$_'" } @ci));

exit $? >> 8;
----------------------------------------------

BTW, you can give this script an initial -n argument if you just want
it to echo what it would check in.

Note also that the above assumes you don't have files with a single
quote in their name.

Finally, make sure you prune your find command if it encounters any
.svn directories.

Terry

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Mar 5 00:48:38 2004

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.