I want to check status of files in my SVN working copy and then remove them by svn if they were manually deleted (so they can be committed). i found out that
svn status "C:\\Tools\\Jenkins\\" | grep "^\!" | sed "s/^\! *//g"
correctly finds files i manually deleted, i my case it is jobs\\run_tests_on_master. But when i try to remove the directory using:
svn status "C:\\Tools\\Jenkins\\" | grep "^\!" | sed "s/^\! *//g" | xargs svn rm
I get error:
svn: E155007: 'C:\ToolsJenkinsjobsrun_tests_on_master' is not a working copy
It looks like the directory lacks backslashes. Is there a way to work around it?
The following awk
will test every line of svn
output to see if it can remove an exclamation mark followed by any spaces from the beginning of that line. If it does so, it will perform svn rm
on the resulting string.
svn status 'C:\Tools\Jenkins' |awk 'sub(/^! */, ""){system("svn rm " $0)}'
You can do two things to improve your command: replace the grep
+ sed
combination with a single call to sed
(thanks to -n
and p
flags), and use single quotes in sed
. Using echo
in place of svn
, that would be something like this:
>>> echo '!C C:\\Tools\\Jenkins\\' | sed -nr 's/!C *//gp'
C:\\Tools\\Jenkins\\
I realised that the problem is with the xargs
part of the command. You need to use the -0
option:
>>> echo '!C C:\\Tools\\Jenkins\\' | sed -nr 's/!C *//gp' | xargs -0 echo
C:\\Tools\\Jenkins\\
This was discussed in Escaping backslash in windows paths passed to unix programs
I did a workaround of the issue, based on the suggested solutions:
svn status "C:\\Tools\\Jenkins\\" | grep "^\!" | sed "s/^\! *//g" >>file.txt
for /F "usebackq tokens=*" %%A in (file.txt) do (svn remove "%%A")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.