branch: die on config error when unsetting upstream

When we try to unset upstream configurations we do not check return codes for the `git_config_set` functions. As those may indicate that we were unable to unset the respective configuration we may exit successfully without any error message while in fact the upstream configuration was not unset. Fix this by dying with an error message when we cannot unset the configuration. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Feb 22, 2016 at 12:23 UTC b81842cbbba21a400c9c7a78c5b358565936254a
2 files changed +9 -2
builtin/branch.c
+2 -2
@@ -791,10 +791,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
791 die(_("Branch '%s' has no upstream information"), branch->name);
792
793 strbuf_addf(&buf, "branch.%s.remote", branch->name);
794 - git_config_set_multivar(buf.buf, NULL, NULL, 1);
794 + git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
795 strbuf_reset(&buf);
796 strbuf_addf(&buf, "branch.%s.merge", branch->name);
797 - git_config_set_multivar(buf.buf, NULL, NULL, 1);
797 + git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
798 strbuf_release(&buf);
799 } else if (argc > 0 && argc <= 2) {
800 struct branch *branch = branch_get(argv[0]);
t/t3200-branch.sh
+7
@@ -473,6 +473,13 @@ test_expect_success '--unset-upstream should fail if given a non-existent branch
473 test_must_fail git branch --unset-upstream i-dont-exist
474 '
475
476 +test_expect_success '--unset-upstream should fail if config is locked' '
477 + test_when_finished "rm -f .git/config.lock" &&
478 + git branch --set-upstream-to locked &&
479 + >.git/config.lock &&
480 + test_must_fail git branch --unset-upstream
481 +'
482 +
483 test_expect_success 'test --unset-upstream on HEAD' '
484 git branch my14 &&
485 test_config branch.master.remote foo &&