remote: die on config error when manipulating remotes
When manipulating remotes we try to set various configuration values without checking if the values were persisted correctly, possibly leaving the remote in an inconsistent state. Fix this issue by dying early and notifying the user about the error. 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
c397debf3d046713ffd040f2c7da5e6921121ce8
1 file changed
+12
-27
builtin/remote.c
+12
-27
@@ -197,8 +197,7 @@ static int add(int argc, const char **argv)
197
die(_("'%s' is not a valid remote name"), name);
198
199
strbuf_addf(&buf, "remote.%s.url", name);
200
- if (git_config_set(buf.buf, url))
201
- return 1;
200
+ git_config_set_or_die(buf.buf, url);
201
202
if (!mirror || mirror & MIRROR_FETCH) {
203
strbuf_reset(&buf);
@@ -214,16 +213,14 @@ static int add(int argc, const char **argv)
213
if (mirror & MIRROR_PUSH) {
214
strbuf_reset(&buf);
215
strbuf_addf(&buf, "remote.%s.mirror", name);
217
- if (git_config_set(buf.buf, "true"))
218
- return 1;
216
+ git_config_set_or_die(buf.buf, "true");
217
}
218
219
if (fetch_tags != TAGS_DEFAULT) {
220
strbuf_reset(&buf);
221
strbuf_addf(&buf, "remote.%s.tagopt", name);
224
- if (git_config_set(buf.buf,
225
- fetch_tags == TAGS_SET ? "--tags" : "--no-tags"))
226
- return 1;
222
+ git_config_set_or_die(buf.buf,
223
+ fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
224
}
225
226
if (fetch && fetch_remote(name))
@@ -589,25 +586,20 @@ static int migrate_file(struct remote *remote)
586
587
strbuf_addf(&buf, "remote.%s.url", remote->name);
588
for (i = 0; i < remote->url_nr; i++)
592
- if (git_config_set_multivar(buf.buf, remote->url[i], "^$", 0))
593
- return error(_("Could not append '%s' to '%s'"),
594
- remote->url[i], buf.buf);
589
+ git_config_set_multivar_or_die(buf.buf, remote->url[i], "^$", 0);
590
strbuf_reset(&buf);
591
strbuf_addf(&buf, "remote.%s.push", remote->name);
592
for (i = 0; i < remote->push_refspec_nr; i++)
598
- if (git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0))
599
- return error(_("Could not append '%s' to '%s'"),
600
- remote->push_refspec[i], buf.buf);
593
+ git_config_set_multivar_or_die(buf.buf, remote->push_refspec[i], "^$", 0);
594
strbuf_reset(&buf);
595
strbuf_addf(&buf, "remote.%s.fetch", remote->name);
596
for (i = 0; i < remote->fetch_refspec_nr; i++)
604
- if (git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0))
605
- return error(_("Could not append '%s' to '%s'"),
606
- remote->fetch_refspec[i], buf.buf);
597
+ git_config_set_multivar_or_die(buf.buf, remote->fetch_refspec[i], "^$", 0);
598
if (remote->origin == REMOTE_REMOTES)
599
unlink_or_warn(git_path("remotes/%s", remote->name));
600
else if (remote->origin == REMOTE_BRANCHES)
601
unlink_or_warn(git_path("branches/%s", remote->name));
602
+
603
return 0;
604
}
605
@@ -654,8 +646,7 @@ static int mv(int argc, const char **argv)
646
647
strbuf_reset(&buf);
648
strbuf_addf(&buf, "remote.%s.fetch", rename.new);
657
- if (git_config_set_multivar(buf.buf, NULL, NULL, 1))
658
- return error(_("Could not remove config section '%s'"), buf.buf);
649
+ git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
650
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old);
651
for (i = 0; i < oldremote->fetch_refspec_nr; i++) {
652
char *ptr;
@@ -675,8 +666,7 @@ static int mv(int argc, const char **argv)
666
"\tPlease update the configuration manually if necessary."),
667
buf2.buf);
668
678
- if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
679
- return error(_("Could not append '%s'"), buf.buf);
669
+ git_config_set_multivar_or_die(buf.buf, buf2.buf, "^$", 0);
670
}
671
672
read_branches();
@@ -686,9 +676,7 @@ static int mv(int argc, const char **argv)
676
if (info->remote_name && !strcmp(info->remote_name, rename.old)) {
677
strbuf_reset(&buf);
678
strbuf_addf(&buf, "branch.%s.remote", item->string);
689
- if (git_config_set(buf.buf, rename.new)) {
690
- return error(_("Could not set '%s'"), buf.buf);
691
- }
679
+ git_config_set_or_die(buf.buf, rename.new);
680
}
681
}
682
@@ -786,10 +774,7 @@ static int rm(int argc, const char **argv)
774
strbuf_reset(&buf);
775
strbuf_addf(&buf, "branch.%s.%s",
776
item->string, *k);
789
- if (git_config_set(buf.buf, NULL)) {
790
- strbuf_release(&buf);
791
- return -1;
792
- }
777
+ git_config_set_or_die(buf.buf, NULL);
778
}
779
}
780
}