Commit c5d8e3006d98023d1540f1404b28a5db1ca0ecd2

Augustin Fabre 2019-02-21T21:46:39

branch: have git_branch_lookup accept GIT_BRANCH_ALL

diff --git a/src/branch.c b/src/branch.c
index 7c6d747..a93db7e 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -22,7 +22,7 @@ static int retrieve_branch_reference(
 	git_reference **branch_reference_out,
 	git_repository *repo,
 	const char *branch_name,
-	int is_remote)
+	bool is_remote)
 {
 	git_reference *branch = NULL;
 	int error = 0;
@@ -334,9 +334,23 @@ int git_branch_lookup(
 	const char *branch_name,
 	git_branch_t branch_type)
 {
+	int error = -1;
 	assert(ref_out && repo && branch_name);
 
-	return retrieve_branch_reference(ref_out, repo, branch_name, branch_type == GIT_BRANCH_REMOTE);
+	switch (branch_type) {
+	case GIT_BRANCH_LOCAL:
+	case GIT_BRANCH_REMOTE:
+		error = retrieve_branch_reference(ref_out, repo, branch_name, branch_type == GIT_BRANCH_REMOTE);
+		break;
+	case GIT_BRANCH_ALL:
+		error = retrieve_branch_reference(ref_out, repo, branch_name, false);
+		if (error == GIT_ENOTFOUND)
+			error = retrieve_branch_reference(ref_out, repo, branch_name, true);
+		break;
+	default:
+		assert(false);
+	}
+	return error;
 }
 
 int git_branch_name(