Skip to content

Plugin fails in git worktree even when native git is used #639

Closed
@xkrogen

Description

@xkrogen

Describe the bug (required)

This plugin never worked out of the box with git worktrees (#215) due to jGit limitations, but it was fairly easy to work around this issue by using native git as recommended in the comments on that issue. However recently this was broken by bbf8e1a. With this commit, even when native git is used, I get an error like:

[ERROR] Failed to execute goal io.github.git-commit-id:git-commit-id-maven-plugin:6.0.0:revision (default) on project trino-testing-services: Git command exited with invalid status [128]: directory: `/<git_root_dir>/.git/worktrees`, command: `git describe --always --dirty=-dirty --match=* --abbrev=7 --tags`, stdout: ``, stderr: `fatal: this operation must be run in a work tree` -> [Help 1]

The issue appears to be that it is incorrectly detecting the directory in which to run the native git commands using the new approach in the aforementioned commit.

Tell us about your plugin configuration (required)

This comes from the trino project which itself pulls the dependency on the commit-id plugin from airlift/airbase.
The root pom.xml in Trino has:

                <plugin>
                    <groupId>io.github.git-commit-id</groupId>
                    <artifactId>git-commit-id-maven-plugin</artifactId>
                    <configuration>
                        <runOnlyOnce>true</runOnlyOnce>
                        <injectAllReactorProjects>true</injectAllReactorProjects>
                        <!-- A workaround to make build work in a Git worktree, see https://github.com/git-commit-id/git-commit-id-maven-plugin/issues/215 -->
                        <useNativeGit>true</useNativeGit>
                    </configuration>
                </plugin>

The pom.xml pulled from airbase has:

                <plugin>
                    <groupId>io.github.git-commit-id</groupId>
                    <artifactId>git-commit-id-maven-plugin</artifactId>
                    <version>6.0.0</version>
                    <configuration>
                        <!-- Include only properties used above to speed up build (https://github.com/git-commit-id/git-commit-id-maven-plugin/issues/462) -->
                        <includeOnlyProperties>
                            <includeOnlyProperty>\Qgit.build.time</includeOnlyProperty>
                            <includeOnlyProperty>\Qgit.commit.id</includeOnlyProperty>
                            <includeOnlyProperty>\Qgit.commit.id.describe</includeOnlyProperty>
                        </includeOnlyProperties>
                        <dateFormat>yyyy-MM-dd'T'HH:mm:ssZZ</dateFormat>
                        <gitDescribe>
                            <tags>true</tags>
                        </gitDescribe>
                    </configuration>
                </plugin>
...
            <plugin>
                <groupId>io.github.git-commit-id</groupId>
                <artifactId>git-commit-id-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Tell us about the Plugin version used (required)

6.0.0

Tell us about the Maven version used (required)

± ./mvnw --version
Apache Maven 3.9.2 (c9616018c7a021c1c39be70fb2843d6f5f9b8a1c)
Maven home: /Users/ekrogen/.m2/wrapper/dists/apache-maven-3.9.2-bin/2ebamk1oldjuut6lacpbt82514/apache-maven-3.9.2
Java version: 17.0.5, vendor: Microsoft, runtime: /Library/Java/JavaVirtualMachines/jdk17.0.5-msft.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "13.4.1", arch: "x86_64", family: "mac"

Steps to Reproduce (required)

  1. Create a git worktree
  2. Check out the master branch of the trinodb/trino project into this worktree
  3. Try to build:
./mvnw package -DskipTests

Are there any stacktraces or any error messages? (required)

From the message, it looks like the dotGitDirectory is incorrectly being detected as .git/worktrees/master, when it really should be master/.git (where master is the name of the worktree).

./mvnw package -DskipTests -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Dair.check.skip-all=true -Dskip.npm -Dskip.yarn
....
[INFO] --- git-commit-id:6.0.0:revision (default) @ trino-testing-services ---
[INFO] Current project: 'trino-testing-services', first project to execute based on dependency graph: 'trino-testing-services'
[INFO] dotGitDirectory '/<git_root_dir>/.git/worktrees/master'
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for trino-root 421-SNAPSHOT:
[INFO]
[INFO] trino-root ......................................... SUCCESS [  1.607 s]
[INFO] trino-testing-services ............................. FAILURE [  0.491 s]
[INFO] trino-spi .......................................... SKIPPED
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.050 s
[INFO] Finished at: 2023-06-23T09:31:45-07:00
[INFO] ------------------------------------------------------------------------
...
[ERROR] Failed to execute goal io.github.git-commit-id:git-commit-id-maven-plugin:6.0.0:revision (default) on project trino-testing-services: Git command exited with invalid status [128]: directory: `<git_root_dir>/.git/worktrees`, command: `git describe --always --dirty=-dirty --match=* --abbrev=7 --tags`, stdout: ``, stderr: `fatal: this operation must be run in a work tree` -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :trino-testing-services

Is there a (public) project where this issue can be reproduced? (optional)

Trino

Your Environment (optional)

No response

Context (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions