Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-Add SVN command line with whitespace

I have an SVN repository. I have a shell/bash script that's designed to automatically add all unversioned files to the repository. It looks like this:

 svn status | grep '^?' | sed 's/^.* /svn add /' | bash;

Which works perfectly, except for when one of my new files has whitespace in the filename. How can I modify this command to deal with that?

like image 858
Jordan Avatar asked Jul 07 '26 01:07

Jordan


2 Answers

To avoid quoting issues here, you should avoid the shell call altogether and use xargs instead, which will also speed up the process:

svn status | grep '^?' | sed -e 's/^? *//' | xargs --no-run-if-empty -d '\n' svn add

This will handle most special characters, but not work to escape newlines, but since these are the record separator for svn status and grep, you won't get much better than that anyway.

like image 161
thiton Avatar answered Jul 08 '26 15:07

thiton


Strange that you use a script because svn add --force . can do this alone:

> svn status
?       INSTALL
?       trunk/INSTALL
?         trunk/INSTALL WITH SPACE
> svn add --force .
A         trunk/INSTALL
A         INSTALL
A         trunk/INSTALL WITH SPACE

No more fuss with whitespace :-)

like image 37
A.H. Avatar answered Jul 08 '26 15:07

A.H.