Commit 392eced6f08b36fedf80287702d1aaf410c7079f

nulltoken 2012-05-11T22:22:14

branch: retrieve symbolic references when listing the branches

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");
+}