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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Feb 22, 2016 at 12:23 UTC
45ebdcc99a8d8e7c671eb1db1212d90f5f2db341
2 files changed
+15
-5
builtin/remote.c
+6
-5
@@ -1579,11 +1579,12 @@ static int set_url(int argc, const char **argv)
1579
/* Special cases that add new entry. */
1580
if ((!oldurl && !delete_mode) || add_mode) {
1581
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);
1584
else
1585
- git_config_set(name_buf.buf, newurl);
1585
+ git_config_set_or_die(name_buf.buf, newurl);
1586
strbuf_release(&name_buf);
1587
+
1588
return 0;
1589
}
1590
@@ -1604,9 +1605,9 @@ static int set_url(int argc, const char **argv)
1605
regfree(&old_regex);
1606
1607
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);
1609
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);
1611
return 0;
1612
}
1613
t/t5505-remote.sh
+9
@@ -932,6 +932,15 @@ test_expect_success 'get-url on new remote' '
932
echo foo | get_url_test --push --all someremote
933
'
934
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
+
944
test_expect_success 'remote set-url bar' '
945
git remote set-url someremote bar &&
946
echo bar >expect &&