jgitver / jgitver

jgit based library to calculate semver compatible version from git tree
https://jgitver.github.io/
Apache License 2.0
179 stars 42 forks source link

Missing unknown commit #107

Open DrVanScott opened 4 years ago

DrVanScott commented 4 years ago

Hi,

I use jgitver via mvn plugin in project witch is build in a docker container on CI (bamboo). The source code had been provided by bamboo doing git clone. When maven starts to run in the container, it fails with

[INFO] Using jgitver configuration file: /usr/src/mymaven/.mvn/jgitver.config.xml
[INFO] Using jgitver-maven-plugin [1.4.5] (sha1: 1e058cda8be24eaf8d8fbf29b9bfc67004241126)
[WARNING] cannot autoclose GitVersionCalculator object for project: /usr/src/mymaven
java.lang.IllegalStateException: failure calculating version
    at fr.brouillard.oss.jgitver.GitVersionCalculator.buildVersion (GitVersionCalculator.java:381)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.computeVersion (GitVersionCalculator.java:173)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersionObject (GitVersionCalculator.java:200)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersionObject (GitVersionCalculator.java:189)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersion (GitVersionCalculator.java:299)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersion (GitVersionCalculator.java:287)
    at fr.brouillard.oss.jgitver.JGitverExtension.afterSessionStart (JGitverExtension.java:111)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:208)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.eclipse.jgit.api.errors.JGitInternalException: Missing unknown 1b17b88576117cb423020d563993e798698405f4
    at org.eclipse.jgit.api.StatusCommand.call (StatusCommand.java:161)
    at fr.brouillard.oss.jgitver.impl.GitUtils.isDirty (GitUtils.java:64)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.buildVersion (GitVersionCalculator.java:306)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.computeVersion (GitVersionCalculator.java:173)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersionObject (GitVersionCalculator.java:200)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersionObject (GitVersionCalculator.java:189)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersion (GitVersionCalculator.java:299)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersion (GitVersionCalculator.java:287)
    at fr.brouillard.oss.jgitver.JGitverExtension.afterSessionStart (JGitverExtension.java:111)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:208)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.eclipse.jgit.errors.MissingObjectException: Missing unknown 1b17b88576117cb423020d563993e798698405f4
    at org.eclipse.jgit.internal.storage.file.WindowCursor.open (WindowCursor.java:168)
    at org.eclipse.jgit.lib.ObjectReader.open (ObjectReader.java:236)
    at org.eclipse.jgit.revwalk.RevWalk.parseAny (RevWalk.java:889)
    at org.eclipse.jgit.revwalk.RevWalk.parseTree (RevWalk.java:827)
    at org.eclipse.jgit.lib.IndexDiff.<init> (IndexDiff.java:317)
    at org.eclipse.jgit.lib.IndexDiff.<init> (IndexDiff.java:298)
    at org.eclipse.jgit.api.StatusCommand.call (StatusCommand.java:149)
    at fr.brouillard.oss.jgitver.impl.GitUtils.isDirty (GitUtils.java:64)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.buildVersion (GitVersionCalculator.java:306)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.computeVersion (GitVersionCalculator.java:173)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersionObject (GitVersionCalculator.java:200)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersionObject (GitVersionCalculator.java:189)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersion (GitVersionCalculator.java:299)
    at fr.brouillard.oss.jgitver.GitVersionCalculator.getVersion (GitVersionCalculator.java:287)
    at fr.brouillard.oss.jgitver.JGitverExtension.afterSessionStart (JGitverExtension.java:111)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:208)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[INFO] Scanning for projects...
[WARNING] jgitver has changed!
[WARNING] 
[WARNING] it now requires the usage of maven core extensions (> 3.3.1) instead of standard plugin extensions.
[WARNING] The plugin must be now declared in a `.mvn/extensions.xml` file.
[WARNING] 
[WARNING]     read https://github.com/jgitver/jgitver-maven-plugin for further information
[WARNING] 
[ERROR] detection of jgitver old setting mechanism: jgitver must now use maven core extensions only -> [Help 1]

The problem is, that Bamboo provides the clone using a mechanism called "referenced clone", see man git clone --referece:

If the reference repository is on the local machine, automatically setup .git/objects/info/alternates to obtain objects from the reference repository. Using an already existing repository as an alternate will require fewer objects to be copied from the repository being cloned, reducing network and local storage costs.

Workaround: Use git repack -a -d to "unreference". Or try to mount the referenced git repository into the container

Maybe improve the error message? Some hints to clone --reference, or "path in .aitsrc/.git/objects/info/alternates does not exist"?

Or is this a jgit issue?

The Warning about "jgitver has changed!" is wrong in this situation...

McFoggy commented 4 years ago

Or is this a jgit issue?

for this kind of thing jgitver delegates fully to jgit. Is that an issue with jgit or a lack of parameters/settings in the usage of jgit : it would require some trials/tests with jgit to have an idea.

How is the repository created ? Do you have a reproducer ?

I have tried to reproduce by cloning a local repository:

$ git clone https://github.com/jgitver/jgitver jgitver-local
$ git clone --reference jgitver-local https://github.com/jgitver/jgitver jgitver-with-reference
$ cd  jgitver-with-reference
$ mvn validate
OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
[INFO] Using jgitver configuration file: C:\workspace\demos\jgitver-with-reference\.mvn\jgitver.config.xml
[INFO] Using jgitver-maven-plugin [1.5.1] (sha1: e45d1669b39cedb98720dd33cc14d0185b455ca1)
[INFO]     version '0.12.1-SNAPSHOT' computed in 657 ms
[INFO]
[INFO] Scanning for projects...
[INFO] jgitver-maven-plugin is about to change project(s) version(s)
[INFO]     fr.brouillard.oss::jgitver::0 -> 0.12.1-SNAPSHOT
[INFO]
[INFO] ---------------------< fr.brouillard.oss:jgitver >----------------------
[INFO] Building GIT versioning using jgit 0.12.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- license-maven-plugin:2.11:check (default) @ jgitver ---
[INFO] Checking licenses...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.186 s
[INFO] Finished at: 2020-07-16T11:44:56+02:00
[INFO] ------------------------------------------------------------------------

But then jgitver works as expected inside jgitver-with-reference.

Please provide a reproducer.

soundasleep commented 2 years ago

On GitHub actions, you may get a similar exception:

Caused by: org.eclipse.jgit.errors.MissingObjectException: Missing commit ....hash...
Error: -07T10:37:52.726+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
    at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:164)

This is because by default, GitHub's actions/checkout only fetches a single commit. You need to configure your .github/workflows/.yml to pull all history with fetch-depth: 0:

    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0 # for jgitver