grgit
grgit copied to clipboard
LogOp: Support for --first-parent and --no-merges
Hi,
first I have to write a big "THANK YOU" for this plugin. It helps me a lot dealing with git in gradle.
However, there is one thing that's missing that I would need. Is it possible to get a result from LogOp that's identical to "git log myTag --first-parent --no-merges"?
By now I get all commit messages, but in fact I only want those from the master branch without merge commit messages. The "--first-parent --no-merges" options are also explained here (that's why I found them): http://stackoverflow.com/questions/10248137/git-how-to-list-commits-on-this-branch-but-not-from-merged-branches
I don't think JGit has direct support for those options (see LogCommand). Since I try to stick to JGit's porcelain commands, I'd suggest filing an issue with JGit to see if that could be enhanced.
Ok... I understand. Thanks for the support so far.
I filled a bug for jgit (Bug 476697 here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=476697). Let's see if they are willing to extend LogCommand. If so, it would be great to have these options in grgit also (and if not you can close this bug :-)
Yeah, if they patch it let me know and this can be enhanced.
Confirming that the JGit bug is still open as of 10/22/2017.
As workaround for --no-merges
you could use the following approach:
grgit.log(maxCommits: 10).find { it.parentIds.size() == 1 }
which is nearly the same as --no-merges
. Unfortunately, as filtering happens after the log command has been executed, it is more likely that the result of find
is null
(I emphasized this in the example by using maxCommits = 10
as we may end up with 10 log entries in a row, which are all merge commits...).
While it seems to be unlikely that JGit will support --no-merges
directly, it may be possible to use the option RevFilter
in LogCommand. As can be seen in JavaDoc of RevFilter, we then have the option to filter for example by no-merges
as well as only-merges
.