[PATCH] branch: error codes for "edit_description"

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

 



Stick to the convention of exit with 1 on error.  May break some
third party tool that expects -1 on "No branch named 'bla'" or
"No commit on branch 'bla' yet." errors.

Test added to avoid regresion on this behaviour.
---

Junio, here is the patch for the change you suggested [1].  My concern is
this might break some third party tool or script.  If no one thinks this
is an issue, I can squash it with the patch I'm responding to.


[1] https://lore.kernel.org/git/xmqq7d2fszhk.fsf@gitster.g/

 builtin/branch.c  | 6 +++---
 t/t3200-branch.sh | 8 ++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index b1f6519cd9..01b6364f58 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -810,11 +810,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			else
 				ret = error(_("No branch named '%s'."),
 					     branch_name);
-		} else if (edit_branch_description(branch_name))
-			ret = 1;
+		} else
+			ret = edit_branch_description(branch_name);
 
 		strbuf_release(&branch_ref);
-		return ret;
+		return -ret;
 	} else if (copy) {
 		if (!argc)
 			die(_("branch name required"));
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 9723c2827c..d09db3fe3d 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -1409,6 +1409,14 @@ test_expect_success 'refuse --edit-description on unborn branch for now' '
 	test_must_fail env EDITOR=./editor git branch --edit-description
 '
 
+test_expect_success 'test error codes using --edit-description' '
+	test_expect_code 1 env EDITOR=./invalid-editor git branch --edit-description main &&
+	write_script editor <<-\EOF &&
+		echo "New contents" >"$1"
+	EOF
+	test_expect_code 1 env EDITOR=./editor git branch --edit-description no-such-branch
+'
+
 test_expect_success '--merged catches invalid object names' '
 	test_must_fail git branch --merged 0000000000000000000000000000000000000000
 '
-- 
2.36.1



[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