Skip to contentSkip to conversation

branch: error code with --edit-description

PATCH In review Rubén Justo 2 participants 2 messages Oct 25, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 branch: error code with --edit-description

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.

---
 builtin/branch.c  | 2 +-
 t/t3200-branch.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
builtin/branch.c +1 -1
index c964ac7bb4..15be0c03ef 100644
@@ -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);
t/t3200-branch.sh +1 -1
index 38c57de71b..7f605f865b 100755
@@ -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"
Signature · 1 line
2.36.1
#1 lore raw
Quoted 6 lines · Rubén Justo

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.

Quoted 33 lines
---
 builtin/branch.c  | 2 +-
 t/t3200-branch.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
builtin/branch.c +1 -1
index c964ac7bb4..15be0c03ef 100644
@@ -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);
t/t3200-branch.sh +1 -1
index 38c57de71b..7f605f865b 100755
@@ -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"