mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 21:08:56 +00:00
branch: retrieve symbolic references when listing the branches
This commit is contained in:
parent
88d6e04408
commit
392eced6f0
@ -170,7 +170,7 @@ int git_branch_list(git_strarray *branch_names, git_repository *repo, unsigned i
|
||||
filter.branchlist = &branchlist;
|
||||
filter.branch_type = list_flags;
|
||||
|
||||
error = git_reference_foreach(repo, GIT_REF_OID|GIT_REF_PACKED, &branch_list_cb, (void *)&filter);
|
||||
error = git_reference_foreach(repo, GIT_REF_LISTALL, &branch_list_cb, (void *)&filter);
|
||||
if (error < 0) {
|
||||
git_vector_free(&branchlist);
|
||||
return -1;
|
||||
|
@ -30,7 +30,7 @@ static void assert_retrieval(unsigned int flags, unsigned int expected_count)
|
||||
{
|
||||
cl_git_pass(git_branch_list(&branch_list, repo, flags));
|
||||
|
||||
cl_assert(branch_list.count == expected_count);
|
||||
cl_assert_equal_i(expected_count, branch_list.count);
|
||||
}
|
||||
|
||||
void test_refs_branches_listall__retrieve_all_branches(void)
|
||||
@ -47,3 +47,32 @@ void test_refs_branches_listall__retrieve_local_branches(void)
|
||||
{
|
||||
assert_retrieval(GIT_BRANCH_LOCAL, 6);
|
||||
}
|
||||
|
||||
static void assert_branch_list_contains(git_strarray *branches, const char* expected_branch_name)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < branches->count; i++) {
|
||||
if (strcmp(expected_branch_name, branches->strings[i]) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
cl_fail("expected branch not found in list.");
|
||||
}
|
||||
|
||||
/*
|
||||
* $ git branch -r
|
||||
* nulltoken/HEAD -> nulltoken/master
|
||||
* nulltoken/master
|
||||
*/
|
||||
void test_refs_branches_listall__retrieve_remote_symbolic_HEAD_when_present(void)
|
||||
{
|
||||
git_reference_free(fake_remote);
|
||||
cl_git_pass(git_reference_create_symbolic(&fake_remote, repo, "refs/remotes/nulltoken/HEAD", "refs/remotes/nulltoken/master", 0));
|
||||
|
||||
cl_git_pass(git_branch_list(&branch_list, repo, GIT_BRANCH_REMOTE));
|
||||
|
||||
cl_assert_equal_i(2, branch_list.count);
|
||||
assert_branch_list_contains(&branch_list, "refs/remotes/nulltoken/HEAD");
|
||||
assert_branch_list_contains(&branch_list, "refs/remotes/nulltoken/master");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user