Commit 3e199f42 by Russell Belfer

Set error message for branch functions

There were a couple of places where an error was being returned
from branch related code but no error message was being set.
parent cfcdbc10
...@@ -185,7 +185,7 @@ int git_branch_move( ...@@ -185,7 +185,7 @@ int git_branch_move(
git_buf_cstr(&old_config_section), git_buf_cstr(&old_config_section),
git_buf_cstr(&new_config_section))) < 0) git_buf_cstr(&new_config_section))) < 0)
goto done; goto done;
if ((error = git_reference_rename(out, branch, git_buf_cstr(&new_reference_name), force)) < 0) if ((error = git_reference_rename(out, branch, git_buf_cstr(&new_reference_name), force)) < 0)
goto done; goto done;
...@@ -276,6 +276,8 @@ int git_branch_upstream__name( ...@@ -276,6 +276,8 @@ int git_branch_upstream__name(
goto cleanup; goto cleanup;
if (!*remote_name || !*merge_name) { if (!*remote_name || !*merge_name) {
giterr_set(GITERR_REFERENCE,
"branch '%s' does not have an upstream", canonical_branch_name);
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
goto cleanup; goto cleanup;
} }
...@@ -342,6 +344,9 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical ...@@ -342,6 +344,9 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical
remote_name = remote_list.strings[i]; remote_name = remote_list.strings[i];
} else { } else {
git_remote_free(remote); git_remote_free(remote);
giterr_set(GITERR_REFERENCE,
"Reference '%s' is ambiguous", canonical_branch_name);
error = GIT_EAMBIGUOUS; error = GIT_EAMBIGUOUS;
goto cleanup; goto cleanup;
} }
...@@ -354,6 +359,8 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical ...@@ -354,6 +359,8 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical
git_buf_clear(buf); git_buf_clear(buf);
error = git_buf_puts(buf, remote_name); error = git_buf_puts(buf, remote_name);
} else { } else {
giterr_set(GITERR_REFERENCE,
"Could not determine remote for '%s'", canonical_branch_name);
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
} }
...@@ -490,8 +497,11 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name) ...@@ -490,8 +497,11 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
local = 1; local = 1;
else if (git_branch_lookup(&upstream, repo, upstream_name, GIT_BRANCH_REMOTE) == 0) else if (git_branch_lookup(&upstream, repo, upstream_name, GIT_BRANCH_REMOTE) == 0)
local = 0; local = 0;
else else {
giterr_set(GITERR_REFERENCE,
"Cannot set upstream for branch '%s'", shortname);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
}
/* /*
* If it's local, the remote is "." and the branch name is * If it's local, the remote is "." and the branch name is
......
...@@ -49,16 +49,20 @@ void test_refs_branches_remote__no_matching_remote_returns_error(void) ...@@ -49,16 +49,20 @@ void test_refs_branches_remote__no_matching_remote_returns_error(void)
{ {
const char *unknown = "refs/remotes/nonexistent/master"; const char *unknown = "refs/remotes/nonexistent/master";
giterr_clear();
cl_git_fail_with(git_branch_remote_name( cl_git_fail_with(git_branch_remote_name(
NULL, 0, g_repo, unknown), GIT_ENOTFOUND); NULL, 0, g_repo, unknown), GIT_ENOTFOUND);
cl_assert(giterr_last() != NULL);
} }
void test_refs_branches_remote__local_remote_returns_error(void) void test_refs_branches_remote__local_remote_returns_error(void)
{ {
const char *local = "refs/heads/master"; const char *local = "refs/heads/master";
giterr_clear();
cl_git_fail_with(git_branch_remote_name( cl_git_fail_with(git_branch_remote_name(
NULL, 0, g_repo, local), GIT_ERROR); NULL, 0, g_repo, local), GIT_ERROR);
cl_assert(giterr_last() != NULL);
} }
void test_refs_branches_remote__ambiguous_remote_returns_error(void) void test_refs_branches_remote__ambiguous_remote_returns_error(void)
...@@ -75,6 +79,8 @@ void test_refs_branches_remote__ambiguous_remote_returns_error(void) ...@@ -75,6 +79,8 @@ void test_refs_branches_remote__ambiguous_remote_returns_error(void)
git_remote_free(remote); git_remote_free(remote);
giterr_clear();
cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo, cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo,
remote_tracking_branch_name), GIT_EAMBIGUOUS); remote_tracking_branch_name), GIT_EAMBIGUOUS);
cl_assert(giterr_last() != NULL);
} }
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