mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-05 16:51:42 +00:00
branch: add getter for the upstream remote name
This gets the value from branch.<foo>.remote.
This commit is contained in:
parent
4e1b3b3b71
commit
82374d9825
@ -260,6 +260,17 @@ GIT_EXTERN(int) git_branch_remote_name(
|
|||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
const char *canonical_branch_name);
|
const char *canonical_branch_name);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the name fo the upstream remote of a local branch
|
||||||
|
*
|
||||||
|
* @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_remote(git_buf *buf, git_repository *repo, const char *refname);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
GIT_END_DECL
|
GIT_END_DECL
|
||||||
#endif
|
#endif
|
||||||
|
23
src/branch.c
23
src/branch.c
@ -384,6 +384,29 @@ cleanup:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
const char *str;
|
||||||
|
git_config *cfg;
|
||||||
|
|
||||||
|
if (!git_reference__is_branch(refname))
|
||||||
|
return not_a_local_branch(refname);
|
||||||
|
|
||||||
|
git_buf_sanitize(buf);
|
||||||
|
if ((error = git_repository_config_snapshot(&cfg, repo)) < 0)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
if ((error = retrieve_upstream_configuration(&str, cfg, refname, "branch.%s.remote")) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
error = git_buf_puts(buf, str);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
git_config_free(cfg);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refname)
|
int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refname)
|
||||||
{
|
{
|
||||||
git_strarray remote_list = {0};
|
git_strarray remote_list = {0};
|
||||||
|
@ -61,6 +61,15 @@ void test_refs_branches_upstream__trying_to_retrieve_a_remote_tracking_reference
|
|||||||
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
|
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_refs_branches_upstream__upstream_remote(void)
|
||||||
|
{
|
||||||
|
git_buf buf = GIT_BUF_INIT;
|
||||||
|
|
||||||
|
cl_git_pass(git_branch_upstream_remote(&buf, repo, "refs/heads/master"));
|
||||||
|
cl_assert_equal_s("test", buf.ptr);
|
||||||
|
git_buf_free(&buf);
|
||||||
|
}
|
||||||
|
|
||||||
static void assert_merge_and_or_remote_key_missing(git_repository *repository, const git_commit *target, const char *entry_name)
|
static void assert_merge_and_or_remote_key_missing(git_repository *repository, const git_commit *target, const char *entry_name)
|
||||||
{
|
{
|
||||||
git_reference *branch;
|
git_reference *branch;
|
||||||
|
Loading…
Reference in New Issue
Block a user