Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe shell output to svn del command?

Tags:

shell

svn

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
etc. . .

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
like image 601
jergason Avatar asked Sep 10 '09 20:09

jergason


2 Answers

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.

like image 175
Greg Hewgill Avatar answered Nov 11 '22 01:11

Greg Hewgill


svn st | egrep ^! | cut -b 9- | xargs svn del
like image 21
Adam Batkin Avatar answered Nov 11 '22 03:11

Adam Batkin