Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
82374d98
Commit
82374d98
authored
Nov 08, 2014
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
branch: add getter for the upstream remote name
This gets the value from branch.<foo>.remote.
parent
4e1b3b3b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
0 deletions
+43
-0
include/git2/branch.h
+11
-0
src/branch.c
+23
-0
tests/refs/branches/upstream.c
+9
-0
No files found.
include/git2/branch.h
View file @
82374d98
...
...
@@ -260,6 +260,17 @@ GIT_EXTERN(int) git_branch_remote_name(
git_repository
*
repo
,
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
#endif
src/branch.c
View file @
82374d98
...
...
@@ -384,6 +384,29 @@ cleanup:
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
)
{
git_strarray
remote_list
=
{
0
};
...
...
tests/refs/branches/upstream.c
View file @
82374d98
...
...
@@ -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
));
}
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
)
{
git_reference
*
branch
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment