尝试使用SVN命令

时间:2017-01-19 07:22:02

标签: svn scripting tcl

我正在尝试通过tcl脚本在svn中提交文件。我在tcl脚本中运行以下命令

catch {exec svn commit -m'SDR' 'C:\abc\def\a.txt'} results

返回以下错误

svn: E020024: Error resolving case of 'C:\abc\def\a.txt'

我尽我所能。在这里张贴,希望得到解决。提前谢谢。

2 个答案:

答案 0 :(得分:2)

问题是'个字符对Tcl没有任何意义,与你习惯使用的shell不同。幸运的是,通常只需将这些值 - 没有'字符 - 放在Tcl变量中并仅使用它们来解决这个问题。在形式上,Tcl使用{ ... },其中shell使用' ... ',但是任何使用正确字符串的内容都会在实践中使用。

此外,Tcl非常希望在文件名中将\转换为/;我们需要在那里稍微小心一点,因为我们将文件名交给子进程(而file nativename 正好我们需要的护理)。

# I'm going to factor these two out into variables; that sort of thing that makes sense
set message "SDR"
set file [file join C:/ abc def a.txt]

catch {exec svn commit -m $message [file nativename $file]} results

当然,在实践中,许多应用程序都有一个工作区域的概念,他们在其中进行文件操作。它可能是当前的工作目录,它可能在其他地方(真的取决于应用程序),但通常最好将它的名称放在它自己的变量中。然后,您可以更轻松地使用该范围内的名称:

set workingArea [file join C:/ abc]

set message "SDR"
set file [file join $workingArea def/a.txt]

catch {exec svn commit -m $message [file nativename $file]} results

如果它是我自己的代码,那么实际上实际将一些内容包装在一个过程中(这使用了lmap,这是在Tcl 8.6中引入的):

proc svnCommit {message args} {
    global workingArea
    set code [catch {
        exec svn commit -m $message {*}[lmap f $args {
            file nativename [file join $workingArea $f]
        }]
    } results]
    return [list $code $results]
}

lassign [svnCommit "SDR" def/a.txt] code results

答案 1 :(得分:0)

使用file join命令解决了我的机器上的问题:

catch {exec svn commit -m'SDR' [file join C:\\ abc def a.txt]} results