codeintel: fix git log ambiguous refname when branch and tag share name but different commit
Created by: Strum355
This PR closes #31098 (closed) by using the commit hash of the branch's HEAD for which we are requesting the unique commits of. As the commit hash is unambiguous in the face of refnames (tags + branches) having the same name, and git log
accepts both object hashes as well as ref names, this change results in the exact same behaviour while also addressing ambiguity cases.
In the test repository, theres both a branch and a tag called testy
but both pointing towards different commits. The previous behaviour of passing the branch name to CommitsUniqueToBranch surfaces the "refname is ambiguous" case, while passing the commit hash instead gives us the correct behaviour. The correctness of the output is confirmed by the output of the same commands on the testx
branch, which shares the same HEAD commit while not being an ambiguous refname.
Test repository
Git Graph
refs/heads/{testx,testy}
1---------------------2
refs/heads/main
refs/tags/testy
Test plan
- Tested git cli invocation behaviour on a test repository with a branch and tag having the same name
- Ran the existing unit tests, with mock behaviour changed in accordance with CommitsUniqueToBranch taking in the branch HEAD's commit hash
- Ran the full dry-run CI pipeline before creating the pull request. Link: https://buildkite.com/sourcegraph/sourcegraph/builds/131027