mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +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:
parent
3cbcceee02
commit
33ceea6099
1 changed files with 7 additions and 1 deletions
|
|
@ -360,7 +360,13 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||||
Hash resolveRef(std::string ref) override
|
Hash resolveRef(std::string ref) override
|
||||||
{
|
{
|
||||||
Object object;
|
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);
|
throw Error("resolving Git reference '%s': %s", ref, git_error_last()->message);
|
||||||
auto oid = git_object_id(object.get());
|
auto oid = git_object_id(object.get());
|
||||||
return toHash(*oid);
|
return toHash(*oid);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue