remote: die on config error when setting/adding branches
When we add or set new branches (e.g. by `git remote add -f` or `git remote set-branches`) we do not check for error codes when writing the branches to the configuration file. When persisting the configuration failed we are left with a remote that has none or not all of the branches that should have been set without notifying the user. Fix this issue by dying early on configuration 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
ab5e4b67e14cbd09e74d3b19c0553a3716205c45
1 file changed
+9
-17
builtin/remote.c
+9
-17
@@ -108,8 +108,8 @@ enum {
108
#define MIRROR_PUSH 2
109
#define MIRROR_BOTH (MIRROR_FETCH|MIRROR_PUSH)
110
111
-static int add_branch(const char *key, const char *branchname,
112
- const char *remotename, int mirror, struct strbuf *tmp)
111
+static void add_branch(const char *key, const char *branchname,
112
+ const char *remotename, int mirror, struct strbuf *tmp)
113
{
114
strbuf_reset(tmp);
115
strbuf_addch(tmp, '+');
@@ -119,7 +119,7 @@ static int add_branch(const char *key, const char *branchname,
119
else
120
strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s",
121
branchname, remotename, branchname);
122
- return git_config_set_multivar(key, tmp->buf, "^$", 0);
122
+ git_config_set_multivar_or_die(key, tmp->buf, "^$", 0);
123
}
124
125
static const char mirror_advice[] =
@@ -206,9 +206,8 @@ static int add(int argc, const char **argv)
206
if (track.nr == 0)
207
string_list_append(&track, "*");
208
for (i = 0; i < track.nr; i++) {
209
- if (add_branch(buf.buf, track.items[i].string,
210
- name, mirror, &buf2))
211
- return 1;
209
+ add_branch(buf.buf, track.items[i].string,
210
+ name, mirror, &buf2);
211
}
212
}
213
@@ -1412,21 +1411,17 @@ static int remove_all_fetch_refspecs(const char *remote, const char *key)
1411
return git_config_set_multivar(key, NULL, NULL, 1);
1412
}
1413
1415
-static int add_branches(struct remote *remote, const char **branches,
1416
- const char *key)
1414
+static void add_branches(struct remote *remote, const char **branches,
1415
+ const char *key)
1416
{
1417
const char *remotename = remote->name;
1418
int mirror = remote->mirror;
1419
struct strbuf refspec = STRBUF_INIT;
1420
1421
for (; *branches; branches++)
1423
- if (add_branch(key, *branches, remotename, mirror, &refspec)) {
1424
- strbuf_release(&refspec);
1425
- return 1;
1426
- }
1422
+ add_branch(key, *branches, remotename, mirror, &refspec);
1423
1424
strbuf_release(&refspec);
1429
- return 0;
1425
}
1426
1427
static int set_remote_branches(const char *remotename, const char **branches,
@@ -1445,10 +1440,7 @@ static int set_remote_branches(const char *remotename, const char **branches,
1440
strbuf_release(&key);
1441
return 1;
1442
}
1448
- if (add_branches(remote, branches, key.buf)) {
1449
- strbuf_release(&key);
1450
- return 1;
1451
- }
1443
+ add_branches(remote, branches, key.buf);
1444
1445
strbuf_release(&key);
1446
return 0;