branch: die on config error when unsetting upstream
authorPatrick Steinhardt <ps@pks.im>
Mon, 22 Feb 2016 11:23:24 +0000 (12:23 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Feb 2016 18:23:45 +0000 (10:23 -0800)
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>
builtin/branch.c
t/t3200-branch.sh
index 3f6c825db1caf9c7cdd2ca7c1280e5ad157f9a27..09782876b8326c1c0509db9a116026959bfe4409 100644 (file)
@@ -791,10 +791,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                        die(_("Branch '%s' has no upstream information"), branch->name);
 
                strbuf_addf(&buf, "branch.%s.remote", branch->name);
-               git_config_set_multivar(buf.buf, NULL, NULL, 1);
+               git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
                strbuf_reset(&buf);
                strbuf_addf(&buf, "branch.%s.merge", branch->name);
-               git_config_set_multivar(buf.buf, NULL, NULL, 1);
+               git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
                strbuf_release(&buf);
        } else if (argc > 0 && argc <= 2) {
                struct branch *branch = branch_get(argv[0]);
index dd776b35592f8350d75b50e0f8c7843fd4324ee8..a897248490650ebef1a33a60a1aa9cf4431f06ff 100755 (executable)
@@ -473,6 +473,13 @@ test_expect_success '--unset-upstream should fail if given a non-existent branch
        test_must_fail git branch --unset-upstream i-dont-exist
 '
 
+test_expect_success '--unset-upstream should fail if config is locked' '
+       test_when_finished "rm -f .git/config.lock" &&
+       git branch --set-upstream-to locked &&
+       >.git/config.lock &&
+       test_must_fail git branch --unset-upstream
+'
+
 test_expect_success 'test --unset-upstream on HEAD' '
        git branch my14 &&
        test_config branch.master.remote foo &&