Repository navigation
Support of git worktree option (for JGIT) #215
Description
Activity
Hi,
yes this seems not yet implemented in the jGit Implementation.
Does it fail as well when you use the native git binary?Recently started discussion on eclipse about the "worktree"
https://www.eclipse.org/forums/index.php/m/1703524/
Couldn't find a feature-request on the bug-list yet:
https://bugs.eclipse.org/bugs/buglist.cgi?quicksearch=worktree
(maybe we should file one?)Also it should be worth quoting from here https://github.com/blog/2042-git-2-5-including-multiple-worktrees-and-triangular-workflows:
Please note that the worktree feature is experimental. It may have some bugs, and its interface may change based on user feedback. It's not recommended to use git worktree with a repository that contains submodules.Is it still experimental? if so we still have a bit time to implement ;-)
@qboileau @TheSnoozer Now it is 2017 and git comes to version 2.12.x, but I am still having issue with git-commit-id-plugin:2.2.2, that when I tried to build a maven project under a git worktree, it gave me:
[ERROR] Failed to execute goal pl.project13.maven:git-commit-id-plugin:2.2.2:revision (default) on project <some_project>: Could not complete Mojo execution... Error: Could not get HEAD Ref, are you sure you have some commits in the dotGitDirectory? -> [Help 1]Could you help me please?
Would be happy to have this in this plugin as well, but as outlined its a JGit issue (a library we use inside the plugin). If the library doesn't support it, this plugin doesn't support it either.
The Bug 7 Enhancement request for JGit (https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475) is still open and thus it is not available afaik.
Note: This feature will prop break java jdk 1.7 support.
With jgit v4.6 the build was moved towards 1.8 only (https://bugs.eclipse.org/bugs/show_bug.cgi?id=500059)
Well sometimes third party libs takes ages...the bug /enhancement request for JGit (https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475) is still open and thus it is not available for jgit...just saying if it isn't obvious....the native git-implementation (
<useNativeGit>true</useNativeGit>) should support thisReacted by Brice Dutheil, Ashhar Hasan, qxo, alexander taylor and Matthias Fritsche@TheSnoozer That's sad... But on the other hand I can at least skip execution of this plugin from now on when I am on a git worktree since Added property to skip from CLI is released in 2.2.3.
@athrunsun agree this is kinda annoying...
For skipping from CLI please checkout this issue:
#315In a nutshell you can't skip by command-line when the property is configured as plugin configuration (a maven bug). The workaround that even was suggested by the maven team is outlined in #315 (comment)
Regardless I fixed this properly and this workaround won't be required in 2.2.4.@TheSnoozer That sounds really great, thanks for the fix! Looking forward to 2.2.4 release.
- changed the title
[-]Support of git worktree option[/-][+]Support of git worktree option (for JGIT)[/+]on Sep 23, 2017 FWIW, I still get the error with 2.2.4:
[ERROR] Failed to execute goal pl.project13.maven:git-commit-id-plugin:2.2.4:revision (default) on project system-activation-service-app: Could not complete Mojo execution...: Error: Could not get HEAD Ref, are you sure you have some commits in the dotGitDirectory? -> [Help 1]Or am doing sth. wrong?
The workaround with adding
-Dmaven.gitcommitid.skip=trueworks, though.Reacted by jeacott1Well this issue that is reported here is still open and the corresponding changes about git worktree are still not merged into jgit. So if you are using git worktree I'd suggest to follow #215 (comment)
If you don't use git worktree, check if you have any commits in your repo (thats at least what the error says).
21 remaining items
- added a commit that references this issue
on May 13, 2022 - added a commit that references this issue
on May 15, 2022 - added a commit that references this issue
on May 17, 2022 - added 3 commits that reference this issue
on May 20, 2022 - added a commit that references this issue
on Jun 22, 2022 Does this help anyone out?
Set
maven.gitcommitid.nativegit=trueto make git-commit-id-plugin bypass JGit and use native Git instead.Workaround: Command Line
mvn package -Dmaven.gitcommitid.nativegit=trueWorkaround: pom.xml
<properties> <maven.gitcommitid.nativegit>true</maven.gitcommitid.nativegit> </properties>Tested with:
- git-commit-id-plugin: 4.9.10
- command line Git: 2.39.1
Reacted by Matthieu S., nadarian, Matthias Fritsche and Jon S. Muñozyes, it works for me, albeit I am using the following clone/fork with this setting:
<build> <plugins> <plugin> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId> [...] <configuration> <useNativeGit>true</useNativeGit> [...] </configuration> </plugin> </plugins>
Cheers,
HolgerDoes this help anyone out?
Set
maven.gitcommitid.nativegit=trueto make git-commit-id-plugin bypass JGit and use native Git instead.Workaround: Command Line
mvn package -Dmaven.gitcommitid.nativegit=trueWorkaround: pom.xml
<properties> <maven.gitcommitid.nativegit>true</maven.gitcommitid.nativegit> </properties>Tested with:
* git-commit-id-plugin: 4.9.10 * command line Git: 2.39.1Reacted by TheSnoozer and Jan DvorakNot sure if any of the initial reporters still monitors this discussion...but JGIT seems to have finally added (read) support for git worktrees.
Refs:- https://eclipse.gerrithub.io/c/eclipse-jgit/jgit/+/1194900
- eclipse-jgit/jgit@f9beeb3
However that is only available in JGIT 7.X and as per https://projects.eclipse.org/projects/technology.jgit/releases/7.0.0 this would require Java 17 (Require Java 17 (LTS) #708).....
Using the native git is still an option and I certainly haven't run any tests whatsoever...
Reacted by Matthias Kurz, Mayer Markus, Leandro Conca De Luccia, mims-github, Arkadiusz Biczewski and Tomasz KabalaThe issue may not lie in whether we use JGit or native Git, but rather in how lookupGitDirectory is handled. It currently returns the directory of the main repository, not the directory of the worktree. As a result, the generated Git information also comes from the main repository instead of the worktree.
- added a commit that references this issue
on Sep 13, 2026
Hi, since git 2.5.0 worktree option allow to create many working tree linked to a single repository.
Building a linked working tree using git-commit-id-plugin mojo failed because current git reference can't be retrieve. Seems to be JGit issue, but I think it's useful to report here first.
Build exception :