Re: [PATCH v4 2/3] builtin/branch: give more useful error messages when renaming

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kaartic Sivaraam <kaartic.sivaraam@xxxxxxxxx> writes:

> +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?



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux