mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 02:56:17 +00:00
refs: make git_reference_cmp consider the name
`git_reference_cmp` only considers the target of a reference, and ignores the name. Meaning that a reference `foo` and reference `bar` pointing to the same commit will compare equal. Correct this, comparing the name _and_ target of a reference.
This commit is contained in:
@@ -1054,10 +1054,14 @@ int git_reference_cmp(
|
||||
const git_reference *ref2)
|
||||
{
|
||||
git_reference_t type1, type2;
|
||||
int ret;
|
||||
|
||||
GIT_ASSERT_ARG(ref1);
|
||||
GIT_ASSERT_ARG(ref2);
|
||||
|
||||
if ((ret = strcmp(ref1->name, ref2->name)) != 0)
|
||||
return ret;
|
||||
|
||||
type1 = git_reference_type(ref1);
|
||||
type2 = git_reference_type(ref2);
|
||||
|
||||
|
||||
27
tests/libgit2/refs/cmp.c
Normal file
27
tests/libgit2/refs/cmp.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "clar_libgit2.h"
|
||||
#include "refs.h"
|
||||
|
||||
static git_repository *g_repo;
|
||||
|
||||
void test_refs_cmp__initialize(void)
|
||||
{
|
||||
g_repo = cl_git_sandbox_init("testrepo2");
|
||||
}
|
||||
|
||||
void test_refs_cmp__cleanup(void)
|
||||
{
|
||||
cl_git_sandbox_cleanup();
|
||||
}
|
||||
|
||||
void test_refs_cmp__symbolic(void)
|
||||
{
|
||||
git_reference *one, *two;
|
||||
|
||||
cl_git_pass(git_reference_lookup(&one, g_repo, "refs/heads/symbolic-one"));
|
||||
cl_git_pass(git_reference_lookup(&two, g_repo, "refs/heads/symbolic-two"));
|
||||
|
||||
cl_assert(git_reference_cmp(one, two) != 0);
|
||||
|
||||
git_reference_free(one);
|
||||
git_reference_free(two);
|
||||
}
|
||||
1
tests/resources/testrepo2/.gitted/refs/heads/symbolic-one
vendored
Normal file
1
tests/resources/testrepo2/.gitted/refs/heads/symbolic-one
vendored
Normal file
@@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
||||
1
tests/resources/testrepo2/.gitted/refs/heads/symbolic-two
vendored
Normal file
1
tests/resources/testrepo2/.gitted/refs/heads/symbolic-two
vendored
Normal file
@@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
||||
Reference in New Issue
Block a user