I'm trying to understand how to use the .gitattributes from JGit. But I'm unable to find any tutorial which best demonstrates it.
Is it that JGit hasn't support for it. But git client has this support. Why not JGit?
I'm trying to understand how to use the .gitattributes from JGit. But I'm unable to find any tutorial which best demonstrates it.
Is it that JGit hasn't support for it. But git client has this support. Why not JGit?
JGit has basic support for .gitattributes. See bug 342372 and related bugs for the current state of development.
The JGit test suite may help you understanding how .gitattributes are implemented in JGit. See this article for how to work with the JGit sources.
If you would like to try libgi2, there is a jni bindings that allows you to access most recent libgit2 attributes apis
Following are some examples:
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;
}
});
You can find the test case about these apis here