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
88bcd515
Commit
88bcd515
authored
Jul 20, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
branch: introduce git_reference_is_branch()
parent
eed378b6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
0 deletions
+33
-0
include/git2/refs.h
+10
-0
src/refs.c
+7
-0
tests-clar/refs/read.c
+16
-0
No files found.
include/git2/refs.h
View file @
88bcd515
...
...
@@ -384,6 +384,16 @@ GIT_EXTERN(int) git_reference_remote_tracking_from_branch(
git_reference
*
branch_ref
);
/**
* Check if a reference is a local branch.
*
* @param ref A git reference
*
* @return 1 when the reference lives in the refs/heads
* namespace; 0 otherwise.
*/
GIT_EXTERN
(
int
)
git_reference_is_branch
(
git_reference
*
ref
);
/** @} */
GIT_END_DECL
#endif
src/refs.c
View file @
88bcd515
...
...
@@ -1888,3 +1888,10 @@ cleanup:
git_buf_free
(
&
buf
);
return
error
;
}
int
git_reference_is_branch
(
git_reference
*
ref
)
{
assert
(
ref
);
return
git__prefixcmp
(
ref
->
name
,
GIT_REFS_HEADS_DIR
)
==
0
;
}
tests-clar/refs/read.c
View file @
88bcd515
...
...
@@ -202,3 +202,19 @@ void test_refs_read__unfound_return_ENOTFOUND(void)
cl_assert_equal_i
(
GIT_ENOTFOUND
,
git_reference_lookup
(
&
reference
,
g_repo
,
"refs/tags/test/master"
));
cl_assert_equal_i
(
GIT_ENOTFOUND
,
git_reference_lookup
(
&
reference
,
g_repo
,
"refs/tags/test/farther/master"
));
}
static
void
assert_is_branch
(
const
char
*
name
,
bool
expected_branchness
)
{
git_reference
*
reference
;
cl_git_pass
(
git_reference_lookup
(
&
reference
,
g_repo
,
name
));
cl_assert_equal_i
(
expected_branchness
,
git_reference_is_branch
(
reference
));
git_reference_free
(
reference
);
}
void
test_refs_read__can_determine_if_a_reference_is_a_local_branch
(
void
)
{
assert_is_branch
(
"refs/heads/master"
,
true
);
assert_is_branch
(
"refs/heads/packed"
,
true
);
assert_is_branch
(
"refs/remotes/test/master"
,
false
);
assert_is_branch
(
"refs/tags/e90810b"
,
false
);
}
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