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
ba7cc8d2
Commit
ba7cc8d2
authored
Aug 26, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1810 from nvloff/reference_is_tag
refs: add git_reference_is_tag
parents
a07db1a1
504850cd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
0 deletions
+37
-0
include/git2/refs.h
+9
-0
src/refs.c
+11
-0
src/refs.h
+1
-0
tests-clar/refs/read.c
+16
-0
No files found.
include/git2/refs.h
View file @
ba7cc8d2
...
@@ -442,6 +442,15 @@ GIT_EXTERN(int) git_reference_is_branch(git_reference *ref);
...
@@ -442,6 +442,15 @@ GIT_EXTERN(int) git_reference_is_branch(git_reference *ref);
*/
*/
GIT_EXTERN
(
int
)
git_reference_is_remote
(
git_reference
*
ref
);
GIT_EXTERN
(
int
)
git_reference_is_remote
(
git_reference
*
ref
);
/**
* Check if a reference is a tag
*
* @param ref A git reference
*
* @return 1 when the reference lives in the refs/tags
* namespace; 0 otherwise.
*/
GIT_EXTERN
(
int
)
git_reference_is_tag
(
git_reference
*
ref
);
typedef
enum
{
typedef
enum
{
GIT_REF_FORMAT_NORMAL
=
0
,
GIT_REF_FORMAT_NORMAL
=
0
,
...
...
src/refs.c
View file @
ba7cc8d2
...
@@ -952,6 +952,17 @@ int git_reference_is_remote(git_reference *ref)
...
@@ -952,6 +952,17 @@ int git_reference_is_remote(git_reference *ref)
return
git_reference__is_remote
(
ref
->
name
);
return
git_reference__is_remote
(
ref
->
name
);
}
}
int
git_reference__is_tag
(
const
char
*
ref_name
)
{
return
git__prefixcmp
(
ref_name
,
GIT_REFS_TAGS_DIR
)
==
0
;
}
int
git_reference_is_tag
(
git_reference
*
ref
)
{
assert
(
ref
);
return
git_reference__is_tag
(
ref
->
name
);
}
static
int
peel_error
(
int
error
,
git_reference
*
ref
,
const
char
*
msg
)
static
int
peel_error
(
int
error
,
git_reference
*
ref
,
const
char
*
msg
)
{
{
giterr_set
(
giterr_set
(
...
...
src/refs.h
View file @
ba7cc8d2
...
@@ -67,6 +67,7 @@ int git_reference__update_terminal(git_repository *repo, const char *ref_name, c
...
@@ -67,6 +67,7 @@ int git_reference__update_terminal(git_repository *repo, const char *ref_name, c
int
git_reference__is_valid_name
(
const
char
*
refname
,
unsigned
int
flags
);
int
git_reference__is_valid_name
(
const
char
*
refname
,
unsigned
int
flags
);
int
git_reference__is_branch
(
const
char
*
ref_name
);
int
git_reference__is_branch
(
const
char
*
ref_name
);
int
git_reference__is_remote
(
const
char
*
ref_name
);
int
git_reference__is_remote
(
const
char
*
ref_name
);
int
git_reference__is_tag
(
const
char
*
ref_name
);
/**
/**
* Lookup a reference by name and try to resolve to an OID.
* Lookup a reference by name and try to resolve to an OID.
...
...
tests-clar/refs/read.c
View file @
ba7cc8d2
...
@@ -255,6 +255,22 @@ void test_refs_read__can_determine_if_a_reference_is_a_local_branch(void)
...
@@ -255,6 +255,22 @@ void test_refs_read__can_determine_if_a_reference_is_a_local_branch(void)
assert_is_branch
(
"refs/tags/e90810b"
,
false
);
assert_is_branch
(
"refs/tags/e90810b"
,
false
);
}
}
static
void
assert_is_tag
(
const
char
*
name
,
bool
expected_tagness
)
{
git_reference
*
reference
;
cl_git_pass
(
git_reference_lookup
(
&
reference
,
g_repo
,
name
));
cl_assert_equal_i
(
expected_tagness
,
git_reference_is_tag
(
reference
));
git_reference_free
(
reference
);
}
void
test_refs_read__can_determine_if_a_reference_is_a_tag
(
void
)
{
assert_is_tag
(
"refs/tags/e90810b"
,
true
);
assert_is_tag
(
"refs/tags/test"
,
true
);
assert_is_tag
(
"refs/heads/packed"
,
false
);
assert_is_tag
(
"refs/remotes/test/master"
,
false
);
}
void
test_refs_read__invalid_name_returns_EINVALIDSPEC
(
void
)
void
test_refs_read__invalid_name_returns_EINVALIDSPEC
(
void
)
{
{
git_reference
*
reference
;
git_reference
*
reference
;
...
...
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