Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of git worktree option (for JGIT) #215

Open
qboileau opened this issue Sep 2, 2015 · 28 comments
Open

Support of git worktree option (for JGIT) #215

qboileau opened this issue Sep 2, 2015 · 28 comments

Comments

@qboileau
Copy link

qboileau commented Sep 2, 2015

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)
@TheSnoozer
Copy link
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 ;-)

@TheSnoozer
Copy link
Collaborator

@athrunsun
Copy link

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

@TheSnoozer
Copy link
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.

@TheSnoozer
Copy link
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)

@TheSnoozer
Copy link
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

@athrunsun
Copy link

athrunsun commented Sep 18, 2017

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

@TheSnoozer
Copy link
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.

@athrunsun
Copy link

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

@TheSnoozer TheSnoozer changed the title Support of git worktree option Support of git worktree option (for JGIT) Sep 23, 2017
@lysium
Copy link

lysium commented Apr 23, 2018

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.

@TheSnoozer
Copy link
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).

@lysium
Copy link

lysium commented May 7, 2018

Thanks for the reply -- I got confused about the "Closed" message above, which references another issue; sorry about that.

I do have commits in the repo; I guess jgit gets confused that .git is a file in a worktree, hence the misleading error message.

@TheSnoozer
Copy link
Collaborator

There is finally some progress on the JGit side on this issue (https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475).

The native git-implementation (<useNativeGit>true</useNativeGit>) should (still) support this...

@elexx
Copy link

elexx commented Dec 9, 2019

2019 and it looks like JGit finally supports read-operations on worktrees, which might be enough to fix this issue, since we don't want to create/modify/delete worktrees here?

https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475#c41

@TheSnoozer
Copy link
Collaborator

Maybe I'm missing something, but the changes are not merged?!?

At least the linked change-set (e.g. https://git.eclipse.org/r/#/c/126440/, https://git.eclipse.org/r/#/c/126454/ or https://git.eclipse.org/r/#/c/67873/ are labeled as Needs Code-Review Label or even Abandoned. The issue itself is labeled with version 4.1, this plugin uses 5.2.2.201904231744-r

@elexx
Copy link

elexx commented Dec 11, 2019

You are right. I was just reading the linked issue, but did not check the actual code/patches.

@TheSnoozer
Copy link
Collaborator

Yeah...thanks for reminding me on this issue, but sadly it seems there is no progress on the JGit-side....the native git-implementation (<useNativeGit>true</useNativeGit>) should (still) support this...let's see if it gets merged in 2020...when it does it perhaps will also break some java versioning support for java 8

@holle
Copy link

holle commented Jul 9, 2020

Hey folks, are there any news on this issue?
Regarding the post https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475#c53 a egit + jgit version for testing in Eclipse is available -- and it works for me (Eclipse 2020-06).
So what would it take to make the changes work here as well?

The Eclipse Package contains org.eclipse.jgit 5.8.0.202006012134

Cheers,
Holger

@TheSnoozer
Copy link
Collaborator

Hi,
thanks for bringing this long living ticket up again!
Unfortunately it seems the referenced ticket is still open and not merged.
One of the more recent comments points to https://git.eclipse.org/r/126454, however the status there is Abandoned and it is superseeded by https://git.eclipse.org/r/163940. This specific commit has a merge conflict and thus it appears nothing was yet merged that supports 'git worktrees'. Also the release-notes (e.g. https://projects.eclipse.org/projects/technology.jgit/releases/5.8.0) seem to lack to point to such support.

I know there is also an unofficial build linked in the discussion you mentioned, however I'd rather have some official support over some random binary shared via dropbox. Perhaps I'm missing a link?

@holle
Copy link

holle commented Jul 14, 2020

Hi,

in regard to your question:

I know there is also an unofficial build linked in the discussion you mentioned, however I'd rather have some official support over some random binary shared via dropbox. Perhaps I'm missing a link?

No, but maybe we could check the source he attached and build a „unofficial test Version“ as well in order to see if it works for us.
To be frank, I did not go through to repo or PRs, but rather read the conversation and took from it that he resolved that merge conflict somehow and the maintainers are „looking into it“ themselves.

Andre Bossert wrote:

Hi,andre,thank you very much for your private work. Can this zip can be used
as sbt plugin? and how?
Btw, i still don't get why jgit don't support worktree in official way.

Hi, thanks, but i'm not alone ;) we are preparing new version for review.

Thanks in advance,
Holger

@TheSnoozer
Copy link
Collaborator

Ah thanks for the clarifications on your observation! Technically we potentially could assemble our own JGit version with the support of worktrees, however I feel I'm not the maintainer or a contributor to jGit. This plugin (or me in the case) are "simply" users. What happens if such support doesn't work accurate? Then I'm forced to keep monkey-patching a release and integrate whatever JGit changes come in. From the perspective of the plugin user's still can work when using <useNativeGit>true</useNativeGit>. Furthermore there are already many merge-requests and attempts made to integrate the functionality. From my perspective it's the responsibility of a maintainer of JGit to take care of getting them integrated.

All together I'd prefer to wait until the changes are integrated officially.

@holle
Copy link

holle commented Jul 16, 2020

All together I'd prefer to wait until the changes are integrated officially.

Understood, thanks for clarifying

👍

@shoffmeister
Copy link

For the record (and folks who hit this via an Internet search), version 4.0.3 of this plugin still has challenges with "worktree".

Not sure about 4.0.4 (the latest release as of this comment)

@shoffmeister
Copy link

FWIW, https://git.eclipse.org/r/c/jgit/jgit/+/163940/ (upstream jgit gerrit review) still exists, last activity there is from mid-December 2020; that patch has a merge conflict.

I am not surprised then that version 4.0.4 of this plugin remains unhappy about worktrees; I suppose the workaround mentioned above - <useNativeGit>true</useNativeGit> - still applies.

@TheSnoozer
Copy link
Collaborator

Hi, thanks for the update. Indeed if JGit doesn't support worktrees the plugin will sadly will not suddenly work with JGit. The workaround by using the native git implementation (via <useNativeGit>true</useNativeGit>) should still work fine. This applies for all plugin versions that have been released so far.

@jeffjensen
Copy link

Interestingly, the JGit change to correctly solve this issue https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475 has 85 votes, the highest JGit one at the moment by nearly three times, with the next highest at 29 votes. While the entry is 6 years old, there are promising comments this year (June, October) on implementation movement.

ksobolew added a commit to ksobolew/trino that referenced this issue Mar 8, 2022
This is a workaround for inability to build Trino in a git worktree.
This is a long-standing issue in the plugin, see
git-commit-id/git-commit-id-maven-plugin#215.
hashhar pushed a commit to trinodb/trino that referenced this issue Mar 8, 2022
This is a workaround for inability to build Trino in a git worktree.
This is a long-standing issue in the plugin, see
git-commit-id/git-commit-id-maven-plugin#215.
BewareMyPower pushed a commit to streamnative/kop that referenced this issue May 15, 2022
…rktrees (#1285)

### Motivation
You cannot use git worktrees in KOP development.

### Modifications
see  git-commit-id/git-commit-id-maven-plugin#215
eolivelli added a commit to datastax/starlight-for-kafka that referenced this issue May 17, 2022
…rktrees (#1285)

### Motivation
You cannot use git worktrees in KOP development.

### Modifications
see  git-commit-id/git-commit-id-maven-plugin#215

(cherry picked from commit dbea538)
BewareMyPower pushed a commit to streamnative/kop that referenced this issue May 20, 2022
…rktrees (#1285)

### Motivation
You cannot use git worktrees in KOP development.

### Modifications
see  git-commit-id/git-commit-id-maven-plugin#215

(cherry picked from commit dbea538)
BewareMyPower pushed a commit to streamnative/kop that referenced this issue May 20, 2022
…rktrees (#1285)

### Motivation
You cannot use git worktrees in KOP development.

### Modifications
see  git-commit-id/git-commit-id-maven-plugin#215

(cherry picked from commit dbea538)
BewareMyPower pushed a commit to streamnative/kop that referenced this issue May 20, 2022
…rktrees (#1285)

### Motivation
You cannot use git worktrees in KOP development.

### Modifications
see  git-commit-id/git-commit-id-maven-plugin#215

(cherry picked from commit dbea538)
eolivelli added a commit to datastax/starlight-for-kafka that referenced this issue Jun 22, 2022
…rktrees (#1285)

### Motivation
You cannot use git worktrees in KOP development.

### Modifications
see  git-commit-id/git-commit-id-maven-plugin#215

(cherry picked from commit dbea538)
(cherry picked from commit e9d4e20)
@justincranford
Copy link

justincranford commented Feb 10, 2023

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

@holle
Copy link

holle commented Feb 13, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants