Merge pull request #7227 from weihanglo/pseudoref

fix(refs): attach refdb owner to loose pseudorefs
This commit is contained in:
Edward Thomson
2026-04-23 21:36:50 +01:00
committed by GitHub
3 changed files with 61 additions and 4 deletions

View File

@@ -524,14 +524,20 @@ int git_reference__lookup_loose(
if (!(target = loose_parse_symbolic(&buf)))
error = -1;
else if (out != NULL)
else if (out != NULL) {
*out = git_reference__alloc_symbolic(ref_name, target);
if (*out == NULL)
error = -1;
}
} else {
git_oid oid;
if (!(error = loose_parse_oid(&oid, ref_name, &buf, oid_type)) &&
out != NULL)
out != NULL) {
*out = git_reference__alloc(ref_name, &oid, NULL);
if (*out == NULL)
error = -1;
}
}
git_str_dispose(&buf);

View File

@@ -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 ||

View File

@@ -0,0 +1,38 @@
#include "clar_libgit2.h"
#include "futils.h"
#include "refs.h"
void test_refs_pseudoref__cleanup(void)
{
git_futils_rmdir_r("dst.git", NULL, GIT_RMDIR_REMOVE_FILES);
cl_git_sandbox_cleanup();
}
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");
cl_git_pass(git_repository_init(&dst, "dst.git", true));
cl_git_pass(git_str_printf(&url, "%s", cl_git_path_url("testrepo.git")));
cl_git_pass(git_remote_create_anonymous(&remote, dst, url.ptr));
cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
git_remote_free(remote);
git_str_dispose(&url);
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_git_pass(git_reference_peel(&commit, ref, GIT_OBJECT_COMMIT));
git_object_free(commit);
git_reference_free(ref);
git_repository_free(dst);
}