Skip to contentSkip to conversation

Example of pull.mode

RFC PATCH New Felipe Contreras 1 participant 3 messages Feb 28, 2023 Documentation

lore
Share & tools
lore
#0 lore raw

cover Example of pull.mode

The discussions about the default mode of pull never end, since there's yet another discussion [1] about the relationship with pull.rebase=merges I'm sending a condensed version of my git update patches [2] which were not properly considered, but they solve the issue.

The two configurations in particular that are currently broken are:

git config pull.mode merge
git config pull.rebase merges
git pull --rebase # same as --rebase=merges

And:

git config pull.rebase true
git pull --no-ff # no mode specified

These patches are *not* meant to be merged, they are just meant as reference for the new discussion.

I have the patches properly split and with tests, which I avoided here for the sake of simplicity.

[1] https://lore.kernel.org/git/[email protected]/
[2] https://lore.kernel.org/git/[email protected]/

Felipe Contreras (2):
Add pull.mode
pull: improve --rebase and pull.rebase interaction

 Documentation/config/branch.txt |   5 +
 Documentation/config/pull.txt   |   6 ++
 Documentation/git-pull.txt      |  15 +--
 builtin/pull.c                  | 157 ++++++++++++++++++++++----------
 rebase.c                        |  12 +++
 rebase.h                        |  13 ++-
 t/t7601-merge-pull-config.sh    |  30 +++---
 7 files changed, 166 insertions(+), 72 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

RFC PATCH 1/2 Add pull.mode

The evolution of pull options has somewhat served most users, however, they have been found lacking for a very needed trio: merge / rebase / fast-forward-only.

To avoid some of the problems of git pull Linus Torvalds suggested a configuration pull.merge [1], however, instead of having pull.merge and pull.rebase, we can have pull.mode which works for both.

Many people have argued that git pull should have a per-branch configuration for its mode of operation (e.g. Linus Torvalds [1] and Theodore Ts'o [2]).

branch.<name>.pullMode achieves that.

Some discussions about pull.mode = fast-forward:

https://lore.kernel.org/git/[email protected]/
https://lore.kernel.org/git/[email protected]
https://lore.kernel.org/git/[email protected]
https://lore.kernel.org/git/[email protected]

This is a squash of the following patches:

* pull: reorganize mode conditionals
* pull: improve default warning
* pull: add pull.mode=fast-forward
* pull: add per-branch mode configuration
* pull: add pull.mode
* pull: introduce --merge option
* rebase: add REBASE_DEFAULT

[1] https://lore.kernel.org/git/CA+55aFz2Uvq4vmyjJPao5tS-uuVvKm6mbP7Uz8sdq1VMxMGJCw@mail.gmail.com/
[2] https://lore.kernel.org/git/[email protected]/

---
 Documentation/config/branch.txt |   5 ++
 Documentation/config/pull.txt   |   6 ++
 Documentation/git-pull.txt      |  15 ++--
 builtin/pull.c                  | 147 +++++++++++++++++++++-----------
 rebase.c                        |  12 +++
 rebase.h                        |  13 ++-
 t/t7601-merge-pull-config.sh    |  30 +++----
 7 files changed, 158 insertions(+), 70 deletions(-)
Documentation/config/branch.txt +5 -0
index 445341a906..035e7c1fe4 100644
@@ -96,6 +96,11 @@ mode.
 it unless you understand the implications (see linkgit:git-rebase[1]
 for details).
 
+branch.<name>.pullMode::
+	When `git pull` is run, this determines the mode of operation,
+	possible values are 'fast-forward', 'merge', and 'rebase'.
+	See `pull.mode` for doing this in a non branch-specific manner.
+
 branch.<name>.description::
 	Branch description, can be edited with
 	`git branch --edit-description`. Branch description is
Documentation/config/pull.txt +6 -0
index 9349e09261..596a9a504b 100644
@@ -25,6 +25,12 @@ mode.
 it unless you understand the implications (see linkgit:git-rebase[1]
 for details).
 
+pull.mode::
+	When "git pull" is run, this determines if it would either merge or
+	rebase the fetched branch. The possible values are 'merge',
+	'rebase', and 'fast-forward'. See "branch.<name>.pullMode" for setting
+	this on a per-branch basis.
+
 pull.octopus::
 	The default merge strategy to use when pulling multiple branches
 	at once.
Documentation/git-pull.txt +9 -6
index 0e14f8b5b2..e961439936 100644
@@ -17,10 +17,10 @@ DESCRIPTION
 
 Incorporates changes from a remote repository into the current branch.
 If the current branch is behind the remote, then by default it will
-fast-forward the current branch to match the remote.  If the current
-branch and the remote have diverged, the user needs to specify how to
-reconcile the divergent branches with `--rebase` or `--no-rebase` (or
-the corresponding configuration option in `pull.rebase`).
+fast-forward the current branch to match the remote.
+
+By default non-fast-forward merges fail, so you need to specify if you want to
+do a merge or a rebase.
 
 More precisely, `git pull` runs `git fetch` with the given parameters
 and then depending on configuration options or command line flags,
@@ -130,8 +130,11 @@ It rewrites history, which does not bode well when you
 published that history already.  Do *not* use this option
 unless you have read linkgit:git-rebase[1] carefully.
 
---no-rebase::
-	This is shorthand for --rebase=false.
+-m::
+--merge::
+	Force a merge.
++
+Previously this was --no-rebase, but that usage has been deprecated.
 
 Options related to fetching
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
builtin/pull.c +99 -48

257 lines not on this page · raw message

rebase.c +12 -0
index 6775cddb28..4b9a5e2066 100644
@@ -34,3 +34,15 @@ enum rebase_type rebase_parse_value(const char *value)
 
 	return REBASE_INVALID;
 }
+
+enum pull_mode_type pull_mode_parse_value(const char *value)
+{
+	if (!strcmp(value, "merge") || !strcmp(value, "m"))
+		return PULL_MODE_MERGE;
+	else if (!strcmp(value, "rebase") || !strcmp(value, "r"))
+		return PULL_MODE_REBASE;
+	else if (!strcmp(value, "fast-forward") || !strcmp(value, "f"))
+		return PULL_MODE_FAST_FORWARD;
+
+	return PULL_MODE_INVALID;
+}
rebase.h +12 -1
index 203b437282..bc2cd75f52 100644
@@ -3,7 +3,8 @@
 
 enum rebase_type {
 	REBASE_INVALID = -1,
-	REBASE_FALSE = 0,
+	REBASE_DEFAULT = 0,
+	REBASE_FALSE,
 	REBASE_TRUE,
 	REBASE_MERGES,
 	REBASE_INTERACTIVE
@@ -11,4 +12,14 @@ enum rebase_type {
 
 enum rebase_type rebase_parse_value(const char *value);
 
+enum pull_mode_type {
+	PULL_MODE_INVALID = -1,
+	PULL_MODE_DEFAULT = 0,
+	PULL_MODE_MERGE,
+	PULL_MODE_REBASE,
+	PULL_MODE_FAST_FORWARD
+};
+
+enum pull_mode_type pull_mode_parse_value(const char *value);
+
 #endif /* REBASE */
t/t7601-merge-pull-config.sh +15 -15
index bd238d89b0..d1e3ecb68c 100755
@@ -95,22 +95,22 @@ test_expect_success 'pull.rebase not set (not-fast-forward)' '
 test_expect_success 'pull.rebase not set and pull.ff=true (not-fast-forward)' '
 	git reset --hard c2 &&
 	test_config pull.ff true &&
-	git pull . c1 2>err &&
-	test_i18ngrep ! "You have divergent branches" err
+	test_must_fail git pull . c1 2>err &&
+	test_i18ngrep "You have divergent branches" err
 '
 
 test_expect_success 'pull.rebase not set and pull.ff=false (not-fast-forward)' '
 	git reset --hard c2 &&
 	test_config pull.ff false &&
-	git pull . c1 2>err &&
-	test_i18ngrep ! "You have divergent branches" err
+	test_must_fail git pull . c1 2>err &&
+	test_i18ngrep "You have divergent branches" err
 '
 
 test_expect_success 'pull.rebase not set and pull.ff=only (not-fast-forward)' '
 	git reset --hard c2 &&
 	test_config pull.ff only &&
 	test_must_fail git pull . c1 2>err &&
-	test_i18ngrep ! "You have divergent branches" err
+	test_i18ngrep "You have divergent branches" err
 '
 
 test_expect_success 'pull.rebase not set and --rebase given (not-fast-forward)' '
@@ -127,20 +127,20 @@ test_expect_success 'pull.rebase not set and --no-rebase given (not-fast-forward
 
 test_expect_success 'pull.rebase not set and --ff given (not-fast-forward)' '
 	git reset --hard c2 &&
-	git pull --ff . c1 2>err &&
-	test_i18ngrep ! "You have divergent branches" err
+	test_must_fail git pull --ff . c1 2>err &&
+	test_i18ngrep "You have divergent branches" err
 '
 
 test_expect_success 'pull.rebase not set and --no-ff given (not-fast-forward)' '
 	git reset --hard c2 &&
-	git pull --no-ff . c1 2>err &&
-	test_i18ngrep ! "You have divergent branches" err
+	test_must_fail git pull --no-ff . c1 2>err &&
+	test_i18ngrep "You have divergent branches" err
 '
 
 test_expect_success 'pull.rebase not set and --ff-only given (not-fast-forward)' '
 	git reset --hard c2 &&
 	test_must_fail git pull --ff-only . c1 2>err &&
-	test_i18ngrep ! "You have divergent branches" err
+	test_i18ngrep "You have divergent branches" err
 '
 
 test_does_rebase () {
@@ -210,11 +210,11 @@ test_attempts_fast_forward () {
 # (And related interaction of pull.ff=only with pull.rebase)
 #
 test_expect_success '--ff-only overrides --rebase' '
-	test_attempts_fast_forward pull --rebase --ff-only
+	test_does_fast_forward pull --rebase --ff-only
 '
 
 test_expect_success '--ff-only overrides --rebase even if first' '
-	test_attempts_fast_forward pull --ff-only --rebase
+	test_does_fast_forward pull --ff-only --rebase
 '
 
 test_expect_success '--ff-only overrides --no-rebase' '
@@ -222,7 +222,7 @@ test_expect_success '--ff-only overrides --no-rebase' '
 '
 
 test_expect_success 'pull.ff=only overrides pull.rebase=true' '
-	test_attempts_fast_forward -c pull.ff=only -c pull.rebase=true pull
+	test_does_fast_forward -c pull.ff=only -c pull.rebase=true pull
 '
 
 test_expect_success 'pull.ff=only overrides pull.rebase=false' '
@@ -253,7 +253,7 @@ test_expect_success 'pull.rebase=true overrides pull.ff=true' '
 
 # Group 3: command line flags take precedence over config
 test_expect_success '--ff-only takes precedence over pull.rebase=true' '
-	test_attempts_fast_forward -c pull.rebase=true pull --ff-only
+	test_does_fast_forward -c pull.rebase=true pull --ff-only
 '
 
 test_expect_success '--ff-only takes precedence over pull.rebase=false' '
@@ -261,7 +261,7 @@ test_expect_success '--ff-only takes precedence over pull.rebase=false' '
 '
 
 test_expect_success '--no-rebase takes precedence over pull.ff=only' '
-	test_falls_back_to_full_merge -c pull.ff=only pull --no-rebase
+	test_attempts_fast_forward -c pull.ff=only pull --no-rebase
 '
 
 test_expect_success '--rebase takes precedence over pull.ff=only' '
Signature · 1 line
2.39.2
#2 lore raw

RFC PATCH 2/2 pull: improve --rebase and pull.rebase interaction

In reply to Felipe Contreras

Currently --rebase without argument overrides pull.rebase:

  git config pull.rebase merges
  git pull --rebase

Up until now this hasn't been a big issue, since user has not been forced to specify a merge, or a rebase. But with the introduction of --merge and pull.mode, the user could in theory have the following configuration:

git config pull.mode merge
git config pull.rebase merges

In such case, the user would expect:

  git pull --rebase

To be the same as:

  git pull --rebase=merges

If the user wants to override the configuration, she can do:

  git pull --rebase=true
---
 builtin/pull.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
builtin/pull.c +8 -2
index 0531328e2f..3c9e7f0861 100644
@@ -68,8 +68,14 @@ static int parse_opt_rebase(const struct option *opt, const char *arg, int unset
 
 	if (arg)
 		*value = parse_config_rebase("--rebase", arg, 0);
-	else
-		*value = unset ? REBASE_FALSE : REBASE_TRUE;
+	else {
+		if (!unset) {
+			/* --rebase shouldn't override pull.rebase=merges (and others) */
+			if (*value < REBASE_TRUE)
+				*value = REBASE_TRUE;
+		} else
+			*value = REBASE_FALSE;
+	}
 
 	if (*value > 0)
 		mode = *value >= REBASE_TRUE ? PULL_MODE_REBASE : PULL_MODE_MERGE;
Signature · 1 line
2.39.2