Skip to content

Commit

Permalink
clone: die on config error in cmd_clone
Browse files Browse the repository at this point in the history
The clone command does not check for error codes returned by
`git_config_set` functions. This may cause the user to end up
with an inconsistent repository without any indication with what
went wrong.

Fix this problem by dying with an error message when we are
unable to write the configuration files to disk.

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 c397deb commit 2ee35c4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,12 @@ static void write_refspec_config(const char *src_ref_prefix,
/* Configure the remote */
if (value.len) {
strbuf_addf(&key, "remote.%s.fetch", option_origin);
git_config_set_multivar(key.buf, value.buf, "^$", 0);
git_config_set_multivar_or_die(key.buf, value.buf, "^$", 0);
strbuf_reset(&key);

if (option_mirror) {
strbuf_addf(&key, "remote.%s.mirror", option_origin);
git_config_set(key.buf, "true");
git_config_set_or_die(key.buf, "true");
strbuf_reset(&key);
}
}
Expand Down Expand Up @@ -946,14 +946,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
src_ref_prefix = "refs/";
strbuf_addstr(&branch_top, src_ref_prefix);

git_config_set("core.bare", "true");
git_config_set_or_die("core.bare", "true");
} else {
strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
}

strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
strbuf_addf(&key, "remote.%s.url", option_origin);
git_config_set(key.buf, repo);
git_config_set_or_die(key.buf, repo);
strbuf_reset(&key);

if (option_reference.nr)
Expand Down

0 comments on commit 2ee35c4

Please sign in to comment.