git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] branch: error code with --edit-description
@ 2022-10-25 22:57 Rubén Justo
  2022-10-25 23:43 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Rubén Justo @ 2022-10-25 22:57 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

Since c2d17ba3db0d (branch --edit-description: protect against mistyped
branch name, 2012-02-05) we return -1 on error editing the branch
description.

Let's change to 1, which follows the established convention and it is
better for portability reasons.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
---
 builtin/branch.c  | 2 +-
 t/t3200-branch.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index c964ac7bb4..15be0c03ef 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -809,7 +809,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 
 		strbuf_addf(&branch_ref, "refs/heads/%s", branch_name);
 		if (!ref_exists(branch_ref.buf))
-			ret = error((!argc || !strcmp(head, branch_name))
+			error((!argc || !strcmp(head, branch_name))
 			      ? _("No commit on branch '%s' yet.")
 			      : _("No branch named '%s'."),
 			      branch_name);
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 38c57de71b..7f605f865b 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -1394,7 +1394,7 @@ test_expect_success 'branch --delete --force removes dangling branch' '
 
 test_expect_success 'use --edit-description' '
 	EDITOR=: git branch --edit-description &&
-	test_must_fail git config branch.main.description &&
+	test_expect_code 1 git config branch.main.description &&
 
 	write_script editor <<-\EOF &&
 		echo "New contents" >"$1"
-- 
2.36.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] branch: error code with --edit-description
  2022-10-25 22:57 [PATCH] branch: error code with --edit-description Rubén Justo
@ 2022-10-25 23:43 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2022-10-25 23:43 UTC (permalink / raw)
  To: Rubén Justo; +Cc: Git List

Rubén Justo <rjusto@gmail.com> writes:

> Since c2d17ba3db0d (branch --edit-description: protect against mistyped
> branch name, 2012-02-05) we return -1 on error editing the branch
> description.
>
> Let's change to 1, which follows the established convention and it is
> better for portability reasons.

Nicely explained.  As ret is initialized to 1 to assume failure (and
we set it to 0 when we are happy), the change to stop assigning the
return value from error() is a very sensible implementation, too.

Will queue.  Thanks.

>
> Signed-off-by: Rubén Justo <rjusto@gmail.com>
> ---
>  builtin/branch.c  | 2 +-
>  t/t3200-branch.sh | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/branch.c b/builtin/branch.c
> index c964ac7bb4..15be0c03ef 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -809,7 +809,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
>  
>  		strbuf_addf(&branch_ref, "refs/heads/%s", branch_name);
>  		if (!ref_exists(branch_ref.buf))
> -			ret = error((!argc || !strcmp(head, branch_name))
> +			error((!argc || !strcmp(head, branch_name))
>  			      ? _("No commit on branch '%s' yet.")
>  			      : _("No branch named '%s'."),
>  			      branch_name);
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index 38c57de71b..7f605f865b 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -1394,7 +1394,7 @@ test_expect_success 'branch --delete --force removes dangling branch' '
>  
>  test_expect_success 'use --edit-description' '
>  	EDITOR=: git branch --edit-description &&
> -	test_must_fail git config branch.main.description &&
> +	test_expect_code 1 git config branch.main.description &&
>  
>  	write_script editor <<-\EOF &&
>  		echo "New contents" >"$1"

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-25 23:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25 22:57 [PATCH] branch: error code with --edit-description Rubén Justo
2022-10-25 23:43 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).