Merge pull request #685 from nulltoken/fix/list-remote-branches branch: retrieve symbolic references when listing the branches
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/src/branch.c b/src/branch.c
index 6d5880c..881e749 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -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;
diff --git a/tests-clar/refs/branches/listall.c b/tests-clar/refs/branches/listall.c
index 3911773..0a5634f 100644
--- a/tests-clar/refs/branches/listall.c
+++ b/tests-clar/refs/branches/listall.c
@@ -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");
+}