Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将SVN与PHP一起使用-Add命令在现有目录上失败_Php_Svn - Fatal编程技术网

将SVN与PHP一起使用-Add命令在现有目录上失败

将SVN与PHP一起使用-Add命令在现有目录上失败,php,svn,Php,Svn,所以基本上我希望能够做到这一点: /* Runs command and checks return code of last command run. Throws SVN exception if non-zero status code is returned. The output of the command otherwise. */ public static function runCommand($cmd)

所以基本上我希望能够做到这一点:

        /*
            Runs command and checks return code of last command run. Throws SVN exception if non-zero status code is returned. The output of the command otherwise.
        */
        public static function runCommand($cmd)
        {
            //Redirect error to stdout
            $cmd .= " 2>&1";

            $output = array();
            exec($cmd, $output, $status);
            $output = implode("\n", $output);

            if($status != 0)
            {
                            //custom exception class - nonimportant
                throw new SvnException($output);
            }

            return $output;
        }
问题在于,当您尝试添加已受版本控制的目录时,
svn add
会将其视为错误,因此它会返回错误状态代码。如果“目录已经存在”的话,有没有办法解决这个问题,而不进行黑客攻击来查找
svn add
命令并忽略错误


具体来说,是否有一些SVN命令可以用来判断文件夹是否在版本控制下,或者我可以使用的参数,以便
SVN add
在目录已在版本控制下时不会返回错误。

您可以询问SVN目录是否存在。如果希望
add
函数模拟
svn
函数,只需抛出异常并让调用方处理即可。如果您希望在目录已经存在时保持静默,请在此处添加检查。

您可以为该特定错误分析SVN输出,并为该情况添加If(){}


我还强烈建议您不要使用exec()解析。安装、使用和工作都很容易(根据我自己的经验)…

该项目看起来已经有一年多没有进行过了。你确定它是完全稳定的吗?此外,我只进行简单的添加/提交,因此在本例中,整个库的配置可能比我自己进行配置所需的时间更长。我们正在使用此扩展的所有只读存储库方面(日志、ls、diff等),它已经完美地工作了3年。我没有尝试过add和类似的非只读方法,但我完全相信它们是有效的。此外,如果您依赖解析输出,则可以使用新的SVN客户端版本更改输出。这是更快,更安全,更好,。。。一句话-正确的方式(好的三个字):)是的,对于一个单独的用例来说,创建一个异常似乎很困难,但我认为没有选择,因为我不认为它是一个错误,但是VSN确实是这样。我最终检查了一个错误,使用了<代码> SvnField。如果命令出错,只添加目录。awk'{print$2;}'@Wrikken不幸的是,如果可能的话,我需要一个跨平台的解决方案。不过,我肯定会在Linux上试用。啊,是的,那一行绝对不是可移植的。