What feature do you want to see added?
Summary
GitSCMFileSystem resolves the head commit ID during construction and stores it in a private commitId field, but getRevision() returns null whenever the filesystem is created via the two-argument SCMFileSystem.of(Item, SCM) overload, even though the resolved commit is sitting in the object.
This makes it impossible for callers using that overload to obtain the exact commit a file (e.g. a Jenkinsfile) was read from, despite the data being available internally.
Current behaviour
In GitSCMFileSystem:
protected GitSCMFileSystem(GitClient client, String remote, final String head, @CheckForNull
AbstractGitSCMSource.SCMRevisionImpl rev) throws IOException, InterruptedException {
super(rev);
/// ...
commitId = rev == null ?
invoke((Repository repository) -> repository.findRef(head).getObjectId()) :
ObjectId.fromString(rev.getHash());
}
When BuilderImpl.build(Item owner, SCM scm, SCMRevision rev) is invoked through SCMFileSystem.of(Item, SCM), rev is null. The constructor resolves a real ObjectId via findRef(head) and stores it in commitId, but passes null to super(rev). Consequently getRevision() (inherited from SCMFileSystem) returns null and the resolved commit is unreachable from outside the class.
Proposed change
- After resolving
commitId, construct an AbstractGitSCMSource.SCMRevisionImpl from it and pass that into super(...) (or assign it to the inherited revision field), so that getRevision() returns a non-null value reflecting the actually-resolved commit.
Or
- keep the current constructor body and add a public
getResolvedHead() (or override getRevision() directly) that returns an SCMRevisionImpl built from the existing private commitId field.
Why this matters
Downstream code needs to know the exact commit from which a Jenkinsfile or other repository file was loaded. The standard, SCM-agnostic API for that is SCMFileSystem.getRevision(). Subversion and Mercurial implementations return real revisions through this method; GitSCMFileSystem is the outlier in returning null for the (Item, SCM) path despite having the data.
AC
SCMFileSystem.of(item, gitScm) returns a GitSCMFileSystem whose getRevision() is non-null and reflects the commit commitId resolves to.
- Behaviour is unchanged when the three-argument overload
SCMFileSystem.of(scmSource, head, rev) is used with an explicit non-null rev.
Related
Upstream changes
No response
Are you interested in contributing this feature?
No response
What feature do you want to see added?
Summary
GitSCMFileSystemresolves the head commit ID during construction and stores it in a privatecommitIdfield, butgetRevision()returnsnullwhenever the filesystem is created via the two-argumentSCMFileSystem.of(Item, SCM)overload, even though the resolved commit is sitting in the object.This makes it impossible for callers using that overload to obtain the exact commit a file (e.g. a
Jenkinsfile) was read from, despite the data being available internally.Current behaviour
In
GitSCMFileSystem:When
BuilderImpl.build(Item owner, SCM scm, SCMRevision rev)is invoked throughSCMFileSystem.of(Item, SCM),revisnull. The constructor resolves a realObjectIdviafindRef(head)and stores it incommitId, but passesnulltosuper(rev). ConsequentlygetRevision()(inherited fromSCMFileSystem) returnsnulland the resolved commit is unreachable from outside the class.Proposed change
commitId, construct anAbstractGitSCMSource.SCMRevisionImplfrom it and pass that intosuper(...)(or assign it to the inherited revision field), so thatgetRevision()returns a non-null value reflecting the actually-resolved commit.Or
getResolvedHead()(or overridegetRevision()directly) that returns anSCMRevisionImplbuilt from the existing privatecommitIdfield.Why this matters
Downstream code needs to know the exact commit from which a
Jenkinsfileor other repository file was loaded. The standard, SCM-agnostic API for that isSCMFileSystem.getRevision(). Subversion and Mercurial implementations return real revisions through this method;GitSCMFileSystemis the outlier in returningnullfor the(Item, SCM)path despite having the data.AC
SCMFileSystem.of(item, gitScm)returns aGitSCMFileSystemwhosegetRevision()is non-null and reflects the commitcommitIdresolves to.SCMFileSystem.of(scmSource, head, rev)is used with an explicit non-nullrev.Related
CpsScmFlowDefinitionbuild path inworkflow-cps-plugincallsSCMFileSystem.of(build.getParent(), scm)to load theJenkinsfilelightweight. With this change, that call site (and any equivalent in third-party plugins) gains visibility of the resolved commit through the standard API.workflow-multibranch-plugin/SCMVar.javarefers to this same gap from a consumer's perspective.Upstream changes
No response
Are you interested in contributing this feature?
No response