How to check whether a repository exist or not?
I want to check whether repository exist on the given path or not before executing the process below..any ideas ?
var exe = Components.classes['@mozilla.org/filelocal;1'].
createInstance(C开发者_运维知识库omponents.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);
Well, you could use
hg --cwd the/path/you/want/to/test root
That command tells you if there is a repository at the/path/you/want/to/test
or above. Look at the exit code of the command to see if it succeeded.
You will also need to compare the root printed by the command with your actual directory -- it could be that there is a repository at some higher level and then hg root
will report that.
You could simply check if the .hg
subdirectory exists (this only works if you are checking the root of the repository, not from within a folder that would be part of your repository).
精彩评论