在现有分支中从 java 运行 hg log 命令



我正在尝试使用JavaHg从Java运行一些hg命令。

我已经有一个现有的 hg 工作目录。

:pwd
/Users/theodore/Work/proj1
:hg identify -b
PROJ1_FEATUREX_BRANCH

我想使用 JavaHg 连接到这个工作目录并运行 hg log 命令。

这就是我走多远:

public static void main(String[] args) {
RepositoryConfiguration conf = new RepositoryConfiguration();
conf.setHgBin("/usr/local/bin/hg"); //Path to HG executable
Repository repo = Repository.create(conf, new File("/Users/theodore/Work/proj1"));

LogCommand log = LogCommand.on(repo);
List<Changeset> changesets = log.execute();
System.out.println(changesets);
for(int i=0;i<changesets.size();i++) {
Changeset cs = changesets.get(i);
System.out.println( cs.getUser());
System.out.println( cs.getMessage());
System.out.println( cs.getAddedFiles() );
System.out.println( cs.getModifiedFiles() );
}
repo.close();
}

但是,上面的代码每次都尝试在该文件夹中创建一个新的存储库。

因此,它失败并显示此错误:

Exception in thread "main" java.lang.RuntimeException: abort: repository /Users/theodore-3428/eclipse-workspace/hgviewer/~/DISKS/Work/CODE/HG/sdplive already exists!

检查存储库类的源代码。你需要使用Repository.open(RepositoryConfiguration, File)Repository.create(RepositoryConfiguration, File)的 isntead ,所以创建这样的 repo 对象:

Repository repo = Repository.open(conf, new File("/Users/theodore/Work/proj1"));

最新更新