Skip to content

Commit 45ebdcc

Browse files
pks-tgitster
authored andcommitted
remote: die on config error when setting URL
When invoking `git-remote --set-url` we do not check the return value when writing the actual new URL to the configuration file, pretending to the user that the configuration has been set while it was in fact not persisted. Fix this problem by dying early when setting the config fails. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 15b92fc commit 45ebdcc

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

builtin/remote.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,11 +1579,12 @@ static int set_url(int argc, const char **argv)
15791579
/* Special cases that add new entry. */
15801580
if ((!oldurl && !delete_mode) || add_mode) {
15811581
if (add_mode)
1582-
git_config_set_multivar(name_buf.buf, newurl,
1583-
"^$", 0);
1582+
git_config_set_multivar_or_die(name_buf.buf, newurl,
1583+
"^$", 0);
15841584
else
1585-
git_config_set(name_buf.buf, newurl);
1585+
git_config_set_or_die(name_buf.buf, newurl);
15861586
strbuf_release(&name_buf);
1587+
15871588
return 0;
15881589
}
15891590

@@ -1604,9 +1605,9 @@ static int set_url(int argc, const char **argv)
16041605
regfree(&old_regex);
16051606

16061607
if (!delete_mode)
1607-
git_config_set_multivar(name_buf.buf, newurl, oldurl, 0);
1608+
git_config_set_multivar_or_die(name_buf.buf, newurl, oldurl, 0);
16081609
else
1609-
git_config_set_multivar(name_buf.buf, NULL, oldurl, 1);
1610+
git_config_set_multivar_or_die(name_buf.buf, NULL, oldurl, 1);
16101611
return 0;
16111612
}
16121613

t/t5505-remote.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,15 @@ test_expect_success 'get-url on new remote' '
932932
echo foo | get_url_test --push --all someremote
933933
'
934934

935+
test_expect_success 'remote set-url with locked config' '
936+
test_when_finished "rm -f .git/config.lock" &&
937+
git config --get-all remote.someremote.url >expect &&
938+
>.git/config.lock &&
939+
test_must_fail git remote set-url someremote baz &&
940+
git config --get-all remote.someremote.url >actual &&
941+
cmp expect actual
942+
'
943+
935944
test_expect_success 'remote set-url bar' '
936945
git remote set-url someremote bar &&
937946
echo bar >expect &&

0 commit comments

Comments
 (0)