Skip to content

Commit b81842c

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27852b2 commit b81842c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

builtin/branch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
791791
die(_("Branch '%s' has no upstream information"), branch->name);
792792

793793
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);
795795
strbuf_reset(&buf);
796796
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);
798798
strbuf_release(&buf);
799799
} else if (argc > 0 && argc <= 2) {
800800
struct branch *branch = branch_get(argv[0]);

t/t3200-branch.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,13 @@ test_expect_success '--unset-upstream should fail if given a non-existent branch
473473
test_must_fail git branch --unset-upstream i-dont-exist
474474
'
475475

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+
476483
test_expect_success 'test --unset-upstream on HEAD' '
477484
git branch my14 &&
478485
test_config branch.master.remote foo &&

0 commit comments

Comments
 (0)