Re: [PATCH v4 2/3] builtin/branch: give more useful error messages when renaming
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 15, 2018, 20:33 UTC
- Message-ID
- <xmqqlget3wqa.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20180310155416.21802-3-kaartic.sivaraam@gmail.com>
Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:
Show 52 quoted lines
> +static void get_error_msg(struct strbuf* error_msg,
> + const char* oldname, enum old_branch_validation_result old_branch_name_res,
> + const char* newname, enum branch_validation_result new_branch_name_res)
> +{
> + const char* connector_string = "; ";
> + unsigned append_connector = 0;
> +
> + switch (old_branch_name_res) {
> + case VALIDATION_1_FATAL_INVALID_OLD_BRANCH_NAME:
> + strbuf_addf(error_msg,
> + _("old branch name '%s' is invalid"), oldname);
> + append_connector = 1;
> + break;
> + case VALIDATION_1_FATAL_OLD_BRANCH_DOESNT_EXIST:
> + strbuf_addf(error_msg,
> + _("branch '%s' doesn't exist"), oldname);
> + append_connector = 1;
> + break;
> +
> + /* not necessary to handle nonfatal cases */
> + case VALIDATION_1_PASS_OLD_BRANCH_EXISTS:
> + case VALIDATION_1_WARN_BAD_OLD_BRANCH_NAME:
> + break;
> + }
> +
> + switch (new_branch_name_res) {
> + case VALIDATION_FATAL_BRANCH_EXISTS_NO_FORCE:
> + strbuf_addf(error_msg, "%s",
> + (append_connector) ? connector_string : "");
> + strbuf_addf(error_msg,
> + _("branch '%s' already exists"), newname);
> + break;
> + case VALIDATION_FATAL_CANNOT_FORCE_UPDATE_CURRENT_BRANCH:
> + strbuf_addf(error_msg, "%s",
> + (append_connector) ? connector_string : "");
> + strbuf_addstr(error_msg,
> + _("cannot force update the current branch"));
> + break;
> + case VALIDATION_FATAL_INVALID_BRANCH_NAME:
> + strbuf_addf(error_msg, "%s",
> + (append_connector) ? connector_string : "");
> + strbuf_addf(error_msg,
> + _("new branch name '%s' is invalid"), newname);
> + break;
> +
> + /* not necessary to handle nonfatal cases */
> + case VALIDATION_PASS_BRANCH_DOESNT_EXIST:
> + case VALIDATION_PASS_BRANCH_EXISTS:
> + case VALIDATION_WARN_BRANCH_EXISTS:
> + break;
> + }
> +}Quite honestly, I am not sure if this amount of new code that results in sentence lego is really worth it. Is it so wrong for "branch -m tset master" to complain that master already exists so no branch can be renamed to it?