Skip to content

Support of git worktree option (for JGIT) #215

Description

@qboileau

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 :

[INFO] --- git-commit-id-plugin:2.1.15:revision (default)  ---
org.apache.maven.plugin.MojoExecutionException: Could not get HEAD Ref, are you sure you have some commits in the dotGitDirectory?
    at pl.project13.maven.git.JGitProvider.prepareGitToExtractMoreDetailedReproInformation(JGitProvider.java:106)
    at pl.project13.maven.git.GitDataProvider.loadGitData(GitDataProvider.java:98)
    at pl.project13.maven.git.GitCommitIdMojo.loadGitDataWithJGit(GitCommitIdMojo.java:585)
    at pl.project13.maven.git.GitCommitIdMojo.loadGitData(GitCommitIdMojo.java:558)
    at pl.project13.maven.git.GitCommitIdMojo.execute(GitCommitIdMojo.java:376)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

Activity

  1. TheSnoozer commented on Sep 2, 2015

    @TheSnoozer
    Collaborator

    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 ;-)

  2. TheSnoozer commented on Jun 8, 2016

    @TheSnoozer
    Collaborator
  3. athrunsun commented on Apr 14, 2017

    @athrunsun

    @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?

  4. TheSnoozer commented on Jun 30, 2017

    @TheSnoozer
    Collaborator

    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.

  5. TheSnoozer commented on Jul 11, 2017

    @TheSnoozer
    Collaborator

    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)

  6. TheSnoozer commented on Sep 18, 2017

    @TheSnoozer
    Collaborator

    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 this

  7. athrunsun commented on Sep 18, 2017

    @athrunsun

    @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.

  8. TheSnoozer commented on Sep 18, 2017

    @TheSnoozer
    Collaborator

    @athrunsun agree this is kinda annoying...
    For skipping from CLI please checkout this issue:
    #315

    In 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.

  9. athrunsun commented on Sep 19, 2017

    @athrunsun

    @TheSnoozer That sounds really great, thanks for the fix! Looking forward to 2.2.4 release.

  10. changed the title [-]Support of git worktree option[/-] [+]Support of git worktree option (for JGIT)[/+] on Sep 23, 2017
  11. lysium commented on Apr 23, 2018

    @lysium

    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=true works, though.

  12. TheSnoozer commented on Apr 23, 2018

    @TheSnoozer
    Collaborator

    Well 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).

  13. 21 remaining items

  14. justincranford commented on Feb 10, 2023

    @justincranford

    Does this help anyone out?

    Set maven.gitcommitid.nativegit=true to make git-commit-id-plugin bypass JGit and use native Git instead.

    Workaround: Command Line

    mvn package -Dmaven.gitcommitid.nativegit=true

    Workaround: 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
  15. holle commented on Feb 13, 2023

    @holle

    Hi @justincranford

    yes, 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,
    Holger

    Does this help anyone out?

    Set maven.gitcommitid.nativegit=true to make git-commit-id-plugin bypass JGit and use native Git instead.

    Workaround: Command Line

    mvn package -Dmaven.gitcommitid.nativegit=true

    Workaround: 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
    
  16. TheSnoozer commented on Oct 7, 2024

    @TheSnoozer
    Collaborator

    Not sure if any of the initial reporters still monitors this discussion...but JGIT seems to have finally added (read) support for git worktrees.
    Refs:

    Using the native git is still an option and I certainly haven't run any tests whatsoever...

  17. added this to the 10.0.0 milestone on May 23, 2025
  18. okou19900722 commented on Jul 22, 2026

    @okou19900722

    The 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.

  19. added a commit that references this issue on Sep 13, 2026
  20. added a commit that references this issue on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions