From 33ceea60998646e8f0b21f473d5cb799d90ca387 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Mon, 21 Jul 2025 21:10:41 -0700 Subject: [PATCH] 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 --- src/libfetchers/git-utils.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index f45360f71..a758848b2 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -360,7 +360,13 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this 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);