git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Henrie <alexhenrie24@gmail.com>
To: git@vger.kernel.org, gitster@pobox.com,
	felipe.contreras@gmail.com, newren@gmail.com
Cc: Alex Henrie <alexhenrie24@gmail.com>
Subject: [PATCH] pull: abort by default if fast-forwarding is impossible
Date: Sat, 26 Jun 2021 18:08:55 -0600	[thread overview]
Message-ID: <20210627000855.530985-1-alexhenrie24@gmail.com> (raw)

The behavior of warning but merging anyway is difficult to explain to
users because it sends mixed signals. End the confusion by firmly
requiring the user to specify whether they want a merge or a rebase.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 Documentation/git-pull.txt | 14 +++++++++-----
 builtin/pull.c             | 32 +++++++++++++++-----------------
 2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt
index 5c3fb67c01..0fb185811e 100644
--- a/Documentation/git-pull.txt
+++ b/Documentation/git-pull.txt
@@ -16,13 +16,17 @@ DESCRIPTION
 -----------
 
 Incorporates changes from a remote repository into the current
-branch.  In its default mode, `git pull` is shorthand for
-`git fetch` followed by `git merge FETCH_HEAD`.
+branch.  `git pull` is shorthand for `git fetch` followed by
+`git merge FETCH_HEAD` or `git rebase FETCH_HEAD`.
 
 More precisely, 'git pull' runs 'git fetch' with the given
-parameters and calls 'git merge' to merge the retrieved branch
-heads into the current branch.
-With `--rebase`, it runs 'git rebase' instead of 'git merge'.
+parameters and then, by default, attempts to fast-forward the
+current branch to the remote branch head.  If fast-forwarding
+is not possible because the local and remote branches have
+diverged, the `--rebase` option causes 'git rebase' to be
+called to rebase the local branch upon the remote branch, and
+the `--no-rebase` option causes 'git merge' to be called to
+merge the retrieved branch heads into the current branch.
 
 <repository> should be the name of a remote repository as
 passed to linkgit:git-fetch[1].  <refspec> can name an
diff --git a/builtin/pull.c b/builtin/pull.c
index e8927fc2ff..21eaebc463 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -925,20 +925,20 @@ static int get_can_ff(struct object_id *orig_head, struct object_id *orig_merge_
 	return ret;
 }
 
-static void show_advice_pull_non_ff(void)
+static void die_pull_non_ff(void)
 {
-	advise(_("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.rebase false  # merge (the default strategy)\n"
-		 "  git config pull.rebase true   # rebase\n"
-		 "  git config pull.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"));
+	die(_("Pulling without specifying how to reconcile divergent branches is not\n"
+	      "possible. You can squelch this message by running one of the following\n"
+	      "commands sometime before your next pull:\n"
+	      "\n"
+	      "  git config pull.rebase false  # merge\n"
+	      "  git config pull.rebase true   # rebase\n"
+	      "  git config pull.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"));
 }
 
 int cmd_pull(int argc, const char **argv, const char *prefix)
@@ -1047,10 +1047,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 
 	can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]);
 
-	if (rebase_unspecified && !opt_ff && !can_ff) {
-		if (opt_verbosity >= 0)
-			show_advice_pull_non_ff();
-	}
+	if (rebase_unspecified && !opt_ff && !can_ff)
+		die_pull_non_ff();
 
 	if (opt_rebase) {
 		int ret = 0;
-- 
2.32.0.95.g4a22da5c5a


             reply	other threads:[~2021-06-27  0:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-27  0:08 Alex Henrie [this message]
2021-06-27  1:34 ` Elijah Newren
2021-06-27  4:16   ` Felipe Contreras
2021-06-27  7:49     ` Elijah Newren
2021-06-27 16:46       ` Felipe Contreras
2021-06-27 19:54         ` Alex Henrie
2021-06-27 21:29           ` Felipe Contreras
2021-06-28 10:31             ` Ævar Arnfjörð Bjarmason
2021-06-28 17:39               ` Felipe Contreras
2021-06-27  4:12 ` Felipe Contreras

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=20210627000855.530985-1-alexhenrie24@gmail.com \
    --to=alexhenrie24@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=newren@gmail.com \
    --subject='Re: [PATCH] pull: abort by default if fast-forwarding is impossible' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox