From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: Alex Henrie <alexhenrie24@gmail.com>, Jeff King <peff@peff.net>,
Junio C Hamano <gitster@pobox.com>,
Elijah Newren <newren@gmail.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
John Keeping <john@keeping.me.uk>,
Richard Hansen <rhansen@rhansen.org>,
Philip Oakley <philipoakley@iee.email>,
"Brian M. Carlson" <sandals@crustytoothpaste.net>,
"W. Trevor King" <wking@tremily.us>,
Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH v8 10/10] pull: improve default warning
Date: Tue, 24 Nov 2020 21:29:38 -0600 [thread overview]
Message-ID: <20201125032938.786393-11-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com>
Also, use pull.mode to determine when to show it, and --ff/--no-ff
shouldn't squelch the warning.
Also, improve the documentation so "git pull --help" actually does
explain what's going on.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
Documentation/git-pull.txt | 17 +++++++++++++++
builtin/pull.c | 34 +++++++++++++++---------------
t/t5520-pull.sh | 14 +++++++++++++
t/t7601-merge-pull-config.sh | 40 +++++++-----------------------------
4 files changed, 55 insertions(+), 50 deletions(-)
diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt
index 5c3fb67c01..ad33d2472c 100644
--- a/Documentation/git-pull.txt
+++ b/Documentation/git-pull.txt
@@ -38,6 +38,20 @@ as set by linkgit:git-branch[1] `--track`.
Assume the following history exists and the current branch is
"`master`":
+------------
+ A---B---C master on origin
+ /
+ D---E master
+------------
+
+Then `git pull` will merge in a fast-foward way up to the new master.
+
+------------
+ D---E---A---B---C master, origin/master
+------------
+
+However, a non-fast-foward case looks very different.
+
------------
A---B---C master on origin
/
@@ -46,6 +60,9 @@ Assume the following history exists and the current branch is
origin/master in your repository
------------
+By default `git pull` will warn about these situations, however, most likely
+you would want to force a merge, which you can do with `git pull --no-rebase`.
+
Then "`git pull`" will fetch and replay the changes from the remote
`master` branch since it diverged from the local `master` (i.e., `E`)
until its current commit (`C`) on top of `master` and record the
diff --git a/builtin/pull.c b/builtin/pull.c
index 3aa7f56142..8e577b6322 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -1060,25 +1060,25 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]);
- if (!opt_rebase && !can_ff && opt_verbosity >= 0 && !opt_ff) {
- warning(_("Pulling without specifying how to reconcile divergent branches is\n"
- "discouraged. You can squelch this message by running one of the following\n"
- "commands sometime before your next pull:\n"
- "\n"
- " git config pull.mode merge # (the default strategy)\n"
- " git config pull.mode rebase\n"
- " git config pull.mode ff-only # fast-forward only\n"
- "\n"
- "You can replace \"git config\" with \"git config --global\" to set a default\n"
- "preference for all repositories. You can also pass --rebase, --no-rebase,\n"
- "or --ff-only on the command line to override the configured default per\n"
- "invocation.\n"));
+ if (!can_ff) {
+ if (mode == PULL_MODE_FF_ONLY)
+ die(_("The pull was not fast-forward, please either merge or rebase.\n"
+ "If unsure, run 'git pull --no-rebase'."));
+ else if (!mode && opt_verbosity >= 0) {
+ warning(_("The pull was not fast-forward, in the future you will have to choose a merge, or a rebase.\n"
+ "To squelch this message and maintain the current behavior, use:\n"
+ "\n"
+ " git config --global pull.mode merge\n"
+ "\n"
+ "To squelch this message and adopt the new behavior now, use:\n"
+ "\n"
+ " git config --global push.mode ff-only\n"
+ "\n"
+ "Falling back to old style for now (merge).\n"
+ "Read 'git pull --help' for more information."));
+ }
}
- if (mode == PULL_MODE_FF_ONLY && !can_ff)
- die(_("The pull was not fast-forward, please either merge or rebase.\n"
- "If unsure, run 'git pull --no-rebase'."));
-
if (opt_rebase >= REBASE_TRUE) {
int ret = 0;
if ((recurse_submodules == RECURSE_SUBMODULES_ON ||
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index ba78c16d73..29d44d000e 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -897,4 +897,18 @@ test_expect_success 'git pull non-fast-forward with merge (ff-only)' '
git pull --no-rebase
'
+test_expect_success 'git pull non-fast-forward (default)' '
+ test_when_finished "git checkout master && git branch -D other test" &&
+ git checkout -b other master^ &&
+ >new &&
+ git add new &&
+ git commit -m new &&
+ git checkout -b test -t other &&
+ git reset --hard master &&
+ git pull 2> error &&
+ cat error &&
+ grep -q "The pull was not fast-forward" error &&
+ grep -q "in the future you will have to choose" error
+'
+
test_done
diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh
index 4a36ad30e2..8a93b37d87 100755
--- a/t/t7601-merge-pull-config.sh
+++ b/t/t7601-merge-pull-config.sh
@@ -30,71 +30,45 @@ test_expect_success 'setup' '
test_expect_success 'pull.rebase not set' '
git reset --hard c2 &&
git pull . c1 2>err &&
- test_i18ngrep "Pulling without specifying how to reconcile" err
+ test_i18ngrep "choose a merge, or a rebase" err
'
test_expect_success 'pull.rebase not set (fast-forward)' '
git reset --hard c0 &&
git pull . c1 2>err &&
- test_i18ngrep ! "Pulling without specifying how to reconcile" err
+ test_i18ngrep ! "choose a merge, or a rebase" err
'
test_expect_success 'pull.mode set' '
git reset --hard c2 &&
test_config pull.mode merge &&
git pull . c1 2>err &&
- test_i18ngrep ! "Pulling without specifying how to reconcile" err
-'
-
-test_expect_success 'pull.rebase not set and pull.ff=true' '
- git reset --hard c2 &&
- test_config pull.ff true &&
- git pull . c1 2>err &&
- test_i18ngrep ! "Pulling without specifying how to reconcile" err
-'
-
-test_expect_success 'pull.rebase not set and pull.ff=false' '
- git reset --hard c2 &&
- test_config pull.ff false &&
- git pull . c1 2>err &&
- test_i18ngrep ! "Pulling without specifying how to reconcile" err
+ test_i18ngrep ! "choose a merge, or a rebase" err
'
test_expect_success 'pull.rebase not set and pull.ff=only' '
git reset --hard c2 &&
test_config pull.ff only &&
test_must_fail git pull . c1 2>err &&
- test_i18ngrep ! "Pulling without specifying how to reconcile" err
+ test_i18ngrep ! "choose a merge, or a rebase" err
'
test_expect_success 'pull.rebase not set and --rebase given' '
git reset --hard c2 &&
git pull --rebase . c1 2>err &&
- test_i18ngrep ! "Pulling without specifying how to reconcile" err
+ test_i18ngrep ! "choose a merge, or a rebase" err
'
test_expect_success 'pull.rebase not set and --no-rebase given' '
git reset --hard c2 &&
git pull --no-rebase . c1 2>err &&
- test_i18ngrep ! "Pulling without specifying how to reconcile" err
-'
-
-test_expect_success 'pull.rebase not set and --ff given' '
- git reset --hard c2 &&
- git pull --ff . c1 2>err &&
- test_i18ngrep ! "Pulling without specifying how to reconcile" err
-'
-
-test_expect_success 'pull.rebase not set and --no-ff given' '
- git reset --hard c2 &&
- git pull --no-ff . c1 2>err &&
- test_i18ngrep ! "Pulling without specifying how to reconcile" err
+ test_i18ngrep ! "choose a merge, or a rebase" err
'
test_expect_success 'pull.rebase not set and --ff-only given' '
git reset --hard c2 &&
test_must_fail git pull --ff-only . c1 2>err &&
- test_i18ngrep ! "Pulling without specifying how to reconcile" err
+ test_i18ngrep ! "choose a merge, or a rebase" err
'
test_expect_success 'merge c1 with c2' '
--
2.29.2
prev parent reply other threads:[~2020-11-25 3:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-25 3:29 [PATCH v8 00/10] Reject non-ff pulls by default Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 01/10] pull: refactor fast-forward check Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 02/10] pull: cleanup autostash check Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 03/10] pull: trivial cleanup Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 04/10] pull: move default warning Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 05/10] pull: display default warning only when non-ff Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 06/10] test: pull-options: revert unnecessary changes Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 07/10] rebase: add REBASE_DEFAULT Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 08/10] pull: add pull.mode Felipe Contreras
2020-11-25 12:31 ` Philip Oakley
2020-12-02 5:04 ` Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 09/10] pull: add pull.mode=ff-only Felipe Contreras
2020-11-25 3:29 ` Felipe Contreras [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201125032938.786393-11-felipe.contreras@gmail.com \
--to=felipe.contreras@gmail.com \
--cc=alexhenrie24@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
--cc=john@keeping.me.uk \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=philipoakley@iee.email \
--cc=rhansen@rhansen.org \
--cc=sandals@crustytoothpaste.net \
--cc=wking@tremily.us \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).