Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5915d70

Browse files
committed
branch: consider an empty upstream remote config as not found
1 parent 8aa7073 commit 5915d70

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/branch.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,12 @@ int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *r
400400
if ((error = retrieve_upstream_configuration(&str, cfg, refname, "branch.%s.remote")) < 0)
401401
goto cleanup;
402402

403+
if (!*str) {
404+
giterr_set(GITERR_REFERENCE, "branch '%s' does not have an upstream remote", refname);
405+
error = GIT_ENOTFOUND;
406+
goto cleanup;
407+
}
408+
403409
error = git_buf_puts(buf, str);
404410

405411
cleanup:

tests/refs/branches/upstream.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ void test_refs_branches_upstream__upstream_remote(void)
7070
git_buf_free(&buf);
7171
}
7272

73+
void test_refs_branches_upstream__upstream_remote_empty_value(void)
74+
{
75+
git_repository *repository;
76+
git_config *cfg;
77+
git_buf buf = GIT_BUF_INIT;
78+
79+
repository = cl_git_sandbox_init("testrepo.git");
80+
cl_git_pass(git_repository_config(&cfg, repository));
81+
cl_git_pass(git_config_set_string(cfg, "branch.master.remote", ""));
82+
cl_git_fail_with(GIT_ENOTFOUND, git_branch_upstream_remote(&buf, repository, "refs/heads/master"));
83+
84+
cl_git_pass(git_config_delete_entry(cfg, "branch.master.remote"));
85+
cl_git_fail_with(GIT_ENOTFOUND, git_branch_upstream_remote(&buf, repository, "refs/heads/master"));
86+
cl_git_sandbox_cleanup();
87+
}
88+
7389
static void assert_merge_and_or_remote_key_missing(git_repository *repository, const git_commit *target, const char *entry_name)
7490
{
7591
git_reference *branch;

0 commit comments

Comments
 (0)