diff options
author | Sven Strickroth <email@cs-ware.de> | 2020-09-08 21:05:18 +0200 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-10-25 16:33:28 +0000 |
commit | fe11160c724853fe8469a9788c5992420e4638de (patch) | |
tree | e3d68202742a4b018ee351c098c2b358fe90963e /src/branch.c | |
parent | c7143d7ce4f4386ca5b024876177f915c39ff86e (diff) | |
download | libgit2-fe11160c724853fe8469a9788c5992420e4638de.tar.gz |
Add git_branch_name_is_valid
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Diffstat (limited to 'src/branch.c')
-rw-r--r-- | src/branch.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/branch.c b/src/branch.c index 715f6cf99..000a63ad8 100644 --- a/src/branch.c +++ b/src/branch.c @@ -723,3 +723,32 @@ int git_branch_is_head( return is_same; } + +int git_branch_name_is_valid(int *valid, const char *name) +{ + git_buf ref_name = GIT_BUF_INIT; + int error = 0; + + GIT_ASSERT(valid); + + *valid = 0; + + /* + * Discourage branch name starting with dash, + * https://github.com/git/git/commit/6348624010888b + * and discourage HEAD as branch name, + * https://github.com/git/git/commit/a625b092cc5994 + */ + if (!name || name[0] == '-' || !git__strcmp(name, "HEAD")) + goto done; + + if ((error = git_buf_puts(&ref_name, GIT_REFS_HEADS_DIR)) < 0 || + (error = git_buf_puts(&ref_name, name)) < 0) + goto done; + + error = git_reference_name_is_valid(valid, ref_name.ptr); + +done: + git_buf_dispose(&ref_name); + return error; +} |