JGit是否支持.gitattributes?

时间:2016-06-23 11:39:50

标签: eclipse git jgit

我正在尝试了解如何使用JGit中的.gitattributes。但我找不到任何最能说明它的教程。

是不是JGit不支持它。但是git客户端有这种支持。为什么不JGit?

2 个答案:

答案 0 :(得分:1)

JGit对.gitattributes有基本的支持。请参阅bug 342372以及当前开发状态​​的相关错误。

JGit测试套件可以帮助您了解如何在JGit中实现.gitattributes。有关如何使用JGit源的信息,请参阅this article

答案 1 :(得分:0)

如果您想尝试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;
            }
        });

您可以找到有关这些API here

的测试用例