2

With Git, I can get the commits that affect a path by means of the log command:

# show commits affecting the `sub` directory
git log -- . "sub"

I can also get the commits that did not occur in a directory (as per the SO answer here: https://stackoverflow.com/a/21079437/272023):

git log -- . ":(exclude)sub"
git log -- . ":!sub"
git log -- . ":^sub"

JGit is a Java implementation of Git that offers an implementation of the log command, however it only offers a variation of the former (inclusive) log command, not the exclusive version (https://download.eclipse.org/jgit/site/5.5.1.201910021850-r/apidocs/org/eclipse/jgit/api/LogCommand.html#addPath-java.lang.String-):

public LogCommand addPath(String path)
// Show only commits that affect any of the specified paths. The path must either name a file or a directory exactly and use / (slash) as separator. Note that regex expressions or wildcards are not supported.

Parameters:
    path - a repository-relative path (with / as separator)

Returns:
    this

Is there a way I can obtain a list of commits that did not affect a path (e.g. git log -- . ":(exclude)sub"), using Java and not requiring me to shell out to git itself?

John
  • 10,837
  • 17
  • 78
  • 141
  • I'm not sure this is possible, so I have submitted a PR via Gerrit to the JGit project: https://git.eclipse.org/r/#/c/153673/ – John Dec 02 '19 at 23:18

0 Answers0