我正在尝试理解如何使用JGit中的.gitattributes。但我找不到任何能最好地演示它的教程。
是不是JGit还不支持它。但是git客户端有这个支持。为什么不是JGit呢?
发布于 2016-06-23 20:04:00
JGit具有对.gitattributes的基本支持。有关当前的开发状态,请参阅bug 342372和相关错误。
JGit测试套件可以帮助您理解.gitattributes是如何在JGit中实现的。有关如何使用JGit源代码的信息,请参阅this article。
发布于 2020-09-15 13:12:35
如果您想尝试使用libgi2,可以使用a jni bindings访问最新的libgit2 attributes apis
下面是一些示例:
Repository testRepo = Repository.open("path-to-your-repo");
// load macros from .gitattributes file
Attr.addMacro(testRepo, "binary", "-diff -crlf");
// Loop through all attributes
Map<String, String> attributes = new HashMap<>();
Attr.foreach(
testRepo,
EnumSet.of(CHECK_INDEX_THEN_FILE),
".",
new Attr.ForeachCb() {
@Override
public int accept(String name, String value) {
attributes.put(name, value);
return 0;
}
});您可以找到关于这些apis的测试用例here
https://stackoverflow.com/questions/37990581
复制相似问题