1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Unpeel reference for git+file

If the reference for git+file is an annotated tag, the revision will
differ than when it's fetched using other fetchers such as `github:`
since Github seems to automatiacally peel to the underlying commit.

Turns out that rev-parse has the capability through it's syntax to
request the underlying commit by "peeling" using the `^{commit}` syntax.

This is safe to apply in all scenarios where the goal is to get an
underlying commit.

fixes #11266
This commit is contained in:
Farid Zakaria 2025-07-21 21:10:41 -07:00
parent 3cbcceee02
commit 33ceea6099

View file

@ -360,7 +360,13 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
Hash resolveRef(std::string ref) override
{
Object object;
if (git_revparse_single(Setter(object), *this, ref.c_str()))
// Using the rev-parse notation which libgit2 supports, make sure we peel
// the ref ultimately down to the underlying commit.
// This is to handle the case where it may be an annotated tag which itself has
// an object_id.
std::string peeledRef = ref + "^{commit}";
if (git_revparse_single(Setter(object), *this, peeledRef.c_str()))
throw Error("resolving Git reference '%s': %s", ref, git_error_last()->message);
auto oid = git_object_id(object.get());
return toHash(*oid);