threads / patch / 33338

patchbranch: give better message when no names specified for rename

Subject: [PATCH] branch: give better message when no names specified for rename

## tl;dr

4 messages between Mar 31, 2013 and Apr 1, 2013. Diffs are folded; open one to read it.

replies: 3people: 3as markdown or json

Jonathon Mah· Mar 31, 2013, 01:27 UTC · lore
Signed-off-by: Jonathon Mah <me@JonathonMah.com>
---
The previous message was incorrect when not enough arguments were
specified:
    
    $ git branch -m 
    fatal: too many branches for a rename operation
I changed to "branch name required" instead of "new branch name required" in the hope that existing translations can be used.
 builtin/branch.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Show changes to builtin/branch.c +3 −1
diff --git a/builtin/branch.c b/builtin/branch.c
index 00d17d2..580107f 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -880,7 +880,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		if (edit_branch_description(branch_name))
 			return 1;
 	} else if (rename) {
-		if (argc == 1)
+		if (!argc)
+			die(_("branch name required"));
+		else if (argc == 1)
 			rename_branch(head, argv[0], rename > 1);
 		else if (argc == 2)
 			rename_branch(argv[0], argv[1], rename > 1);
-- 
1.8.2.279.g631bc94
Duy Nguyen· Mar 31, 2013, 01:35 UTC · re: Jonathon Mah · lore

Re: [PATCH] branch: give better message when no names specified for rename

On Sun, Mar 31, 2013 at 8:27 AM, Jonathon Mah <me@jonathonmah.com> wrote:
Show 7 quoted lines
> -               if (argc == 1)
> +               if (!argc)
> +                       die(_("branch name required"));
> +               else if (argc == 1)
>                         rename_branch(head, argv[0], rename > 1);
>                 else if (argc == 2)
>                         rename_branch(argv[0], argv[1], rename > 1);

This makes four branches based on argc. Maybe we should convert if/else chain to switch/case. -- Duy

Junio C Hamano· Apr 1, 2013, 02:51 UTC · re: Jonathon Mah · lore

Re: [PATCH] branch: give better message when no names specified for rename

Jonathon Mah <me@JonathonMah.com> writes:
Show 29 quoted lines
> Signed-off-by: Jonathon Mah <me@JonathonMah.com>
> ---
>
> The previous message was incorrect when not enough arguments were
> specified:
>     
>     $ git branch -m 
>     fatal: too many branches for a rename operation
>
> I changed to "branch name required" instead of "new branch name required" in the hope that existing translations can be used.
>
>  builtin/branch.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/branch.c b/builtin/branch.c
> index 00d17d2..580107f 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -880,7 +880,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
>  		if (edit_branch_description(branch_name))
>  			return 1;
>  	} else if (rename) {
> -		if (argc == 1)
> +		if (!argc)
> +			die(_("branch name required"));
> +		else if (argc == 1)
>  			rename_branch(head, argv[0], rename > 1);
>  		else if (argc == 2)
>  			rename_branch(argv[0], argv[1], rename > 1);
Obviously a good thing to do; thanks.
Junio C Hamano· Apr 1, 2013, 03:06 UTC · re: Junio C Hamano · lore

Re: [PATCH] branch: give better message when no names specified for rename

Junio C Hamano <gitster@pobox.com> writes:
Show 33 quoted lines
> Jonathon Mah <me@JonathonMah.com> writes:
>
>> Signed-off-by: Jonathon Mah <me@JonathonMah.com>
>> ---
>>
>> The previous message was incorrect when not enough arguments were
>> specified:
>>     
>>     $ git branch -m 
>>     fatal: too many branches for a rename operation
>>
>> I changed to "branch name required" instead of "new branch name required" in the hope that existing translations can be used.
>>
>>  builtin/branch.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/builtin/branch.c b/builtin/branch.c
>> index 00d17d2..580107f 100644
>> --- a/builtin/branch.c
>> +++ b/builtin/branch.c
>> @@ -880,7 +880,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
>>  		if (edit_branch_description(branch_name))
>>  			return 1;
>>  	} else if (rename) {
>> -		if (argc == 1)
>> +		if (!argc)
>> +			die(_("branch name required"));
>> +		else if (argc == 1)
>>  			rename_branch(head, argv[0], rename > 1);
>>  		else if (argc == 2)
>>  			rename_branch(argv[0], argv[1], rename > 1);
>
> Obviously a good thing to do; thanks.

Next time, please run the testsuite before sending a patch. I've fixed t3200 locally when queuing this patch, so no need to resend this one.

Thanks.

← back to recent threads