palantir / gradle-git-version

a Gradle plugin that uses `git describe` to produce a version string.
Apache License 2.0
371 stars 76 forks source link

jgit fails on shallow clone #98

Open StrangeNoises opened 6 years ago

StrangeNoises commented 6 years ago

I'm getting this error:

> Inconsistent git describe: native was 8.3-pre and jgit was null. Please report this on github.com/palantir/gradle-git-version

Running with debug gets me a loong stack trace but the top of it looks like:

17:18:18.682 [DEBUG] [com.palantir.gradle.gitversion.JGitDescribe] JGit describe failed with {}
org.eclipse.jgit.errors.MissingObjectException: Missing commit 09d0457984dcf100a07e16da5bda493249ba3ce8
        at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:159)
        at org.eclipse.jgit.revwalk.RevWalk.getCachedBytes(RevWalk.java:903)
        at org.eclipse.jgit.revwalk.RevCommit.parseHeaders(RevCommit.java:155)
        at org.eclipse.jgit.revwalk.RevWalk.parseHeaders(RevWalk.java:1012)
        at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:861)
        at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:772)
        at com.palantir.gradle.gitversion.JGitDescribe.revList(JGitDescribe.java:77)
        at com.palantir.gradle.gitversion.JGitDescribe.describe(JGitDescribe.java:36)
        at com.palantir.gradle.gitversion.VersionDetails.expensiveComputeRawDescription(VersionDetails.java:64)
        at com.palantir.gradle.gitversion.VersionDetails.description(VersionDetails.java:50)
        at com.palantir.gradle.gitversion.VersionDetails.getVersion(VersionDetails.java:30)
        at com.palantir.gradle.gitversion.GitVersionPlugin$1.doCall(GitVersionPlugin.java:22)

This git repo was checked out with:

git clone <url> --branch <branchname> --depth 1

(it's a legacy project, recently - just now - converted to gradle; cloning the whole thing is huge, i wanted to do a minimal checkout.)

I had an earlier error where gitVersion() itself was returning null, causing a later error while writing a manifest, so I created a tag, then I get this.

The commit object mentioned as being missing in the above stacktrace is the penultimate one, ie: the one before the most recent, and therefore as I used --depth 1 it wasn't fetched. So I tried it again with --depth 2 and sure enough it all worked; in fact it worked without me needing to create that tag to have git describe have something to report. So I have a solution for myself, but this does look like a bug.

delta003 commented 6 years ago

Thanks for reporting this! We missed the case where walking the tree following the first parent might not be possible.

Paramood commented 6 years ago

Noticed the similar issue or maybe it is just the same. If two tags point to the same commit, I also get Inconsistent git describe.

martin-a commented 6 years ago

Same problem here with, get a "Inconsistent git describe" error when there is two tags on the same commit

bam80 commented 5 years ago

Maybe related(please confirm): [PATCH] Missing commit when fetching on shallow clone

StrangeNoises commented 5 years ago

i'm sorry i'm not using it any more. also gave up on shallow clones as i hit other more intractable problems with it in my situation!