如何检查存储库是否存在?

时间:2010-06-29 00:19:34

标签: mercurial firefox-addon

我想在执行以下流程之前检查存储库是否存在于给定路径上。任何想法?

var exe = Components.classes['@mozilla.org/filelocal;1'].
                     createInstance(Components.interfaces.nsILocalFile);

exe.initWithPath("HG.EXE");

var process = Components.classes["@mozilla.org/process/util;1"].
              createInstance(Components.interfaces.nsIProcess);

Process.init(exe);

args = ["init", "D:\\testRepo\\"];
process.run(blocking, args, args.length);

2 个答案:

答案 0 :(得分:5)

好吧,你可以用

hg --cwd the/path/you/want/to/test root

该命令会告诉您the/path/you/want/to/test或更高版本是否有存储库。查看命令的退出代码以查看它是否成功。

您还需要将命令打印的根与您的实际目录进行比较 - 可能是某个更高级别的存储库,然后hg root会报告该。

答案 1 :(得分:1)

您可以简单地检查.hg子目录是否存在(这只有在您检查存储库的根目录时才有效,而不是在存储库的一个文件夹中)。

相关问题