* 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
*
* @param force Overwrite existing references
*
- * @return 0 or an error code
+ * @return 0 on success, GIT_EINVALIDSPEC or 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
*/
* 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
*
* @param force Overwrite existing references
*
- * @return 0 or an error code
+ * @return 0 on success, GIT_EINVALIDSPEC or an error code
* A proper reference is written in the /refs/tags folder,
* pointing to the provided target object
*/
/**
* 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 on success, GIT_EINVALIDSPEC or an error code
*/
GIT_EXTERN(int) git_tag_delete(
git_repository *repo,
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 **/
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;
git_buf_free(&ref_name);
if (error < 0)
- return -1;
+ return error;
return git_reference_delete(tag_ref);
}
git_object_free(target);
git_signature_free(tagger);
-
}
void test_object_tag_write__replace(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"));
+}