Commit 392eced6 by nulltoken

branch: retrieve symbolic references when listing the branches

parent 88d6e044
...@@ -170,7 +170,7 @@ int git_branch_list(git_strarray *branch_names, git_repository *repo, unsigned i ...@@ -170,7 +170,7 @@ int git_branch_list(git_strarray *branch_names, git_repository *repo, unsigned i
filter.branchlist = &branchlist; filter.branchlist = &branchlist;
filter.branch_type = list_flags; 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) { if (error < 0) {
git_vector_free(&branchlist); git_vector_free(&branchlist);
return -1; return -1;
......
...@@ -30,7 +30,7 @@ static void assert_retrieval(unsigned int flags, unsigned int expected_count) ...@@ -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_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) void test_refs_branches_listall__retrieve_all_branches(void)
...@@ -47,3 +47,32 @@ void test_refs_branches_listall__retrieve_local_branches(void) ...@@ -47,3 +47,32 @@ void test_refs_branches_listall__retrieve_local_branches(void)
{ {
assert_retrieval(GIT_BRANCH_LOCAL, 6); 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");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment