commit bd5895f3726fd0edc272b4c44727f60b5a5132c9 from: Stefan Sperling date: Thu Nov 28 05:06:55 2019 UTC Outright forbid reference names with a leading '-'. Matches behaviour documented in git-repository(5). commit - e560b7e0e2efbbf43870b8d112d4279ca7df5535 commit + bd5895f3726fd0edc272b4c44727f60b5a5132c9 blob - ef77dfcd0650f8cb98621ee08d6b464d4f080d0d blob + 5541936d50a60c79cffb25e28117f4814c40512a --- got/got.c +++ got/got.c @@ -655,12 +655,12 @@ cmd_import(int argc, char *argv[]) return error; /* - * Don't let the user create a branch named '-'. + * Don't let the user create a branch name with a leading '-'. * While technically a valid reference name, this case is usually * an unintended typo. */ - if (branch_name[0] == '-' && branch_name[1] == '\0') - return got_error_path(branch_name, GOT_ERR_BAD_REF_NAME); + if (branch_name[0] == '-') + return got_error_path(branch_name, GOT_ERR_REF_NAME_MINUS); if (asprintf(&refname, "refs/heads/%s", branch_name) == -1) { error = got_error_from_errno("asprintf"); @@ -3096,12 +3096,12 @@ add_ref(struct got_repository *repo, const char *refna struct got_reference *ref = NULL; /* - * Don't let the user create a reference named '-'. + * Don't let the user create a reference name with a leading '-'. * While technically a valid reference name, this case is usually * an unintended typo. */ - if (refname[0] == '-' && refname[1] == '\0') - return got_error_path(refname, GOT_ERR_BAD_REF_NAME); + if (refname[0] == '-') + return got_error_path(refname, GOT_ERR_REF_NAME_MINUS); err = got_repo_match_object_id_prefix(&id, target, GOT_OBJ_TYPE_ANY, repo); @@ -3139,12 +3139,12 @@ add_symref(struct got_repository *repo, const char *re struct got_reference *target_ref = NULL; /* - * Don't let the user create a reference named '-'. + * Don't let the user create a reference name with a leading '-'. * While technically a valid reference name, this case is usually * an unintended typo. */ - if (refname[0] == '-' && refname[1] == '\0') - return got_error_path(refname, GOT_ERR_BAD_REF_NAME); + if (refname[0] == '-') + return got_error_path(refname, GOT_ERR_REF_NAME_MINUS); err = got_ref_open(&target_ref, repo, target, 0); if (err) @@ -3430,12 +3430,12 @@ add_branch(struct got_repository *repo, const char *br char *base_refname = NULL, *refname = NULL; /* - * Don't let the user create a branch named '-'. + * Don't let the user create a branch name with a leading '-'. * While technically a valid reference name, this case is usually * an unintended typo. */ - if (branch_name[0] == '-' && branch_name[1] == '\0') - return got_error_path(branch_name, GOT_ERR_BAD_REF_NAME); + if (branch_name[0] == '-') + return got_error_path(branch_name, GOT_ERR_REF_NAME_MINUS); if (asprintf(&refname, "refs/heads/%s", branch_name) == -1) { err = got_error_from_errno("asprintf"); @@ -3849,12 +3849,12 @@ add_tag(struct got_repository *repo, const char *tag_n int preserve_tagmsg = 0; /* - * Don't let the user create a tag named '-'. + * Don't let the user create a tag name with a leading '-'. * While technically a valid reference name, this case is usually * an unintended typo. */ - if (tag_name[0] == '-' && tag_name[1] == '\0') - return got_error_path(tag_name, GOT_ERR_BAD_REF_NAME); + if (tag_name[0] == '-') + return got_error_path(tag_name, GOT_ERR_REF_NAME_MINUS); err = get_author(&tagger, repo); if (err) blob - 4e252ffbac5584645f2d0ce7bd4ba2688825f65d blob + e2e96e4065e6d735452b5a23c4eb1ad179abfa67 --- include/got_error.h +++ include/got_error.h @@ -126,6 +126,7 @@ #define GOT_ERR_GIT_REPO_FORMAT 110 #define GOT_ERR_REBASE_REQUIRED 111 #define GOT_ERR_REGEX 112 +#define GOT_ERR_REF_NAME_MINUS 113 static const struct got_error { int code; @@ -258,6 +259,7 @@ static const struct got_error { { GOT_ERR_GIT_REPO_FORMAT,"unknown git repository format version" }, { GOT_ERR_REBASE_REQUIRED,"specified branch must be rebased first" }, { GOT_ERR_REGEX, "regular expression error" }, + { GOT_ERR_REF_NAME_MINUS, "reference name may not start with '-'" }, }; /*