summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2014-02-24 03:59:03 -0500
committerLibravatar Junio C Hamano <gitster@pobox.com>2014-02-24 12:53:28 -0800
commit98b406f3ad6a6989a5b11c2a2582a9f539d66263 (patch)
treeea03420878d55379efbf4c3bb0a82ec1d43c4521 /remote.c
parentGit 1.8.5.5 (diff)
downloadtgif-98b406f3ad6a6989a5b11c2a2582a9f539d66263.tar.xz
remote: handle pushremote config in any order
The remote we push can be defined either by remote.pushdefault or by branch.*.pushremote for the current branch. The order in which they appear in the config file should not matter to precedence (which should be to prefer the branch-specific config). The current code parses the config linearly and uses a single string to store both values, overwriting any previous value. Thus, config like: [branch "master"] pushremote = foo [remote] pushdefault = bar erroneously ends up pushing to "bar" from the master branch. We can fix this by storing both values and resolving the correct value after all config is read. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/remote.c b/remote.c
index 9f1a8aa2c4..c0e95e2eb6 100644
--- a/remote.c
+++ b/remote.c
@@ -49,6 +49,7 @@ static int branches_nr;
static struct branch *current_branch;
static const char *default_remote_name;
+static const char *branch_pushremote_name;
static const char *pushremote_name;
static int explicit_default_remote_name;
@@ -352,7 +353,7 @@ static int handle_config(const char *key, const char *value, void *cb)
}
} else if (!strcmp(subkey, ".pushremote")) {
if (branch == current_branch)
- if (git_config_string(&pushremote_name, key, value))
+ if (git_config_string(&branch_pushremote_name, key, value))
return -1;
} else if (!strcmp(subkey, ".merge")) {
if (!value)
@@ -492,6 +493,10 @@ static void read_config(void)
make_branch(head_ref + strlen("refs/heads/"), 0);
}
git_config(handle_config, NULL);
+ if (branch_pushremote_name) {
+ free((char *)pushremote_name);
+ pushremote_name = branch_pushremote_name;
+ }
alias_all_urls();
}