Skip to content

Commit e2e3943

Browse files
authored
Merge pull request libgit2#4367 from pks-t/pks/peel-peeled-to-tag
refs: do not use peeled OID if peeling to a tag
2 parents 62ac393 + b112b1e commit e2e3943

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/refs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,13 @@ int git_reference_peel(
13601360
return peel_error(error, ref, "Cannot resolve reference");
13611361
}
13621362

1363-
if (!git_oid_iszero(&resolved->peel)) {
1363+
/*
1364+
* If we try to peel an object to a tag, we cannot use
1365+
* the fully peeled object, as that will always resolve
1366+
* to a commit. So we only want to use the peeled value
1367+
* if it is not zero and the target is not a tag.
1368+
*/
1369+
if (target_type != GIT_OBJ_TAG && !git_oid_iszero(&resolved->peel)) {
13641370
error = git_object_lookup(&target,
13651371
git_reference_owner(ref), &resolved->peel, GIT_OBJ_ANY);
13661372
} else {

tests/refs/peel.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,15 @@ void test_refs_peel__can_peel_fully_peeled_packed_refs(void)
117117
"0df1a5865c8abfc09f1f2182e6a31be550e99f07",
118118
GIT_OBJ_COMMIT);
119119
}
120+
121+
void test_refs_peel__can_peel_fully_peeled_tag_to_tag(void)
122+
{
123+
assert_peel_generic(g_peel_repo,
124+
"refs/tags/tag-inside-tags", GIT_OBJ_TAG,
125+
"c2596aa0151888587ec5c0187f261e63412d9e11",
126+
GIT_OBJ_TAG);
127+
assert_peel_generic(g_peel_repo,
128+
"refs/foo/tag-outside-tags", GIT_OBJ_TAG,
129+
"c2596aa0151888587ec5c0187f261e63412d9e11",
130+
GIT_OBJ_TAG);
131+
}

0 commit comments

Comments
 (0)