Commit fe9bfec4 by yuangli

tag: refactor tag name validity checks

parent 7560ac4d
...@@ -244,6 +244,15 @@ on_error: ...@@ -244,6 +244,15 @@ on_error:
return -1; return -1;
} }
static bool tag_name_follows_pattern(const char *tag_name)
{
/*
* Discourage tag name starting with dash,
* https://github.com/git/git/commit/4f0accd638b8d2
*/
return tag_name[0] != '-';
}
static int git_tag_create__internal( static int git_tag_create__internal(
git_oid *oid, git_oid *oid,
git_repository *repo, git_repository *repo,
...@@ -269,6 +278,11 @@ static int git_tag_create__internal( ...@@ -269,6 +278,11 @@ static int git_tag_create__internal(
return -1; return -1;
} }
if (!tag_name_follows_pattern(tag_name)) {
git_error_set(GIT_ERROR_TAG, "'%s' is not a valid tag name", tag_name);
return -1;
}
error = retrieve_tag_reference_oid(oid, &ref_name, repo, tag_name); error = retrieve_tag_reference_oid(oid, &ref_name, repo, tag_name);
if (error < 0 && error != GIT_ENOTFOUND) if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup; goto cleanup;
...@@ -540,11 +554,7 @@ int git_tag_name_is_valid(int *valid, const char *name) ...@@ -540,11 +554,7 @@ int git_tag_name_is_valid(int *valid, const char *name)
GIT_ASSERT(valid); GIT_ASSERT(valid);
/* if (!name || !tag_name_follows_pattern(name))
* Discourage tag name starting with dash,
* https://github.com/git/git/commit/4f0accd638b8d2
*/
if (!name || name[0] == '-')
goto done; goto done;
if ((error = git_buf_puts(&ref_name, GIT_REFS_TAGS_DIR)) < 0 || if ((error = git_buf_puts(&ref_name, GIT_REFS_TAGS_DIR)) < 0 ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment