tags:

views:

295

answers:

3

I have a rather complicated deploy setup for our Drupal site that is a combination of CVS and SVN. We use CVS to get the newest versions of modules, and we deploy with SVN. Unfortunately, when CVS updates remove files, Subversions complains because they weren't removed in SVN. I am trying to do some shell scripting and Perl to run an svn rm command on all these files that have already been deleted from the filesystem, but I have not gotten far. What I have so far is this:

svn st | grep !

This outputs a list of all the files deleted from the filesystem like so:

!       panels_views/panels_views.info
!       panels_views/panels_views.admin.inc
!       contexts/term.inc
!       contexts/vocabulary.inc
!       contexts/terms.inc
!       contexts/node_edit_form.inc
!       contexts/user.inc
!       contexts/node_add_form.inc
!       contexts/node.inc
ect. . .

However, I want to somehow run an svn del on each of these lines. How can I get this output into my Perl script, or alternatively, how can I run svn del on each of these lines?

Edit: The exact command I used, with some help from all, was

svn st | grep ^! | cut -c 9- | xargs svn del
+6  A: 

Try using xargs, like this:

svn st | grep ^! | cut -f2 | xargs svn rm

The xargs command takes lines on its standard input, and turns them around and uses those lines as command line parameters on the svn rm. By default, xargs uses multiple lines with each invocation of its command, which in the case of svm rm is fine.

You may also have to experiment with the cut command to get it just right. By default, cut uses a tab as a delimiter and Subversion may output spaces there. In that case, you may have to use cut -d' ' -f6 or something.

As always when building such a command pipeline, run portions at a time to make sure things look right. So run everything up to the cut command to ensure that you have the list of file names you expect, before running it again with "| xargs svn rm" on the end.

Greg Hewgill
I would change `grep !` to `grep ^!` to ensure that we don't accidentally kill files that happen to have exclamation points in their path.
Adam Bellaire
That's a wise idea.
Greg Hewgill
Wonderful, I had no idea about cut or xargs. I knew Perl was not the simplest way, but I have a bit of familiarity with.
Jergason
A: 
svn st | egrep ^! | cut -b 9- | xargs svn del
Adam Batkin
A: 

Just as an alternative to the ones above, I'd use something like:

svn st | awk '$1=="!"{print $2}' | xargs svn del

I find awk's pattern-matching language very handy for tasks like this.

Dominic Mitchell