From: Bert Wesarg <bert.wesarg@googlemail.com>
To: git@vger.kernel.org
Cc: Bert Wesarg <bert.wesarg@googlemail.com>,
Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
Matthew Rogers <mattr94@gmail.com>
Subject: [PATCH 7/7] remote rename: gently handle remote.pushDefault config
Date: Tue, 21 Jan 2020 10:24:55 +0100 [thread overview]
Message-ID: <d10d3049ce9824f6925dddeb12cc130627a8c478.1579598053.git.bert.wesarg@googlemail.com> (raw)
In-Reply-To: <cover.1579598053.git.bert.wesarg@googlemail.com>
When renaming a remote with
git remote rename X Y
Git already renames any branch.<name>.remote and branch.<name>.pushRemote
values from X to Y.
However remote.pushDefault needs a more gentle approach, as this may be
set in a non-repo configuration file. In such a case only a warning is
printed, such as:
warning: The global configuration remote.pushDefault in:
$HOME/.gitconfig:35
now names the non-existent remote 'origin'
It is changed to remote.pushDefault = Y when set in a repo configuration
though.
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
Matthew, you are in Cc because of your current work 'config: allow user to
know scope of config options'. I think I'm correct to assuming an ordering
of the enum config_scope.
Cc: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>
Cc: Matthew Rogers <mattr94@gmail.com>
---
builtin/remote.c | 43 ++++++++++++++++++++++++++++++++++++++++
t/t5505-remote.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 92 insertions(+), 1 deletion(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 0cb930fe00..52172e523a 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -611,6 +611,29 @@ static int migrate_file(struct remote *remote)
return 0;
}
+struct push_default_info
+{
+ struct rename_info *rename;
+ enum config_scope scope;
+ struct strbuf* origin;
+ int linenr;
+};
+
+static int config_read_push_default(const char *key, const char *value,
+ void *cb)
+{
+ struct push_default_info* info = cb;
+ if (strcmp(key, "remote.pushdefault") || strcmp(value, info->rename->old_name))
+ return 0;
+
+ info->scope = current_config_scope();
+ strbuf_reset(info->origin);
+ strbuf_addstr(info->origin, current_config_name());
+ info->linenr = current_config_line();
+
+ return 0;
+}
+
static int mv(int argc, const char **argv)
{
struct option options[] = {
@@ -746,6 +769,26 @@ static int mv(int argc, const char **argv)
die(_("creating '%s' failed"), buf.buf);
}
string_list_clear(&remote_branches, 1);
+
+ struct push_default_info push_default;
+ push_default.rename = &rename;
+ push_default.scope = CONFIG_SCOPE_UNKNOWN;
+ push_default.origin = &buf;
+ git_config(config_read_push_default, &push_default);
+ if (push_default.scope >= CONFIG_SCOPE_CMDLINE)
+ ; /* pass */
+ else if (push_default.scope >= CONFIG_SCOPE_REPO) {
+ git_config_set("remote.pushDefault", rename.new_name);
+ } else if (push_default.scope >= CONFIG_SCOPE_SYSTEM) {
+ /* warn */
+ warning(_("The %s configuration remote.pushDefault in:\n"
+ "\t%s:%d\n"
+ "now names the non-existent remote '%s'"),
+ config_scope_name(push_default.scope),
+ push_default.origin->buf, push_default.linenr,
+ rename.old_name);
+ }
+
return 0;
}
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 59a1681636..3b84c7bf9b 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -737,6 +737,7 @@ test_expect_success 'rename a remote' '
git clone one four &&
(
cd four &&
+ test_config_global remote.pushDefault origin &&
git config branch.master.pushRemote origin &&
git remote rename origin upstream &&
test -z "$(git for-each-ref refs/remotes/origin)" &&
@@ -744,7 +745,54 @@ test_expect_success 'rename a remote' '
test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
test "$(git config branch.master.remote)" = "upstream" &&
- test "$(git config branch.master.pushRemote)" = "upstream"
+ test "$(git config branch.master.pushRemote)" = "upstream" &&
+ test "$(git config --global remote.pushDefault)" = "origin"
+ )
+'
+
+test_expect_success 'rename a remote renames repo remote.pushDefault' '
+ git clone one four.1 &&
+ (
+ cd four.1 &&
+ git config remote.pushDefault origin &&
+ git remote rename origin upstream &&
+ test "$(git config remote.pushDefault)" = "upstream"
+ )
+'
+
+test_expect_success 'rename a remote keeps global remote.pushDefault' '
+ git clone one four.2 &&
+ (
+ cd four.2 &&
+ test_config_global remote.pushDefault origin &&
+ git config remote.pushDefault other &&
+ git remote rename origin upstream &&
+ test "$(git config --global remote.pushDefault)" = "origin" &&
+ test "$(git config remote.pushDefault)" = "other"
+ )
+'
+
+test_expect_success 'rename a remote renames repo remote.pushDefault but ignores global' '
+ git clone one four.3 &&
+ (
+ cd four.3 &&
+ test_config_global remote.pushDefault other &&
+ git config remote.pushDefault origin &&
+ git remote rename origin upstream &&
+ test "$(git config --global remote.pushDefault)" = "other" &&
+ test "$(git config remote.pushDefault)" = "upstream"
+ )
+'
+
+test_expect_success 'rename a remote renames repo remote.pushDefault but keeps global' '
+ git clone one four.4 &&
+ (
+ cd four.4 &&
+ test_config_global remote.pushDefault origin &&
+ git config remote.pushDefault origin &&
+ git remote rename origin upstream &&
+ test "$(git config --global remote.pushDefault)" = "origin" &&
+ test "$(git config remote.pushDefault)" = "upstream"
)
'
--
2.24.1.497.g9abd7b20b4.dirty
next prev parent reply other threads:[~2020-01-21 9:25 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-16 21:25 [PATCH] remote: rename also remotes in the branch.<name>.pushRemote config Bert Wesarg
2020-01-16 23:14 ` Junio C Hamano
2020-01-17 9:33 ` [PATCH v2] remote rename: rename branch.<name>.pushRemote config values too Bert Wesarg
2020-01-17 11:50 ` Johannes Schindelin
2020-01-17 12:37 ` Bert Wesarg
2020-01-17 13:30 ` Johannes Schindelin
2020-01-17 14:40 ` Bert Wesarg
2020-01-20 11:25 ` Johannes Schindelin
2020-01-20 13:14 ` Bert Wesarg
2020-01-20 13:51 ` Johannes Schindelin
2020-01-17 18:48 ` Junio C Hamano
2020-01-17 20:20 ` Bert Wesarg
2020-01-17 21:24 ` Junio C Hamano
2020-01-21 9:24 ` [PATCH 0/7] remote rename: improve handling of configuration values Bert Wesarg
2020-01-21 9:24 ` [PATCH 1/7] pull --rebase/remote rename: document and honor single-letter abbreviations rebase types Bert Wesarg
2020-01-21 23:26 ` Junio C Hamano
2020-01-22 7:34 ` Bert Wesarg
2020-01-22 19:43 ` Junio C Hamano
2020-01-21 9:24 ` [PATCH 2/7] remote: clean-up by returning early to avoid one indentation Bert Wesarg
2020-01-23 23:02 ` Junio C Hamano
2020-01-21 9:24 ` [PATCH 3/7] remote: clean-up config callback Bert Wesarg
2020-01-21 9:24 ` [PATCH v3 4/7] remote rename: rename branch.<name>.pushRemote config values too Bert Wesarg
2020-01-21 9:24 ` [PATCH 5/7] [RFC] config: make `scope_name` global as `config_scope_name` Bert Wesarg
2020-01-22 0:12 ` Matt Rogers
2020-01-22 7:37 ` Bert Wesarg
2020-01-23 1:30 ` Matt Rogers
2020-01-21 9:24 ` [PATCH 6/7] config: provide access to the current line number Bert Wesarg
2020-01-21 9:24 ` Bert Wesarg [this message]
2020-01-23 23:03 ` [PATCH 7/7] remote rename: gently handle remote.pushDefault config Junio C Hamano
2020-01-24 8:49 ` Bert Wesarg
2020-01-22 15:26 ` [PATCH 0/7] remote rename: improve handling of configuration values Bert Wesarg
2020-01-17 9:49 ` [PATCH] remote: rename also remotes in the branch.<name>.pushRemote config Johannes Schindelin
2020-01-17 9:45 ` Johannes Schindelin
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=d10d3049ce9824f6925dddeb12cc130627a8c478.1579598053.git.bert.wesarg@googlemail.com \
--to=bert.wesarg@googlemail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
--cc=mattr94@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).