mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
fix(refs): attach refdb owner to loose pseudorefs
Pseudoref lookup now reads `FETCH_HEAD` directly as a loose ref, but callers still expect looked-up references to know their owning repository. Attach the repo's refdb after the loose pseudoref is read so owner-dependent ops such as peeling can safely resolve objects.
This commit is contained in:
@@ -236,8 +236,21 @@ int git_reference_lookup_resolved(
|
||||
* contain additional data that doesn't even follow the normal ref
|
||||
* format. So we look these up as "loose" refs directly.
|
||||
*/
|
||||
if (git_reference__is_pseudoref(name))
|
||||
return git_reference__lookup_loose(ref_out, repo->gitdir, name, repo->oid_type);
|
||||
if (git_reference__is_pseudoref(name)) {
|
||||
if ((error = git_reference__lookup_loose(ref_out, repo->gitdir, name, repo->oid_type)) < 0)
|
||||
return error;
|
||||
|
||||
if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) {
|
||||
git_reference_free(*ref_out);
|
||||
*ref_out = NULL;
|
||||
return error;
|
||||
}
|
||||
|
||||
GIT_REFCOUNT_INC(refdb);
|
||||
(*ref_out)->db = refdb;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((error = reference_normalize_for_repo(normalized, repo, name, true)) < 0 ||
|
||||
(error = git_repository_refdb__weakptr(&refdb, repo)) < 0 ||
|
||||
|
||||
@@ -14,6 +14,7 @@ void test_refs_pseudoref__lookup_fetch_head_after_fetch(void)
|
||||
git_repository *dst;
|
||||
git_remote *remote;
|
||||
git_reference *ref;
|
||||
git_object *commit;
|
||||
git_str url = GIT_STR_INIT;
|
||||
|
||||
cl_git_sandbox_init("testrepo.git");
|
||||
@@ -28,8 +29,10 @@ void test_refs_pseudoref__lookup_fetch_head_after_fetch(void)
|
||||
|
||||
cl_git_pass(git_reference_lookup(&ref, dst, "FETCH_HEAD"));
|
||||
cl_assert_equal_i(GIT_REFERENCE_DIRECT, git_reference_type(ref));
|
||||
cl_assert(ref->db == NULL);
|
||||
cl_assert(ref->db != NULL);
|
||||
cl_git_pass(git_reference_peel(&commit, ref, GIT_OBJECT_COMMIT));
|
||||
|
||||
git_object_free(commit);
|
||||
git_reference_free(ref);
|
||||
git_repository_free(dst);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user