Skip to content

Commit

Permalink
remote: die on config error when setting URL
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Patrick Steinhardt authored and Junio C Hamano committed Feb 22, 2016
1 parent 15b92fc commit 45ebdcc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 6 additions & 5 deletions builtin/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1579,11 +1579,12 @@ static int set_url(int argc, const char **argv)
/* Special cases that add new entry. */
if ((!oldurl && !delete_mode) || add_mode) {
if (add_mode)
git_config_set_multivar(name_buf.buf, newurl,
"^$", 0);
git_config_set_multivar_or_die(name_buf.buf, newurl,
"^$", 0);
else
git_config_set(name_buf.buf, newurl);
git_config_set_or_die(name_buf.buf, newurl);
strbuf_release(&name_buf);

return 0;
}

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

if (!delete_mode)
git_config_set_multivar(name_buf.buf, newurl, oldurl, 0);
git_config_set_multivar_or_die(name_buf.buf, newurl, oldurl, 0);
else
git_config_set_multivar(name_buf.buf, NULL, oldurl, 1);
git_config_set_multivar_or_die(name_buf.buf, NULL, oldurl, 1);
return 0;
}

Expand Down
9 changes: 9 additions & 0 deletions t/t5505-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,15 @@ test_expect_success 'get-url on new remote' '
echo foo | get_url_test --push --all someremote
'

test_expect_success 'remote set-url with locked config' '
test_when_finished "rm -f .git/config.lock" &&
git config --get-all remote.someremote.url >expect &&
>.git/config.lock &&
test_must_fail git remote set-url someremote baz &&
git config --get-all remote.someremote.url >actual &&
cmp expect actual
'

test_expect_success 'remote set-url bar' '
git remote set-url someremote bar &&
echo bar >expect &&
Expand Down

0 comments on commit 45ebdcc

Please sign in to comment.