diff options
author | yuangli <yuangli@mathworks.com> | 2022-07-11 13:54:38 +0100 |
---|---|---|
committer | yuangli <yuangli@mathworks.com> | 2022-07-11 13:54:38 +0100 |
commit | 391afec497364e5c945cd1d78aa29e9b8803d9e1 (patch) | |
tree | 9e7540dd01f045f103a23806c32318cf6c4e3a48 | |
parent | 71fafae17a9a82e444c318db9346a6fb9a3d042c (diff) | |
download | libgit2-391afec497364e5c945cd1d78aa29e9b8803d9e1.tar.gz |
branch: refactor branch name validity checks
-rw-r--r-- | src/branch.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/branch.c b/src/branch.c index e6818a86d..69be8c796 100644 --- a/src/branch.c +++ b/src/branch.c @@ -52,6 +52,11 @@ static int not_a_local_branch(const char *reference_name) return -1; } +static bool branch_name_follows_pattern(const char *branch_name) +{ + return branch_name[0] != '-' && git__strcmp(branch_name, "HEAD"); +} + static int create_branch( git_reference **ref_out, git_repository *repository, @@ -72,7 +77,7 @@ static int create_branch( GIT_ASSERT_ARG(ref_out); GIT_ASSERT_ARG(git_commit_owner(commit) == repository); - if (!git__strcmp(branch_name, "HEAD")) { + if (!branch_name_follows_pattern(branch_name)) { git_error_set(GIT_ERROR_REFERENCE, "'HEAD' is not a valid branch name"); error = -1; goto cleanup; @@ -762,7 +767,7 @@ int git_branch_name_is_valid(int *valid, const char *name) * and discourage HEAD as branch name, * https://github.com/git/git/commit/a625b092cc5994 */ - if (!name || name[0] == '-' || !git__strcmp(name, "HEAD")) + if (!name || !branch_name_follows_pattern(name)) goto done; if ((error = git_buf_puts(&ref_name, GIT_REFS_HEADS_DIR)) < 0 || |