From: Jeff King <peff@peff.net>
To: Jack Nagel <jacknagel@gmail.com>
Cc: Ramkumar Ramachandra <artagnon@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org
Subject: [PATCH] remote: handle pushremote config in any order order
Date: Mon, 24 Feb 2014 03:59:03 -0500 [thread overview]
Message-ID: <20140224085903.GA10698@sigill.intra.peff.net> (raw)
In-Reply-To: <CAMYxyaUwPXXdvGv786_p5n7-biMLOFbur-gQ1pxXOttc0R0=eg@mail.gmail.com>
On Mon, Feb 24, 2014 at 12:10:04AM -0500, Jack Nagel wrote:
> There seems to be a difference in the behavior of "git push" depending
> on whether remote.pushdefault is defined before or after
> branch.<name>.pushremote in .git/config.
> [...]
> I would expect the order that things are defined in the config file to
> have no effect on the behavior of "git push".
Yes, with a few exceptions, we usually try to make the ordering in the
config file irrelevant. This is a bug. The patch below should fix it.
-- >8 --
Subject: 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>
---
remote.c | 7 ++++++-
t/t5516-fetch-push.sh | 12 ++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/remote.c b/remote.c
index e41251e..7232a33 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(pushremote_name);
+ pushremote_name = branch_pushremote_name;
+ }
alias_all_urls();
}
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 926e7f6..1309c4d 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -536,6 +536,18 @@ test_expect_success 'push with config branch.*.pushremote' '
check_push_result down_repo $the_commit heads/master
'
+test_expect_success 'branch.*.pushremote config order is irrelevant' '
+ mk_test one_repo heads/master &&
+ mk_test two_repo heads/master &&
+ test_config remote.one.url one_repo &&
+ test_config remote.two.url two_repo &&
+ test_config branch.master.pushremote two_repo &&
+ test_config remote.pushdefault one_repo &&
+ git push &&
+ check_push_result one_repo $the_first_commit heads/master &&
+ check_push_result two_repo $the_commit heads/master
+'
+
test_expect_success 'push with dry-run' '
mk_test testrepo heads/master &&
--
1.8.5.2.500.g8060133
next prev parent reply other threads:[~2014-02-24 8:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-24 5:10 [BUG] remote.pushdefault and branch.<name>.pushremote definition order Jack Nagel
2014-02-24 8:59 ` Jeff King [this message]
2014-02-24 17:55 ` [PATCH] remote: handle pushremote config in any order order Junio C Hamano
2014-02-24 20:32 ` Junio C Hamano
2014-02-24 20:39 ` Jeff King
2014-02-24 20:53 ` Junio C Hamano
2014-02-24 22:45 ` Ramkumar Ramachandra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140224085903.GA10698@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacknagel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).