From 5915d7001b0084356ece3f23c5e7c3f2be17e39c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 17 Nov 2014 14:28:22 +0100 Subject: branch: consider an empty upstream remote config as not found --- src/branch.c | 6 ++++++ tests/refs/branches/upstream.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/branch.c b/src/branch.c index 01402a2e9..b4e4b0564 100644 --- a/src/branch.c +++ b/src/branch.c @@ -400,6 +400,12 @@ int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *r if ((error = retrieve_upstream_configuration(&str, cfg, refname, "branch.%s.remote")) < 0) goto cleanup; + if (!*str) { + giterr_set(GITERR_REFERENCE, "branch '%s' does not have an upstream remote", refname); + error = GIT_ENOTFOUND; + goto cleanup; + } + error = git_buf_puts(buf, str); cleanup: diff --git a/tests/refs/branches/upstream.c b/tests/refs/branches/upstream.c index abf7933d3..b20b93753 100644 --- a/tests/refs/branches/upstream.c +++ b/tests/refs/branches/upstream.c @@ -70,6 +70,22 @@ void test_refs_branches_upstream__upstream_remote(void) git_buf_free(&buf); } +void test_refs_branches_upstream__upstream_remote_empty_value(void) +{ + git_repository *repository; + git_config *cfg; + git_buf buf = GIT_BUF_INIT; + + repository = cl_git_sandbox_init("testrepo.git"); + cl_git_pass(git_repository_config(&cfg, repository)); + cl_git_pass(git_config_set_string(cfg, "branch.master.remote", "")); + cl_git_fail_with(GIT_ENOTFOUND, git_branch_upstream_remote(&buf, repository, "refs/heads/master")); + + cl_git_pass(git_config_delete_entry(cfg, "branch.master.remote")); + cl_git_fail_with(GIT_ENOTFOUND, git_branch_upstream_remote(&buf, repository, "refs/heads/master")); + cl_git_sandbox_cleanup(); +} + static void assert_merge_and_or_remote_key_missing(git_repository *repository, const git_commit *target, const char *entry_name) { git_reference *branch; -- cgit v1.2.1