我正在使用 SCM Manager 进行 HG 版本控制。我正在尝试使用 maven-scm-provider-hg 依赖项提供的 Java API 将现有的 sc.txt 文件添加到 HG 存储库。
将文件添加到 HG repo 的方法:
public void add(ScmRepository scmRepository, ScmFileSet fileSet, String message,
boolean binary) {
try {
AddScmResult rs = scmManager.add(scmRepository, fileSet, message);
System.out.println("Result : " + rs.getAddedFiles());
} catch (Exception e) {
System.out.println("Execption occured while adding new file " + e);
}
}
获取 ScmRepository 的方法:
public ScmRepository getScmRepository(String scmUrl) throws Exception {
ScmRepository repository;
try {
repository = getScmManager().makeScmRepository(scmUrl);
System.out.println("Repo " + repository.getProviderRepository().getUser() + " Path : "
+ repository.getProvider());
return repository;
} catch (NoSuchScmProviderException ex) {
throw new Exception("Could not find a provider.", ex);
} catch (ScmRepositoryException ex) {
throw new Exception("Error while connecting to the repository", ex);
}
}
主应用程序.java
ScmRepository repo = scmClient.getScmRepository("scm:hg:/Users/john/work/hgtest/v1");
ScmFileSet fileSet = new ScmFileSet(new File("/Users/john/work/hgtest/v1"),
new File("sc.txt"));
scmClient.add(repo, fileSet, "This is first file checking", false);
这是我执行代码时遇到的错误:
将新文件添加到 hg..... 执行:/bin/sh -c cd /Users/diwakar/work/hgtest/v2 && hg add --verbose sc.txt [ERROR] EXECUTION FAILED 执行 cmd : add failed with退出代码:127。工作目录为:/Users/diwakar/work/hgtest/v2 您的 Hg 安装似乎有效且完整。汞版:NA(OK)
结果:[] 完成.....
POM.xml:
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-hg</artifactId>
<version>1.8</version>
</dependency>