bash 抑制 svn remove 的“文件不存在”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10667973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Suppress "file does not exist" error of svn remove
提问by DrummerB
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 stateand calls svn addfor files marked with a ?and svn removefor files with a !. I added this bash script to my build script. The problem is, svn removereturns 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.
我写了一个简单的bash脚本,检查svn state并呼吁svn add对标有文件?,并svn remove用一个文件!。我将此 bash 脚本添加到我的构建脚本中。问题是,svn remove当使用本地不再存在的文件调用时返回错误。这会导致我的构建脚本中止并返回错误。
Is there a way to suppress these errors? I tried --forceand --quiet. Didn't help.
有没有办法抑制这些错误?我试过--force和--quiet。没有帮助。
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
回答by nosid
There are (at least) two different cases in which svn statprints a line with an exclamation point:
有(至少)两种不同的情况,其中svn stat打印带有感叹号的行:
- The file exists in the repository, does not exist in the working directory, and
svn rmwas not used. - The file does not exist in the repository,
svn addwas used on the file, and the file does no longer exist in the working directory.
- 该文件存在于存储库中,不存在于工作目录中,并且
svn rm未被使用。 - 该文件不存在于存储库中,
svn add已用于该文件,并且该文件不再存在于工作目录中。
svn rmworks 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:
svn rm在第一种情况下工作,但在第二种情况下退出并出现错误。有多种方法可以解决此问题 - 取决于您要实现的目标:
- 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".
- 如果你想删除这两种情况下的文件,这样做:
touch "$filename" ; svn rm --force "$filename"。 - 如果您只想在第二种情况下删除文件,并在第一种情况下恢复,请执行:
svn revert "$filename"。
回答by DrummerB
So, to answer my question, using --keep-localfixed the problem.
所以,为了回答我的问题,使用--keep-local修复了问题。
Here is the script I ended up using. This will check for files marked as not versioned (?) and call svn addfor them. Then it checks for files marked as missing (!) and call svn rmfor them.
这是我最终使用的脚本。这将检查标记为未版本化 ( ?) 的文件并调用svn add它们。然后它检查标记为丢失 ( !) 的文件并调用svn rm它们。
svn st "$Resources" | grep '^?' | sed 's_^? \(.*\)$_svn add ""_g' | sh
svn st "$Resources" | grep '^!' | sed 's_^! \(.*\)$_svn rm --keep-local ""_g' | sh

