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
18d6f120
Commit
18d6f120
authored
Nov 12, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag: Deploy EINVALIDSPEC usage
parent
80212ecb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
6 deletions
+46
-6
include/git2/tag.h
+13
-3
src/tag.c
+3
-2
tests-clar/object/tag/write.c
+30
-1
No files found.
include/git2/tag.h
View file @
18d6f120
...
...
@@ -144,6 +144,10 @@ GIT_EXTERN(const char *) git_tag_message(const git_tag *tag);
* The message will not be cleaned up. This can be achieved
* through `git_message_prettify()`.
*
* The tag name will be checked for validity. You must avoid
* the characters '~', '^', ':', '\\', '?', '[', and '*', and the
* sequences ".." and "@{" which have special meaning to revparse.
*
* @param oid Pointer where to store the OID of the
* newly created tag. If the tag already exists, this parameter
* will be the oid of the existing tag, and the function will
...
...
@@ -165,7 +169,7 @@ GIT_EXTERN(const char *) git_tag_message(const git_tag *tag);
*
* @param force Overwrite existing references
*
* @return 0 or an error code
* @return 0 o
n success, GIT_EINVALIDSPEC o
r an error code
* A tag object is written to the ODB, and a proper reference
* is written in the /refs/tags folder, pointing to it
*/
...
...
@@ -200,6 +204,9 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
* this target object. If `force` is true and a reference
* already exists with the given name, it'll be replaced.
*
* The tag name will be checked for validity.
* See `git_tag_create()` for rules about valid names.
*
* @param oid Pointer where to store the OID of the provided
* target object. If the tag already exists, this parameter
* will be filled with the oid of the existing pointed object
...
...
@@ -216,7 +223,7 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
*
* @param force Overwrite existing references
*
* @return 0 or an error code
* @return 0 o
n success, GIT_EINVALIDSPEC o
r an error code
* A proper reference is written in the /refs/tags folder,
* pointing to the provided target object
*/
...
...
@@ -230,12 +237,15 @@ GIT_EXTERN(int) git_tag_create_lightweight(
/**
* Delete an existing tag reference.
*
* The tag name will be checked for validity.
* See `git_tag_create()` for rules about valid names.
*
* @param repo Repository where lives the tag
*
* @param tag_name Name of the tag to be deleted;
* this name is validated for consistency.
*
* @return 0 or an error code
* @return 0 o
n success, GIT_EINVALIDSPEC o
r an error code
*/
GIT_EXTERN
(
int
)
git_tag_delete
(
git_repository
*
repo
,
...
...
src/tag.c
View file @
18d6f120
...
...
@@ -251,7 +251,7 @@ static int git_tag_create__internal(
error
=
retrieve_tag_reference_oid
(
oid
,
&
ref_name
,
repo
,
tag_name
);
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
return
-
1
;
goto
cleanup
;
/** Ensure the tag name doesn't conflict with an already existing
* reference unless overwriting has explictly been requested **/
...
...
@@ -269,6 +269,7 @@ static int git_tag_create__internal(
error
=
git_reference_create
(
&
new_ref
,
repo
,
ref_name
.
ptr
,
oid
,
allow_ref_overwrite
);
cleanup:
git_reference_free
(
new_ref
);
git_buf_free
(
&
ref_name
);
return
error
;
...
...
@@ -384,7 +385,7 @@ int git_tag_delete(git_repository *repo, const char *tag_name)
git_buf_free
(
&
ref_name
);
if
(
error
<
0
)
return
-
1
;
return
error
;
return
git_reference_delete
(
tag_ref
);
}
...
...
tests-clar/object/tag/write.c
View file @
18d6f120
...
...
@@ -88,7 +88,6 @@ void test_object_tag_write__overwrite(void)
git_object_free
(
target
);
git_signature_free
(
tagger
);
}
void
test_object_tag_write__replace
(
void
)
...
...
@@ -190,3 +189,33 @@ void test_object_tag_write__delete(void)
git_reference_free
(
ref_tag
);
}
void
test_object_tag_write__creating_with_an_invalid_name_returns_EINVALIDSPEC
(
void
)
{
git_oid
target_id
,
tag_id
;
git_signature
*
tagger
;
git_object
*
target
;
git_oid_fromstr
(
&
target_id
,
tagged_commit
);
cl_git_pass
(
git_object_lookup
(
&
target
,
g_repo
,
&
target_id
,
GIT_OBJ_COMMIT
));
cl_git_pass
(
git_signature_new
(
&
tagger
,
tagger_name
,
tagger_email
,
123456789
,
60
));
cl_assert_equal_i
(
GIT_EINVALIDSPEC
,
git_tag_create
(
&
tag_id
,
g_repo
,
"Inv@{id"
,
target
,
tagger
,
tagger_message
,
0
)
);
cl_assert_equal_i
(
GIT_EINVALIDSPEC
,
git_tag_create_lightweight
(
&
tag_id
,
g_repo
,
"Inv@{id"
,
target
,
0
)
);
git_object_free
(
target
);
git_signature_free
(
tagger
);
}
void
test_object_tag_write__deleting_with_an_invalid_name_returns_EINVALIDSPEC
(
void
)
{
cl_assert_equal_i
(
GIT_EINVALIDSPEC
,
git_tag_delete
(
g_repo
,
"Inv@{id"
));
}
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