Skip to content

Resolve GitRefSCMHead using its local ref name - #4015

Open
vidhumahajan wants to merge 1 commit into
jenkinsci:masterfrom
vidhumahajan:test-retrieve-git-ref-head
Open

vidhumahajan wants to merge 1 commit into
jenkinsci:masterfrom
vidhumahajan:test-retrieve-git-ref-head

Conversation

@vidhumahajan

Copy link
Copy Markdown

AbstractGitSCMSource.retrieve(SCMHead, TaskListener) always returned null for a GitRefSCMHead.

With DiscoverOtherRefsTrait("refs/custom/foo") the ref is fetched with +refs/custom/foo:refs/remotes/origin/custom/foo, so in the cache repo it only exists as refs/remotes/origin/custom/foo. retrieve() called client.revParse(mHead.getRef()), which looks up refs/custom/foo. That name doesn't exist locally, the GitException was caught and null came back, even when the ref existed. Heads found during a scan are created with the remote ref name too, so they had the same problem.

I found this while writing the test asked for by the //TODO write test using GitRefSCMHead comment.

The fix only touches the GitRefSCMHead branch of retrieve(): the ref now goes through the configured refspecs, and the first matching one gives the local name (expandFromSource(...).getDestination()). If no refspec matches, the original ref is used as before. The TODO is removed.

Testing done

Four new tests in AbstractGitSCMSourceTest:

  • custom ref fetched to refs/remotes/origin/custom/foo resolves to the expected commit
  • a missing custom ref returns null
  • a refspec that keeps the same name (+refs/custom/*:refs/custom/*) still resolves
  • no matching refspec falls back to the original ref

All 33 tests in AbstractGitSCMSourceTest pass locally. I couldn't finish a run of every *SCMSource* test class on my laptop (it ran out of memory), so I'm relying on CI for the rest.

@vidhumahajan
vidhumahajan requested a review from a team as a code owner October 22, 2026 20:18
@github-actions github-actions Bot added the tests Automated test addition or improvement label Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Automated test addition or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant