summaryrefslogtreecommitdiff
path: root/builtin/remote.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-02-22 11:23:29 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-02-22 18:23:53 (GMT)
commitab5e4b67e14cbd09e74d3b19c0553a3716205c45 (patch)
tree19e413bdcc99240fc2ddf4e76742770cd3c79101 /builtin/remote.c
parent45ebdcc99a8d8e7c671eb1db1212d90f5f2db341 (diff)
downloadgit-ab5e4b67e14cbd09e74d3b19c0553a3716205c45.zip
git-ab5e4b67e14cbd09e74d3b19c0553a3716205c45.tar.gz
git-ab5e4b67e14cbd09e74d3b19c0553a3716205c45.tar.bz2
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>
Diffstat (limited to 'builtin/remote.c')
-rw-r--r--builtin/remote.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/builtin/remote.c b/builtin/remote.c
index 0771e42..6a7244e 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -108,8 +108,8 @@ enum {
#define MIRROR_PUSH 2
#define MIRROR_BOTH (MIRROR_FETCH|MIRROR_PUSH)
-static int add_branch(const char *key, const char *branchname,
- const char *remotename, int mirror, struct strbuf *tmp)
+static void add_branch(const char *key, const char *branchname,
+ const char *remotename, int mirror, struct strbuf *tmp)
{
strbuf_reset(tmp);
strbuf_addch(tmp, '+');
@@ -119,7 +119,7 @@ static int add_branch(const char *key, const char *branchname,
else
strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s",
branchname, remotename, branchname);
- return git_config_set_multivar(key, tmp->buf, "^$", 0);
+ git_config_set_multivar_or_die(key, tmp->buf, "^$", 0);
}
static const char mirror_advice[] =
@@ -206,9 +206,8 @@ static int add(int argc, const char **argv)
if (track.nr == 0)
string_list_append(&track, "*");
for (i = 0; i < track.nr; i++) {
- if (add_branch(buf.buf, track.items[i].string,
- name, mirror, &buf2))
- return 1;
+ add_branch(buf.buf, track.items[i].string,
+ name, mirror, &buf2);
}
}
@@ -1412,21 +1411,17 @@ static int remove_all_fetch_refspecs(const char *remote, const char *key)
return git_config_set_multivar(key, NULL, NULL, 1);
}
-static int add_branches(struct remote *remote, const char **branches,
- const char *key)
+static void add_branches(struct remote *remote, const char **branches,
+ const char *key)
{
const char *remotename = remote->name;
int mirror = remote->mirror;
struct strbuf refspec = STRBUF_INIT;
for (; *branches; branches++)
- if (add_branch(key, *branches, remotename, mirror, &refspec)) {
- strbuf_release(&refspec);
- return 1;
- }
+ add_branch(key, *branches, remotename, mirror, &refspec);
strbuf_release(&refspec);
- return 0;
}
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,
strbuf_release(&key);
return 1;
}
- if (add_branches(remote, branches, key.buf)) {
- strbuf_release(&key);
- return 1;
- }
+ add_branches(remote, branches, key.buf);
strbuf_release(&key);
return 0;