Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress "file does not exist" error of svn remove

Tags:

bash

shell

svn

In my project I have a folder with resources which I don't want to manually add or remove to the repository as I add or remove them to my working copy.

I wrote a simple bash script that checks svn state and calls svn add for files marked with a ? and svn remove for files with a !. I added this bash script to my build script. The problem is, svn remove returns an error when called with a file that doesn't exist locally anymore. This results in my build script being aborted and returning an error too.

Is there a way to suppress these errors? I tried --force and --quiet. Didn't help.

Example:

MacBook-Pro:proj Bill$ echo "test" > foo.bar
MacBook-Pro:proj Bill$ svn st
?       foo.bar
MacBook-Pro:proj Bill$ svn add foo.bar 
A         foo.bar
MacBook-Pro:proj Bill$ rm foo.bar 
MacBook-Pro:proj Bill$ svn st
!       foo.bar
MacBook-Pro:proj Bill$ svn rm foo.bar
D         foo.bar
svn: 'foo.bar' does not exist
like image 675
DrummerB Avatar asked Nov 30 '25 16:11

DrummerB


2 Answers

There are (at least) two different cases in which svn stat prints a line with an exclamation point:

  1. The file exists in the repository, does not exist in the working directory, and svn rm was not used.
  2. The file does not exist in the repository, svn add was used on the file, and the file does no longer exist in the working directory.

svn rm works in the first case, but exits with an error in the second case. There are several ways to solve this issue - depending on what you want to achieve:

  • If you want to remove the file in both cases, do:
    touch "$filename" ; svn rm --force "$filename".
  • If you want to remove the file only in the second case, and revert in the first case, do:
    svn revert "$filename".
like image 145
nosid Avatar answered Dec 02 '25 07:12

nosid


So, to answer my question, using --keep-local fixed the problem.

Here is the script I ended up using. This will check for files marked as not versioned (?) and call svn add for them. Then it checks for files marked as missing (!) and call svn rm for them.

svn st "$Resources" | grep '^?' | sed 's_^?       \(.*\)$_svn add "\1"_g' | sh
svn st "$Resources" | grep '^!' | sed 's_^!       \(.*\)$_svn rm --keep-local  "\1"_g' | sh
like image 31
DrummerB Avatar answered Dec 02 '25 07:12

DrummerB