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
cc68c19a
Commit
cc68c19a
authored
Jul 30, 2021
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'pr/5861'
parents
47dd9f47
f2915ec4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
3 deletions
+49
-3
include/git2/branch.h
+13
-0
src/branch.c
+13
-3
tests/refs/branches/upstream.c
+23
-0
No files found.
include/git2/branch.h
View file @
cc68c19a
...
...
@@ -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
...
...
src/branch.c
View file @
cc68c19a
...
...
@@ -468,7 +468,7 @@ cleanup:
return
error
;
}
int
git_branch_upstream_remote
(
git_buf
*
buf
,
git_repository
*
repo
,
const
char
*
ref
name
)
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"
,
ref
name
);
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
};
...
...
tests/refs/branches/upstream.c
View file @
cc68c19a
...
...
@@ -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
;
...
...
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