2

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?

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
Ragu
  • 187
  • 1
  • 11
  • If I understand correct, JGit is only a library, that is you build a git client with it in java – niceman Jun 23 '16 at 12:16
  • @niceman: Can you point me to some useful examples\tutorials for working with .gitattriebutes using JGit ? – Ragu Jun 23 '16 at 12:17
  • Yes, I'm using eclipse (with EGit that uses JGit) and I'm integrating GIT into it. – Ragu Jun 23 '16 at 12:23
  • if you're on windows, there is [this](http://stackoverflow.com/questions/22629396/cant-get-git-to-correctly-handle-crlf-problems-with-eclipse-launch-configs-xml) problem. besides that any documentation/tutorial/example for git is good – niceman Jun 23 '16 at 12:33
  • like [this](https://git-scm.com/docs/gitattributes) documentation – niceman Jun 23 '16 at 12:35
  • If you feel an answer solved the problem, please mark it as 'accepted' by clicking the green checkmark. This helps keep the focus on older posts which still don't have answers. – Rüdiger Herrmann Mar 02 '18 at 20:59

2 Answers2

1

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.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • Thanks, Can you point to some useful links from where I can get to know the usage of JGit attributes ? I cannot find even a single link which illustrates the working behavior of JGit attributes – Ragu Jun 24 '16 at 06:42
  • As far as there is support, .gitattributes behave the same in JGit and native Git. Hence you can use all the regular information about .gitattributes. If you find something is not working as described for native Git, you may want to file a [bug report](https://eclipse.org/jgit/support/) – Rüdiger Herrmann Jun 24 '16 at 09:11
  • Yes, I understand that. I would like to know any self explanatory tutorial exists like [cookbook](https://github.com/centic9/jgit-cookbook) which has self-explanatory code illustrating the various JGIT commands, Any tutorial\example exists from which I can learn how to play with JGit attributes ? – Ragu Jun 24 '16 at 09:33
  • To understand 'various' JGit commands, you may want to read a getting started tutorial like this: http://www.codeaffine.com/2015/12/15/getting-started-with-jgit/ – Rüdiger Herrmann Jun 24 '16 at 11:28
  • Yes, I have read that already. I'm asking if any similar tutorial (like cookbook) exists which illustrates about `org.eclipse.jgit.attributes` – Ragu Jun 24 '16 at 12:04
  • I am not aware of any. – Rüdiger Herrmann Jun 24 '16 at 12:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/115525/discussion-between-ragu-and-rudiger-herrmann). – Ragu Jun 24 '16 at 12:39
0

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

Shijing Lv
  • 6,286
  • 1
  • 20
  • 12