检查文件是否已提交至 svn

检查文件是否已提交至 svn

如何检查文件/文件夹是否已提交到 svn?我有一个 shell 脚本,我想确保用户选择签入的文件/文件夹尚未提交。例如,如果我尝试使用以下方法签入已提交的文件夹

svn 添加我的文件夹

我收到以下警告:

svn:警告:‘myfolder’已处于版本控制之下

答案1

使用返回码svn info。如果在版本控制下则为0,否则为非零。

我的 shell 在命令后显示非零返回代码,因此它看起来像这样:

$ svn info trunk
Path: trunk
URL: https://(...)/trunk
Repository Root: https://(...)
Repository UUID: 651713a4-5a46-7e42-a99e-f31e79777eab
Revision: 213
Node Kind: directory
(...)

$ touch foo
$ svn info foo 
foo:  (Not a versioned resource)

svn: A problem occurred; see other errors for details

rc: 1

如何在脚本中执行此操作 bash(与其他 shell 类似),并抑制info输出:

svn info <filename> 1>/dev/null 2>&1
echo $?

答案2

我正在使用这个:

if [ $(svn status $file | awk '{ print $1 }') == "?" ]; then
    echo "File is not under version control"
fi

这样您还可以查询不同的 svn 状态代码,如下所示:http://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.status.html

答案3

我想解决一个类似的问题:作为生成文件脚本的一部分,如果之前没有这样做,则自动将其添加到 subversion。

我发现以下方法有效:

if ! svn info ${file} 1>/dev/null 2>&1 ; then
  svn add ${file}
fi

在 Bash 中测试退出值让我找到了这个答案。

相关内容