I have a script in which I add all new files before to commit my working copy to my repository with this line:
svn status | grep ^\? | awk '{print $2}' | xargs svn add
I now want to add a line that delete from repository all deleted files in my working copy. In other terms, I cannot specify them one by one, and I need to detect them with svn status and then automatically remove them. However the line doesn't work.
svn status | grep ^\! | awk '{print $2}' | xargs svn --force delete
As you can see I've replaced
"?
" with "!
" and
"add
" with "--force delete
"
Could you tell me why it doesn't work ?
ps. I know it is a risky procedure. I've already discussed all about it.
thanks
thanks
I just tried this and it works perfectly.
$ svn st | grep '^!' | awk '{print $2}' | xargs svn delete --force
D groups.pl
D textblock.pl
Do your files have spaces in their names?
WAIT A SECOND!! I see the problem. You have:
svn --force delete
and not:
svn delete --force
The --force
is a parameter of the delete
command and not the svn
command.
I have found another solution, too.
svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %
I have seen it on http://donunix.blogspot.de/2009/02/svn-remove-all-deleted-files.html
svn status | grep '^!' | sed 's/! *//' | xargs -d '\n' svn delete --force
The solution works for filenames with spaces and special characters.
svn status
- lists all changes, deleted files are marked as !
grep '^!'
- extracts lines that begins with !
(i.e. deleted files)
sed 's/! *//'
- removes !
-char at the beginning and spaces after it
xargs -d '\n'
- treats every input line (including spaces and special characters) as separate argument and passes them to svn delete --force
what about adding you could simply use
svn add --force .
or
svn --force add .
it would do the same: add all unversioned files except ones matching svn:ignore patterns
an approach using a perl oneliner would be:
svn st | perl -ne 'print "$1\n" if /^\!\s+(.*)/' | xargs svn rm
this should also work with space characters in file names.
edit: improved regexp