Skip to content

Commit ab5e4b6

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 45ebdcc commit ab5e4b6

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

builtin/remote.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ enum {
108108
#define MIRROR_PUSH 2
109109
#define MIRROR_BOTH (MIRROR_FETCH|MIRROR_PUSH)
110110

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)
113113
{
114114
strbuf_reset(tmp);
115115
strbuf_addch(tmp, '+');
@@ -119,7 +119,7 @@ static int add_branch(const char *key, const char *branchname,
119119
else
120120
strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s",
121121
branchname, remotename, branchname);
122-
return git_config_set_multivar(key, tmp->buf, "^$", 0);
122+
git_config_set_multivar_or_die(key, tmp->buf, "^$", 0);
123123
}
124124

125125
static const char mirror_advice[] =
@@ -206,9 +206,8 @@ static int add(int argc, const char **argv)
206206
if (track.nr == 0)
207207
string_list_append(&track, "*");
208208
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);
212211
}
213212
}
214213

@@ -1412,21 +1411,17 @@ static int remove_all_fetch_refspecs(const char *remote, const char *key)
14121411
return git_config_set_multivar(key, NULL, NULL, 1);
14131412
}
14141413

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)
14171416
{
14181417
const char *remotename = remote->name;
14191418
int mirror = remote->mirror;
14201419
struct strbuf refspec = STRBUF_INIT;
14211420

14221421
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);
14271423

14281424
strbuf_release(&refspec);
1429-
return 0;
14301425
}
14311426

14321427
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,
14451440
strbuf_release(&key);
14461441
return 1;
14471442
}
1448-
if (add_branches(remote, branches, key.buf)) {
1449-
strbuf_release(&key);
1450-
return 1;
1451-
}
1443+
add_branches(remote, branches, key.buf);
14521444

14531445
strbuf_release(&key);
14541446
return 0;

0 commit comments

Comments
 (0)