Commit cc68c19a by Edward Thomson

Merge branch 'pr/5861'

parents 47dd9f47 f2915ec4
......@@ -305,6 +305,19 @@ GIT_EXTERN(int) git_branch_remote_name(
GIT_EXTERN(int) git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname);
/**
* Retrieve the upstream merge of a local branch
*
* This will return the currently configured "branch.*.merge" for a given
* branch. This branch must be local.
*
* @param buf the buffer into which to write the name
* @param repo the repository in which to look
* @param refname the full name of the branch
* @return 0 or an error code
*/
GIT_EXTERN(int) git_branch_upstream_merge(git_buf *buf, git_repository *repo, const char *refname);
/**
* Determine whether a branch name is valid, meaning that (when prefixed
* with `refs/heads/`) that it is a valid reference name, and that any
* additional branch name restrictions are imposed (eg, it cannot start
......
......@@ -468,7 +468,7 @@ cleanup:
return error;
}
int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname)
static int git_branch_upstream_with_format(git_buf *buf, git_repository *repo, const char *refname, const char *format, const char *format_name)
{
int error;
git_config *cfg;
......@@ -480,11 +480,11 @@ int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *r
return error;
if ((error = git_buf_sanitize(buf)) < 0 ||
(error = retrieve_upstream_configuration(buf, cfg, refname, "branch.%s.remote")) < 0)
(error = retrieve_upstream_configuration(buf, cfg, refname, format)) < 0)
return error;
if (git_buf_len(buf) == 0) {
git_error_set(GIT_ERROR_REFERENCE, "branch '%s' does not have an upstream remote", refname);
git_error_set(GIT_ERROR_REFERENCE, "branch '%s' does not have an upstream %s", refname, format_name);
error = GIT_ENOTFOUND;
git_buf_clear(buf);
}
......@@ -492,6 +492,16 @@ int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *r
return error;
}
int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname)
{
return git_branch_upstream_with_format(buf, repo, refname, "branch.%s.remote", "remote");
}
int git_branch_upstream_merge(git_buf *buf, git_repository *repo, const char *refname)
{
return git_branch_upstream_with_format(buf, repo, refname, "branch.%s.merge", "merge");
}
int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refname)
{
git_strarray remote_list = {0};
......
......@@ -71,6 +71,29 @@ void test_refs_branches_upstream__upstream_remote(void)
git_buf_dispose(&buf);
}
void test_refs_branches_upstream__upstream_merge(void)
{
git_reference *branch;
git_repository *repository;
git_buf buf = GIT_BUF_INIT;
repository = cl_git_sandbox_init("testrepo.git");
/* check repository */
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test"));
cl_git_pass(git_branch_set_upstream(branch, "test/master"));
assert_config_entry_value(repository, "branch.test.remote", "test");
assert_config_entry_value(repository, "branch.test.merge", "refs/heads/master");
git_reference_free(branch);
/* check merge branch */
cl_git_pass(git_branch_upstream_merge(&buf, repository, "refs/heads/test"));
cl_assert_equal_s("refs/heads/master", buf.ptr);
git_buf_dispose(&buf);
}
void test_refs_branches_upstream__upstream_remote_empty_value(void)
{
git_repository *repository;
......
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