Skip to contentSkip to conversation

rebase: support non-interactive autosquash

PATCH Superseded Andy Koppe 3 participants 32 messages Nov 3, 2023 – Nov 16, 2023 Documentation

lore
Share & tools
lore

Andy Koppe

author
#0 lore raw

PATCH 1/2 rebase: support non-interactive autosquash

So far, the rebase --autosquash option and rebase.autoSquash=true config setting are quietly ignored when used without --interactive, except that they prevent fast-forward and that they trigger conflicts with --apply and relatives, which is less than helpful particularly for the config setting.

Since the "merge" backend used for interactive rebase also is the default for non-interactive rebase, there does not appear to be a reason not to do --autosquash without --interactive, so support that.

Turn rebase.autoSquash into a multi-choice setting, with "interactive" enabling autosquashing for --interactive, and "always" enabling it without --interactive as well. Make boolean true values synonyms for "interactive" for backward compatibility.

Don't prevent fast-forwards or report conflicts with --apply options for rebase.autoSquash=interactive mode when rebase is invoked without --interactive.

Change the git-rebase and config/rebase documentation accordingly, and extend t3415-rebase-autosquash.sh to test the new rebase.autosquash values and combinations with and without --interactive.

---
 Documentation/config/rebase.txt        |  4 +-
 Documentation/git-rebase.txt           |  2 +-
 builtin/rebase.c                       | 45 +++++++++++------
 t/t3415-rebase-autosquash.sh           | 70 ++++++++++++++++++++------
 t/t3422-rebase-incompatible-options.sh |  2 +-
 5 files changed, 92 insertions(+), 31 deletions(-)
Documentation/config/rebase.txt +3 -1
index 9c248accec..7e5ec74e00 100644
@@ -9,7 +9,9 @@ rebase.stat::
 	rebase. False by default.
 
 rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
+	When set to 'interactive' or 'true', enable the `--autosquash` option
+	for interactive rebase. When set to 'always', enable it for
+	non-interactive rebase as well. Defaults to 'false'.
 
 rebase.autoStash::
 	When set to true, automatically create a temporary stash entry
Documentation/git-rebase.txt +1 -1
index e7b39ad244..102ff91493 100644
@@ -592,7 +592,7 @@ See also INCOMPATIBLE OPTIONS below.
 	When the commit log message begins with "squash! ..." or "fixup! ..."
 	or "amend! ...", and there is already a commit in the todo list that
 	matches the same `...`, automatically modify the todo list of
-	`rebase -i`, so that the commit marked for squashing comes right after
+	`rebase`, so that the commit marked for squashing comes right after
 	the commit to be modified, and change the action of the moved commit
 	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
 	matches the `...` if the commit subject matches, or if the `...` refers
builtin/rebase.c +31 -14

102 lines not on this page · raw message

t/t3415-rebase-autosquash.sh +56 -14

100 lines not on this page · raw message

t/t3422-rebase-incompatible-options.sh +1 -1
index 2eba00bdf5..d9feb3a89d 100755
@@ -102,7 +102,7 @@ test_rebase_am_only () {
 
 	test_expect_success "$opt incompatible with rebase.autosquash" "
 		git checkout B^0 &&
-		test_must_fail git -c rebase.autosquash=true rebase $opt A 2>err &&
+		test_must_fail git -c rebase.autosquash=always rebase $opt A 2>err &&
 		grep -e --no-autosquash err
 	"
 
Signature · 1 line
2.43.0-rc0
author
#1 lore raw

PATCH 2/2 docs: rewrite rebase --(no-)autosquash description

Rewrite the description of the rebase --(no-)autosquash options to try to make it a bit clearer. Don't use "the '...'" to refer to part of a commit message, mention how --interactive can be used to review the todo list, and add a bit more detail on commit --squash/amend.

---
 Documentation/git-rebase.txt | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +18 -14
index 102ff91493..594158fcbc 100644
@@ -589,21 +589,25 @@ See also INCOMPATIBLE OPTIONS below.
 
 --autosquash::
 --no-autosquash::
-	When the commit log message begins with "squash! ..." or "fixup! ..."
-	or "amend! ...", and there is already a commit in the todo list that
-	matches the same `...`, automatically modify the todo list of
-	`rebase`, so that the commit marked for squashing comes right after
-	the commit to be modified, and change the action of the moved commit
-	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
-	matches the `...` if the commit subject matches, or if the `...` refers
-	to the commit's hash. As a fall-back, partial matches of the commit
-	subject work, too. The recommended way to create fixup/amend/squash
-	commits is by using the `--fixup`, `--fixup=amend:` or `--fixup=reword:`
-	and `--squash` options respectively of linkgit:git-commit[1].
+	Automatically squash commits with specially formatted messages into
+	previous commits.  If a commit message starts with "squash! ",
+	"fixup! " or "amend! ", the remainder of the subject line is taken
+	as a commit specifier, which matches a previous commit if it matches
+	the start of the subject line or the hash of that commit.
 +
-If the `--autosquash` option is enabled by default using the
-configuration variable `rebase.autoSquash`, this option can be
-used to override and disable this setting.
+In the rebase todo list, commits marked for squashing are moved right after
+the commits they modify, and their action is changed from `pick` to `squash`,
+`fixup` or `fixup -C`, depending on the squash marker.  The `--interactive`
+option can be used to review and edit the todo list before proceeding.
++
+The recommended way to create commits with squash markers is by using the
+`--squash`, `--fixup`, `--fixup=amend:` or `--fixup=reword:` options of
+linkgit:git-commit[1], which take the target commit as an argument and
+automatically fill in the subject line of the new commit from that.
++
+The configuration variable `rebase.autoSquash` can be used to enable
+`--autosquash` by default.  See the CONFIGURATION section below for details.
+The `--no-autosquash` option overrides that setting.
 +
 See also INCOMPATIBLE OPTIONS below.
 
Signature · 1 line
2.43.0-rc0
#2 lore raw
In reply to Andy Koppe

Documentation/config/rebase.txt rebase.stat:: · line 14

Quoted 5 lines · Andy Koppe

rebase.autoSquash::

Documentation/config/rebase.txt +3 -1
-	If set to true enable `--autosquash` option by default.
+	When set to 'interactive' or 'true', enable the `--autosquash` option
+	for interactive rebase. When set to 'always', enable it for
+	non-interactive rebase as well. Defaults to 'false'.

I think a better and more extensible way to coax the new feature into the configuration system is to arrange it more like so:

false - synonym for "".
true - synonym for "interactive".
anything else - comman separated list of rebase methods, e.g.,
"interactive,noninteractive"

possible rebase method names might include other stuff like "apply" or "merge", but I haven't thought it through, so take this part with a grain of salt.

That way, the Boolean versions can be considered historical spelling of a more general system where you can exactly tell when autosquash takes place. When we add to a new variant on top of 'interactive' and 'non-interactive' variants the current rebase has, we do not know if it makes sense to allow it to also handle autosquash without knowing how that new variant's behavior appears to the end user, so 'always' that blindly enables autosquash for any unforseen future variants of 'rebase' is probably not what you want.

author
#3 lore raw
Quoted 21 lines · Junio C Hamano

Documentation/config/rebase.txt rebase.stat:: · line 14

Quoted 5 lines · Andy Koppe

rebase.autoSquash::

Documentation/config/rebase.txt +3 -1
-	If set to true enable `--autosquash` option by default.
+	When set to 'interactive' or 'true', enable the `--autosquash` option
+	for interactive rebase. When set to 'always', enable it for
+	non-interactive rebase as well. Defaults to 'false'.

I think a better and more extensible way to coax the new feature into the configuration system is to arrange it more like so:

false - synonym for "".
true - synonym for "interactive".
anything else - comman separated list of rebase methods, e.g.,
"interactive,noninteractive"

possible rebase method names might include other stuff like "apply" or "merge", but I haven't thought it through, so take this part with a grain of salt.

Quoted 8 lines

That way, the Boolean versions can be considered historical spelling of a more general system where you can exactly tell when autosquash takes place. When we add to a new variant on top of 'interactive' and 'non-interactive' variants the current rebase has, we do not know if it makes sense to allow it to also handle autosquash without knowing how that new variant's behavior appears to the end user, so 'always' that blindly enables autosquash for any unforseen future variants of 'rebase' is probably not what you want.

Thanks, done in v2.

Andy

author
#4 lore raw

PATCH v2 1/2 rebase: support non-interactive autosquash

In reply to Andy Koppe

So far, the rebase --autosquash option and rebase.autoSquash=true config setting are quietly ignored when used without --interactive, except that they prevent fast-forward and that they trigger conflicts with --apply and relatives, which is less than helpful particularly for the config setting.

Since the "merge" backend used for interactive rebase also is the default for non-interactive rebase, there doesn't appear to be a reason not to do --autosquash without --interactive, so support that.

Turn rebase.autoSquash into a comma-separated list of flags, with "interactive" or "i" enabling auto-squashing with --interactive, and "no-interactive" or "no-i" enabling it without. Make boolean true mean "interactive" for backward compatibility.

Don't prevent fast-forwards or report conflicts with --apply options when auto-squashing is not active.

Change the git-rebase and config/rebase documentation accordingly, and extend t3415-rebase-autosquash.sh to test the new rebase.autosquash values and combinations with and without --interactive.

---
 Documentation/config/rebase.txt        | 11 +++-
 Documentation/git-rebase.txt           |  2 +-
 builtin/rebase.c                       | 63 ++++++++++++++-----
 t/t3415-rebase-autosquash.sh           | 83 +++++++++++++++++++++-----
 t/t3422-rebase-incompatible-options.sh |  2 +-
 5 files changed, 129 insertions(+), 32 deletions(-)
Documentation/config/rebase.txt +10 -1
index 9c248accec..68191e5673 100644
@@ -9,7 +9,16 @@ rebase.stat::
 	rebase. False by default.
 
 rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
+	A comma-separated list of flags for when to enable auto-squashing.
+	Specifying `interactive` or `i` enables auto-squashing for rebasing with
+	`--interactive`, whereas `no-interactive` or `no-i` enables it for
+	rebasing without that option. For example, setting this to `i,no-i`
+	enables auto-squashing for both types. Setting it to true is equivalent
+	to setting it to `interactive`.
+
+	The `--autosquash` and `--no-autosquash` options of
+	linkgit:git-rebase[1] override the setting here.
+	Auto-squashing is disabled by default.
 
 rebase.autoStash::
 	When set to true, automatically create a temporary stash entry
Documentation/git-rebase.txt +1 -1
index e7b39ad244..102ff91493 100644
@@ -592,7 +592,7 @@ See also INCOMPATIBLE OPTIONS below.
 	When the commit log message begins with "squash! ..." or "fixup! ..."
 	or "amend! ...", and there is already a commit in the todo list that
 	matches the same `...`, automatically modify the todo list of
-	`rebase -i`, so that the commit marked for squashing comes right after
+	`rebase`, so that the commit marked for squashing comes right after
 	the commit to be modified, and change the action of the moved commit
 	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
 	matches the `...` if the commit subject matches, or if the `...` refers
builtin/rebase.c +48 -15

120 lines not on this page · raw message

t/t3415-rebase-autosquash.sh +69 -14

113 lines not on this page · raw message

t/t3422-rebase-incompatible-options.sh +1 -1
index 2eba00bdf5..e5119e7371 100755
@@ -102,7 +102,7 @@ test_rebase_am_only () {
 
 	test_expect_success "$opt incompatible with rebase.autosquash" "
 		git checkout B^0 &&
-		test_must_fail git -c rebase.autosquash=true rebase $opt A 2>err &&
+		test_must_fail git -c rebase.autosquash=no-i rebase $opt A 2>err &&
 		grep -e --no-autosquash err
 	"
 
Signature · 1 line
2.43.0-rc0
author
#5 lore raw

PATCH v2 2/2 docs: rewrite rebase --(no-)autosquash description

Rewrite the description of the rebase --(no-)autosquash options to try to make it a bit clearer. Don't use "the '...'" to refer to part of a commit message, mention how --interactive can be used to review the todo list, and add a bit more detail on commit --squash/amend.

---
 Documentation/git-rebase.txt | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +18 -14
index 102ff91493..594158fcbc 100644
@@ -589,21 +589,25 @@ See also INCOMPATIBLE OPTIONS below.
 
 --autosquash::
 --no-autosquash::
-	When the commit log message begins with "squash! ..." or "fixup! ..."
-	or "amend! ...", and there is already a commit in the todo list that
-	matches the same `...`, automatically modify the todo list of
-	`rebase`, so that the commit marked for squashing comes right after
-	the commit to be modified, and change the action of the moved commit
-	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
-	matches the `...` if the commit subject matches, or if the `...` refers
-	to the commit's hash. As a fall-back, partial matches of the commit
-	subject work, too. The recommended way to create fixup/amend/squash
-	commits is by using the `--fixup`, `--fixup=amend:` or `--fixup=reword:`
-	and `--squash` options respectively of linkgit:git-commit[1].
+	Automatically squash commits with specially formatted messages into
+	previous commits.  If a commit message starts with "squash! ",
+	"fixup! " or "amend! ", the remainder of the subject line is taken
+	as a commit specifier, which matches a previous commit if it matches
+	the start of the subject line or the hash of that commit.
 +
-If the `--autosquash` option is enabled by default using the
-configuration variable `rebase.autoSquash`, this option can be
-used to override and disable this setting.
+In the rebase todo list, commits marked for squashing are moved right after
+the commits they modify, and their action is changed from `pick` to `squash`,
+`fixup` or `fixup -C`, depending on the squash marker.  The `--interactive`
+option can be used to review and edit the todo list before proceeding.
++
+The recommended way to create commits with squash markers is by using the
+`--squash`, `--fixup`, `--fixup=amend:` or `--fixup=reword:` options of
+linkgit:git-commit[1], which take the target commit as an argument and
+automatically fill in the subject line of the new commit from that.
++
+The configuration variable `rebase.autoSquash` can be used to enable
+`--autosquash` by default.  See the CONFIGURATION section below for details.
+The `--no-autosquash` option overrides that setting.
 +
 See also INCOMPATIBLE OPTIONS below.
 
Signature · 1 line
2.43.0-rc0
author
#6 lore raw

PATCH v3 1/2 rebase: support non-interactive autosquash

In reply to Andy Koppe

So far, the rebase --autosquash option and rebase.autoSquash=true config setting are quietly ignored when used without --interactive, except that they prevent fast-forward and that they trigger conflicts with --apply and relatives, which is less than helpful particularly for the config setting.

Since the "merge" backend used for interactive rebase also is the default for non-interactive rebase, there doesn't appear to be a reason not to do --autosquash without --interactive, so support that.

Turn rebase.autoSquash into a comma-separated list of flags, with "interactive" or "i" enabling auto-squashing with --interactive, and "no-interactive" or "no-i" enabling it without. Make boolean true mean "interactive" for backward compatibility.

Don't prevent fast-forwards or report conflicts with --apply options when auto-squashing is not active.

Change the git-rebase and config/rebase documentation accordingly, and extend t3415-rebase-autosquash.sh to test the new rebase.autosquash values and combinations with and without --interactive.

---
 Documentation/config/rebase.txt        | 11 +++-
 Documentation/git-rebase.txt           |  2 +-
 builtin/rebase.c                       | 66 +++++++++++++++-----
 t/t3415-rebase-autosquash.sh           | 83 +++++++++++++++++++++-----
 t/t3422-rebase-incompatible-options.sh |  2 +-
 5 files changed, 132 insertions(+), 32 deletions(-)
Documentation/config/rebase.txt +10 -1
index 9c248accec..68191e5673 100644
@@ -9,7 +9,16 @@ rebase.stat::
 	rebase. False by default.
 
 rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
+	A comma-separated list of flags for when to enable auto-squashing.
+	Specifying `interactive` or `i` enables auto-squashing for rebasing with
+	`--interactive`, whereas `no-interactive` or `no-i` enables it for
+	rebasing without that option. For example, setting this to `i,no-i`
+	enables auto-squashing for both types. Setting it to true is equivalent
+	to setting it to `interactive`.
+
+	The `--autosquash` and `--no-autosquash` options of
+	linkgit:git-rebase[1] override the setting here.
+	Auto-squashing is disabled by default.
 
 rebase.autoStash::
 	When set to true, automatically create a temporary stash entry
Documentation/git-rebase.txt +1 -1
index e7b39ad244..102ff91493 100644
@@ -592,7 +592,7 @@ See also INCOMPATIBLE OPTIONS below.
 	When the commit log message begins with "squash! ..." or "fixup! ..."
 	or "amend! ...", and there is already a commit in the todo list that
 	matches the same `...`, automatically modify the todo list of
-	`rebase -i`, so that the commit marked for squashing comes right after
+	`rebase`, so that the commit marked for squashing comes right after
 	the commit to be modified, and change the action of the moved commit
 	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
 	matches the `...` if the commit subject matches, or if the `...` refers
builtin/rebase.c +51 -15

123 lines not on this page · raw message

t/t3415-rebase-autosquash.sh +69 -14

113 lines not on this page · raw message

t/t3422-rebase-incompatible-options.sh +1 -1
index 2eba00bdf5..e5119e7371 100755
@@ -102,7 +102,7 @@ test_rebase_am_only () {
 
 	test_expect_success "$opt incompatible with rebase.autosquash" "
 		git checkout B^0 &&
-		test_must_fail git -c rebase.autosquash=true rebase $opt A 2>err &&
+		test_must_fail git -c rebase.autosquash=no-i rebase $opt A 2>err &&
 		grep -e --no-autosquash err
 	"
 
Signature · 1 line
2.43.0-rc0
author
#7 lore raw

PATCH v3 2/2 docs: rewrite rebase --(no-)autosquash description

Rewrite the description of the rebase --(no-)autosquash options to try to make it a bit clearer. Don't use "the '...'" to refer to part of a commit message, mention how --interactive can be used to review the todo list, and add a bit more detail on commit --squash/amend.

---
 Documentation/git-rebase.txt | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +18 -14
index 102ff91493..594158fcbc 100644
@@ -589,21 +589,25 @@ See also INCOMPATIBLE OPTIONS below.
 
 --autosquash::
 --no-autosquash::
-	When the commit log message begins with "squash! ..." or "fixup! ..."
-	or "amend! ...", and there is already a commit in the todo list that
-	matches the same `...`, automatically modify the todo list of
-	`rebase`, so that the commit marked for squashing comes right after
-	the commit to be modified, and change the action of the moved commit
-	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
-	matches the `...` if the commit subject matches, or if the `...` refers
-	to the commit's hash. As a fall-back, partial matches of the commit
-	subject work, too. The recommended way to create fixup/amend/squash
-	commits is by using the `--fixup`, `--fixup=amend:` or `--fixup=reword:`
-	and `--squash` options respectively of linkgit:git-commit[1].
+	Automatically squash commits with specially formatted messages into
+	previous commits.  If a commit message starts with "squash! ",
+	"fixup! " or "amend! ", the remainder of the subject line is taken
+	as a commit specifier, which matches a previous commit if it matches
+	the start of the subject line or the hash of that commit.
 +
-If the `--autosquash` option is enabled by default using the
-configuration variable `rebase.autoSquash`, this option can be
-used to override and disable this setting.
+In the rebase todo list, commits marked for squashing are moved right after
+the commits they modify, and their action is changed from `pick` to `squash`,
+`fixup` or `fixup -C`, depending on the squash marker.  The `--interactive`
+option can be used to review and edit the todo list before proceeding.
++
+The recommended way to create commits with squash markers is by using the
+`--squash`, `--fixup`, `--fixup=amend:` or `--fixup=reword:` options of
+linkgit:git-commit[1], which take the target commit as an argument and
+automatically fill in the subject line of the new commit from that.
++
+The configuration variable `rebase.autoSquash` can be used to enable
+`--autosquash` by default.  See the CONFIGURATION section below for details.
+The `--no-autosquash` option overrides that setting.
 +
 See also INCOMPATIBLE OPTIONS below.
 
Signature · 1 line
2.43.0-rc0
#8 lore raw

Re: [PATCH v3 2/2] docs: rewrite rebase --(no-)autosquash description

Hi Andy

Quoted 3 lines · Andy Koppe

Rewrite the description of the rebase --(no-)autosquash options to try to make it a bit clearer. Don't use "the '...'" to refer to part of a commit message,

Thanks for doing that, it is a definite improvement, I'm a bit concerned about the loss of detail in other areas though - see below.

Quoted 21 lines

mention how --interactive can be used to review the todo list, and add a bit more detail on commit --squash/amend.

---
  Documentation/git-rebase.txt | 32 ++++++++++++++++++--------------
  1 file changed, 18 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +0 -5
index 102ff91493..594158fcbc 100644
@@ -589,21 +589,25 @@ See also INCOMPATIBLE OPTIONS below.
 
  --autosquash::
  --no-autosquash::
-	When the commit log message begins with "squash! ..." or "fixup! ..."
-	or "amend! ...", and there is already a commit in the todo list that
-	matches the same `...`, automatically modify the todo list of
-	`rebase`, so that the commit marked for squashing comes right after
-	the commit to be modified, and change the action of the moved commit

Documentation/git-rebase.txt See also INCOMPATIBLE OPTIONS below. · line 595

Quoted 10 lines
Documentation/git-rebase.txt +4 -6
-	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
-	matches the `...` if the commit subject matches, or if the `...` refers
-	to the commit's hash. As a fall-back, partial matches of the commit
-	subject work, too. The recommended way to create fixup/amend/squash
-	commits is by using the `--fixup`, `--fixup=amend:` or `--fixup=reword:`
-	and `--squash` options respectively of linkgit:git-commit[1].
+	Automatically squash commits with specially formatted messages into
+	previous commits.  If a commit message starts with "squash! ",
+	"fixup! " or "amend! ", the remainder of the subject line is taken
+	as a commit specifier,

I like this change as I think saying "remainder of the subject line" is clearer than using ...

Documentation/git-rebase.txt See also INCOMPATIBLE OPTIONS below. · line 596

Quoted 2 lines

which matches a previous commit if it matches

Documentation/git-rebase.txt +1 -0
+	the start of the subject line or the hash of that commit.

This simplification glosses over some details, in particular it is no longer clear we prefer an exact subject match to a prefix match so that

pick 123 foo
pick 456 foo bar
pick 789 fixup! foo

will be re-arranged to

pick 123 foo
fixup 789 fixup! foo
pick 456 foo bar

and not

pick 123 foo
pick 456 foo bar
fixup 789 fixup! foo

Documentation/git-rebase.txt See also INCOMPATIBLE OPTIONS below.

Quoted 7 lines

+

Documentation/git-rebase.txt +3 -3
-If the `--autosquash` option is enabled by default using the
-configuration variable `rebase.autoSquash`, this option can be
-used to override and disable this setting.
+In the rebase todo list, commits marked for squashing are moved right after
+the commits they modify, and their action is changed from `pick` to `squash`,
+`fixup` or `fixup -C`, depending on the squash marker.

Here we have lost the documentation that told users which marker corresponds to which action which is unfortunate.

Best Wishes

Phillip

Quoted 14 lines

The --interactive

Documentation/git-rebase.txt +10 -0
+option can be used to review and edit the todo list before proceeding.
++
+The recommended way to create commits with squash markers is by using the
+`--squash`, `--fixup`, `--fixup=amend:` or `--fixup=reword:` options of
+linkgit:git-commit[1], which take the target commit as an argument and
+automatically fill in the subject line of the new commit from that.
++
+The configuration variable `rebase.autoSquash` can be used to enable
+`--autosquash` by default.  See the CONFIGURATION section below for details.
+The `--no-autosquash` option overrides that setting.
  +
  See also INCOMPATIBLE OPTIONS below.
#9 lore raw
In reply to Andy Koppe

Hi Andy

Quoted 2 lines · Andy Koppe

So far, the rebase --autosquash option and rebase.autoSquash=true config setting are quietly ignored when used without --interactive,

Thanks for working on this, I agree that "--autosquash" being ignored without "--interactive" is something that we should address. I think there are several possible solutions

1 - make "--autosquash" imply "--interactive". This has the advantage
that the user gets to check the commits are going to be reordered as they expect when they edit the todo list. It is hard to see how to accommodate the config setting though - I don't think we want "rebase.autosquash=true" to imply "--interactive".

2 - make "--autosquash" without "--interactive" an error. This would
prevent the user being surprised that their commits are not squashed by a non-interactive rebase. Users who have set "rebase.autosquash=true" would have to pass "--no-autosquash" to perform any form of non-interactive rebase. This is similar to the current behavior where the user has to pass "--no-autosquash" if they want to use the apply backend with "rebase.autosquash=true".

3 - make "--autosquash" rearrange and squash commits without
"--interactive". This is convenient but there is a risk in that the user does not get a chance to check the todo list before the commits are reordered and squashed. I think that risk is fairly small with an explicit "--autosquash" on the commandline. This is the approach taken by this patch. I do have some concerns about extending the config setting to non-interactive rebases though. If the user has commits that look like

fixup! foo (HEAD)
foo bar
foo

and runs "git -c rebase.autosquash=non-interactive rebase HEAD~2" then we'll silently squash the fixup into the wrong commit due to a prefix subject match.

Quoted 3 lines

except that they prevent fast-forward and that they trigger conflicts with --apply and relatives, which is less than helpful particularly for the config setting.

The behavior to make the config setting incompatible with the apply backend was implemented to avoid users being surprised that their commits are not squashed by that backend even when they have set "rebase.autosquash=true"[1]. I think one could consider "--autosquash" being silently ignored without "--interactive" to be an oversight in 796abac7e1 (rebase: add coverage of other incompatible options, 2023-01-25) that introduced that change.

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

Quoted 3 lines

Since the "merge" backend used for interactive rebase also is the default for non-interactive rebase, there doesn't appear to be a reason not to do --autosquash without --interactive, so support that.

I think making "--autosquash" on the commandline work for non-interactive rebases is reasonable but I would be open to the argument that it would be better to make it an error and require "--interactive" to allow the user to check that the commits are going to be reordered as they expect.

Quoted 4 lines

Turn rebase.autoSquash into a comma-separated list of flags, with "interactive" or "i" enabling auto-squashing with --interactive, and "no-interactive" or "no-i" enabling it without. Make boolean true mean "interactive" for backward compatibility.

Please, please, please don't introduce abbreviated config settings, it just makes the interface more complicated. The user only has to set this once so I think the short names just add confusion. I also think "non-interactive" would be a better name for the config setting corresponding to non-interactive rebases. Does this mean the user can request that commits are only rearranged when the do not pass "--interactive"?

As I said above I do have some concerns that the "rebase.autosquash=non-interactive" setting will catch people out. Having said that ignoring "rebase.autosquash=true" without "--interactive" as we do now is inconsistent with the behavior of "rebase.autosquash=true" with "--apply". One possibility would be to introduce "rebase.autosquash=interactive" which would not cause an error with "--apply" and always require an explicit "--autosquash" on the commandline to squash fixups without "--interactive"

Quoted 2 lines

Don't prevent fast-forwards or report conflicts with --apply options when auto-squashing is not active.

I think this change deserves to be in a separate commit (which probably means separating out the config changes into that commit) as it is not directly related to fixing "--autosquash" without "--interactive" on the commandline. It would revert 796abac7e1 (rebase: add coverage of other incompatible options, 2023-01-25) and part of eddfcd8ece (rebase: provide better error message for apply options vs. merge config, 2023-01-25) and so the commit message would need to explain why that is desirable (and why it is desirable to revert only the changes related to "rebase.autosquash" and not those related to "rebase.updateRefs")

Quoted 3 lines

Change the git-rebase and config/rebase documentation accordingly, and extend t3415-rebase-autosquash.sh to test the new rebase.autosquash values and combinations with and without --interactive.

Thanks for adding tests for the new behavior.

In summary I like "--autosquash" working without "--interactive" but I'm unsure about the config changes.

Best Wishes

Phillip

Quoted 314 lines
---
  Documentation/config/rebase.txt        | 11 +++-
  Documentation/git-rebase.txt           |  2 +-
  builtin/rebase.c                       | 66 +++++++++++++++-----
  t/t3415-rebase-autosquash.sh           | 83 +++++++++++++++++++++-----
  t/t3422-rebase-incompatible-options.sh |  2 +-
  5 files changed, 132 insertions(+), 32 deletions(-)
Documentation/config/rebase.txt +10 -1
index 9c248accec..68191e5673 100644
@@ -9,7 +9,16 @@ rebase.stat::
  	rebase. False by default.
 
  rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
+	A comma-separated list of flags for when to enable auto-squashing.
+	Specifying `interactive` or `i` enables auto-squashing for rebasing with
+	`--interactive`, whereas `no-interactive` or `no-i` enables it for
+	rebasing without that option. For example, setting this to `i,no-i`
+	enables auto-squashing for both types. Setting it to true is equivalent
+	to setting it to `interactive`.
+
+	The `--autosquash` and `--no-autosquash` options of
+	linkgit:git-rebase[1] override the setting here.
+	Auto-squashing is disabled by default.
 
  rebase.autoStash::
  	When set to true, automatically create a temporary stash entry
Documentation/git-rebase.txt +1 -1
index e7b39ad244..102ff91493 100644
@@ -592,7 +592,7 @@ See also INCOMPATIBLE OPTIONS below.
  	When the commit log message begins with "squash! ..." or "fixup! ..."
  	or "amend! ...", and there is already a commit in the todo list that
  	matches the same `...`, automatically modify the todo list of
-	`rebase -i`, so that the commit marked for squashing comes right after
+	`rebase`, so that the commit marked for squashing comes right after
  	the commit to be modified, and change the action of the moved commit
  	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
  	matches the `...` if the commit subject matches, or if the `...` refers
builtin/rebase.c +51 -15
index 261a9a61fc..26c3e5dcb4 100644
@@ -131,7 +131,10 @@ struct rebase_options {
  	int reapply_cherry_picks;
  	int fork_point;
  	int update_refs;
-	int config_autosquash;
+	enum {
+		AUTOSQUASH_INTERACTIVE = 1 << 0,
+		AUTOSQUASH_NO_INTERACTIVE = 1 << 1,
+	} config_autosquash;
  	int config_rebase_merges;
  	int config_update_refs;
  };
@@ -149,7 +152,6 @@ struct rebase_options {
  		.reapply_cherry_picks = -1,             \
  		.allow_empty_message = 1,               \
  		.autosquash = -1,                       \
-		.config_autosquash = -1,                \
  		.rebase_merges = -1,                    \
  		.config_rebase_merges = -1,             \
  		.update_refs = -1,                      \
@@ -711,10 +713,8 @@ static int run_specific_rebase(struct rebase_options *opts)
  	if (opts->type == REBASE_MERGE) {
  		/* Run sequencer-based rebase */
  		setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1);
-		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
+		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT))
  			setenv("GIT_SEQUENCE_EDITOR", ":", 1);
-			opts->autosquash = 0;
-		}
  		if (opts->gpg_sign_opt) {
  			/* remove the leading "-S" */
  			char *tmp = xstrdup(opts->gpg_sign_opt + 2);
@@ -748,6 +748,30 @@ static int run_specific_rebase(struct rebase_options *opts)
  	return status ? -1 : 0;
  }
 
+static void parse_rebase_autosquash_value(struct rebase_options *opts,
+					  const char *var, const char *value)
+{
+	struct string_list tokens = STRING_LIST_INIT_NODUP;
+	char *buf = xstrdup(value);
+
+	opts->config_autosquash = 0;
+	string_list_split_in_place(&tokens, buf, ",", -1);
+
+	for (int i = 0; i < tokens.nr; i++) {
+		const char *s = tokens.items[i].string;
+
+		if (!strcmp(s, "i") || !strcmp(s, "interactive"))
+			opts->config_autosquash |= AUTOSQUASH_INTERACTIVE;
+		else if (!strcmp(s, "no-i") || !strcmp(s, "no-interactive"))
+			opts->config_autosquash |= AUTOSQUASH_NO_INTERACTIVE;
+		else
+			die(_("invalid value for '%s': '%s'"), var, s);
+	}
+
+	string_list_clear(&tokens, 0);
+	free(buf);
+}
+
  static void parse_rebase_merges_value(struct rebase_options *options, const char *value)
  {
  	if (!strcmp("no-rebase-cousins", value))
@@ -772,8 +796,14 @@ static int rebase_config(const char *var, const char *value,
  	}
 
  	if (!strcmp(var, "rebase.autosquash")) {
-		opts->config_autosquash = git_config_bool(var, value);
-		return 0;
+		int b = git_parse_maybe_bool(value);
+
+		if (b < 0)
+			parse_rebase_autosquash_value(opts, var, value);
+		else if (b)
+			opts->config_autosquash = AUTOSQUASH_INTERACTIVE;
+		else
+			opts->config_autosquash = 0;
  	}
 
  	if (!strcmp(var, "commit.gpgsign")) {
@@ -1402,13 +1432,23 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
  		    state_dir_base, cmd_live_rebase, buf.buf);
  	}
 
+	if (options.autosquash == 1) {
+		imply_merge(&options, "--autosquash");
+	} else if (options.autosquash == -1) {
+		int conf = options.config_autosquash;
+		options.autosquash =
+			(options.flags & REBASE_INTERACTIVE_EXPLICIT)
+			? !!(conf & AUTOSQUASH_INTERACTIVE)
+			: !!(conf & AUTOSQUASH_NO_INTERACTIVE);
+	}
+
  	if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
  	    (options.action != ACTION_NONE) ||
  	    (options.exec.nr > 0) ||
-	    (options.autosquash == -1 && options.config_autosquash == 1) ||
-	    options.autosquash == 1) {
+	    options.autosquash) {
  		allow_preemptive_ff = 0;
  	}
+
  	if (options.committer_date_is_author_date || options.ignore_date)
  		options.flags |= REBASE_FORCE;
 
@@ -1508,7 +1548,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
  			if (is_merge(&options))
  				die(_("apply options and merge options "
  					  "cannot be used together"));
-			else if (options.autosquash == -1 && options.config_autosquash == 1)
+			else if (options.autosquash && options.config_autosquash)
  				die(_("apply options are incompatible with rebase.autoSquash.  Consider adding --no-autosquash"));
  			else if (options.rebase_merges == -1 && options.config_rebase_merges == 1)
  				die(_("apply options are incompatible with rebase.rebaseMerges.  Consider adding --no-rebase-merges"));
@@ -1529,11 +1569,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
  	options.rebase_merges = (options.rebase_merges >= 0) ? options.rebase_merges :
  				((options.config_rebase_merges >= 0) ? options.config_rebase_merges : 0);
 
-	if (options.autosquash == 1)
-		imply_merge(&options, "--autosquash");
-	options.autosquash = (options.autosquash >= 0) ? options.autosquash :
-			     ((options.config_autosquash >= 0) ? options.config_autosquash : 0);
-
  	if (options.type == REBASE_UNSPECIFIED) {
  		if (!strcmp(options.default_backend, "merge"))
  			options.type = REBASE_MERGE;
@@ -1858,3 +1893,4 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
  	free(keep_base_onto_name);
  	return !!ret;
  }
+
t/t3415-rebase-autosquash.sh +69 -14
index a364530d76..1386eb6394 100755
@@ -43,7 +43,7 @@ test_auto_fixup () {
 
  	git tag $1 &&
  	test_tick &&
-	git rebase $2 -i HEAD^^^ &&
+	git rebase $2 HEAD^^^ &&
  	git log --oneline >actual &&
  	if test -n "$no_squash"
  	then
@@ -61,15 +61,43 @@ test_auto_fixup () {
  }
 
  test_expect_success 'auto fixup (option)' '
-	test_auto_fixup final-fixup-option --autosquash
+	test_auto_fixup fixup-option --autosquash &&
+	test_auto_fixup fixup-option-i "-i --autosquash"
  '
 
-test_expect_success 'auto fixup (config)' '
-	git config rebase.autosquash true &&
-	test_auto_fixup final-fixup-config-true &&
-	test_auto_fixup ! fixup-config-true-no --no-autosquash &&
+test_expect_success 'auto fixup (config false)' '
  	git config rebase.autosquash false &&
-	test_auto_fixup ! final-fixup-config-false
+	test_auto_fixup ! fixup-config-false &&
+	test_auto_fixup ! fixup-config-false-i -i
+'
+
+test_expect_success 'auto fixup (config true)' '
+	git config rebase.autosquash true &&
+	test_auto_fixup ! fixup-config-true &&
+	test_auto_fixup fixup-config-true-i -i &&
+	test_auto_fixup ! fixup-config-true-i-no "-i --no-autosquash"
+'
+
+test_expect_success 'auto fixup (config interactive)' '
+	git config rebase.autosquash interactive &&
+	test_auto_fixup ! fixup-config-interactive &&
+	test_auto_fixup fixup-config-interactive-i -i &&
+	test_auto_fixup ! fixup-config-interactive-i-no "-i --no-autosquash"
+'
+
+test_expect_success 'auto fixup (config no-interactive)' '
+	git config rebase.autosquash no-interactive &&
+	test_auto_fixup fixup-config-no-interactive &&
+	test_auto_fixup ! fixup-config-no-interactive-i -i &&
+	test_auto_fixup ! fixup-config-no-interactive-no "--no-autosquash"
+'
+
+test_expect_success 'auto fixup (config always)' '
+	git config rebase.autosquash i,no-i &&
+	test_auto_fixup fixup-config-always &&
+	test_auto_fixup fixup-config-always-i -i &&
+	test_auto_fixup ! fixup-config-always-no --no-autosquash &&
+	test_auto_fixup ! fixup-config-always-i-no "-i --no-autosquash"
  '
 
  test_auto_squash () {
@@ -87,7 +115,7 @@ test_auto_squash () {
  	git commit -m "squash! first" -m "extra para for first" &&
  	git tag $1 &&
  	test_tick &&
-	git rebase $2 -i HEAD^^^ &&
+	git rebase $2 HEAD^^^ &&
  	git log --oneline >actual &&
  	if test -n "$no_squash"
  	then
@@ -105,15 +133,42 @@ test_auto_squash () {
  }
 
  test_expect_success 'auto squash (option)' '
-	test_auto_squash final-squash --autosquash
+	test_auto_squash squash-option --autosquash &&
+	test_auto_squash squash-option-i "-i --autosquash"
  '
 
-test_expect_success 'auto squash (config)' '
-	git config rebase.autosquash true &&
-	test_auto_squash final-squash-config-true &&
-	test_auto_squash ! squash-config-true-no --no-autosquash &&
+test_expect_success 'auto squash (config false)' '
  	git config rebase.autosquash false &&
-	test_auto_squash ! final-squash-config-false
+	test_auto_squash ! squash-config-false &&
+	test_auto_squash ! squash-config-false-i -i
+'
+
+test_expect_success 'auto squash (config true)' '
+	git config rebase.autosquash true &&
+	test_auto_squash ! squash-config-true &&
+	test_auto_squash squash-config-true-i -i &&
+	test_auto_squash ! squash-config-true-i-no "-i --no-autosquash"
+'
+
+test_expect_success 'auto squash (config interactive)' '
+	git config rebase.autosquash i &&
+	test_auto_squash ! squash-config-interactive &&
+	test_auto_squash squash-config-interactive-i -i &&
+	test_auto_squash ! squash-config-interactive-i-no "-i --no-autosquash"
+'
+
+test_expect_success 'auto squash (config no-interactive)' '
+	git config rebase.autosquash no-i &&
+	test_auto_squash squash-config-no-interactive &&
+	test_auto_squash ! squash-config-no-interactive-i -i &&
+	test_auto_squash ! squash-config-no-interactive-no "--no-autosquash"
+'
+test_expect_success 'auto squash (config always)' '
+	git config rebase.autosquash interactive,no-interactive &&
+	test_auto_squash squash-config-always &&
+	test_auto_squash squash-config-always-i -i &&
+	test_auto_squash ! squash-config-always-no --no-autosquash &&
+	test_auto_squash ! squash-config-always-i-no "-i --no-autosquash"
  '
 
  test_expect_success 'misspelled auto squash' '
t/t3422-rebase-incompatible-options.sh +1 -1
index 2eba00bdf5..e5119e7371 100755
@@ -102,7 +102,7 @@ test_rebase_am_only () {
 
  	test_expect_success "$opt incompatible with rebase.autosquash" "
  		git checkout B^0 &&
-		test_must_fail git -c rebase.autosquash=true rebase $opt A 2>err &&
+		test_must_fail git -c rebase.autosquash=no-i rebase $opt A 2>err &&
  		grep -e --no-autosquash err
  	"
 
author
#10 lore raw
Quoted 29 lines · Phillip Wood
Quoted 2 lines · Andy Koppe

So far, the rebase --autosquash option and rebase.autoSquash=true config setting are quietly ignored when used without --interactive,

Thanks for working on this, I agree that "--autosquash" being ignored without "--interactive" is something that we should address. I think there are several possible solutions

1 - make "--autosquash" imply "--interactive". This has the advantage
    that the user gets to check the commits are going to be reordered as they expect when they edit the todo list. It is hard to see how to accommodate the config setting though - I don't think we want "rebase.autosquash=true" to imply "--interactive".

2 - make "--autosquash" without "--interactive" an error. This would
    prevent the user being surprised that their commits are not squashed by a non-interactive rebase. Users who have set "rebase.autosquash=true" would have to pass "--no-autosquash" to perform any form of non-interactive rebase. This is similar to the current behavior where the user has to pass "--no-autosquash" if they want to use the apply backend with "rebase.autosquash=true".

3 - make "--autosquash" rearrange and squash commits without
    "--interactive". This is convenient but there is a risk in that the user does not get a chance to check the todo list before the commits are reordered and squashed. I think that risk is fairly small with an explicit "--autosquash" on the commandline. This is the approach taken by this patch. I do have some concerns about extending the config setting to non-interactive rebases though. If the user has commits that look like

Quoted 7 lines

    fixup! foo (HEAD)
    foo bar
    foo

    and runs "git -c rebase.autosquash=non-interactive rebase HEAD~2" then we'll silently squash the fixup into the wrong commit due to a prefix subject match.

Good analysis. My order of preference is 3 (obviously), 1, 2.

Quoted 6 lines
Quoted 3 lines

except that they prevent fast-forward and that they trigger conflicts with --apply and relatives, which is less than helpful particularly for the config setting.

The behavior to make the config setting incompatible with the apply backend was implemented to avoid users being surprised that their commits are not squashed by that backend even when they have set "rebase.autosquash=true"[1]. I think one could consider "--autosquash" being silently ignored without "--interactive" to be an oversight in 796abac7e1 (rebase: add coverage of other incompatible options, 2023-01-25) that introduced that change.

Quoted 7 lines

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

Quoted 3 lines

Since the "merge" backend used for interactive rebase also is the default for non-interactive rebase, there doesn't appear to be a reason not to do --autosquash without --interactive, so support that.

I think making "--autosquash" on the commandline work for non-interactive rebases is reasonable but I would be open to the argument that it would be better to make it an error and require "--interactive" to allow the user to check that the commits are going to be reordered as they expect.

I found that once I got used to and started trusting the feature, particularly in connection with the corresponding git-commit support, I no longer felt the need to check the todo list as I'd inspect the log afterwards anyway. And of course there's always resetting to ORIG_HEAD when things do go wrong.

So I think users should be trusted with this, especially as it's not a particularly dangerous feature, given it requires the squash markers to be present in the first place to do anything.

Quoted 6 lines
Quoted 4 lines

Turn rebase.autoSquash into a comma-separated list of flags, with "interactive" or "i" enabling auto-squashing with --interactive, and "no-interactive" or "no-i" enabling it without. Make boolean true mean "interactive" for backward compatibility.

Please, please, please don't introduce abbreviated config settings, it just makes the interface more complicated. The user only has to set this once so I think the short names just add confusion.

Duly noted.

Quoted 1 line

I also think "non-interactive" would be a better name for the config setting corresponding to non-interactive rebases. Does this mean the user can request that commits are only rearranged when they do not pass "--interactive"?

Yes. That doesn't seem useful.

Quoted 1 line

As I said above I do have some concerns that the "rebase.autosquash=non-interactive" setting will catch people out.

I think you're right, so I've gone back to interpreting it as a boolean, but officially make it affect interactive mode only.

Quoted 1 line

Having said that ignoring "rebase.autosquash=true" without "--interactive" as we do now is inconsistent with the behavior of "rebase.autosquash=true" with "--apply". One possibility would be to introduce "rebase.autosquash=interactive" which would not cause an error with "--apply" and always require an explicit "--autosquash" on the commandline to squash fixups without "--interactive"

I don't think different error behaviour is worth a separate setting, as we can't change rebase.autosquash=true to do auto-squashing without --interactive without surprising people.

Quoted 4 lines
Quoted 2 lines

Don't prevent fast-forwards or report conflicts with --apply options when auto-squashing is not active.

I think this change deserves to be in a separate commit (which probably means separating out the config changes into that commit) as it is not directly related to fixing "--autosquash" without "--interactive" on the commandline.

Done in v4.

Quoted 1 line

In summary I like "--autosquash" working without "--interactive" but I'm unsure about the config changes.

Thanks very much for the thoughtful review!

Regards,
Andy

author
#11 lore raw

v4 cover rebase: support --autosquash without -i

In reply to Andy Koppe

Make rebase --autosquash work without --interactive, but limit rebase.autoSquash's effects to interactive mode, and improve testing and documentation.

Changes from v3:
- Separate commits for rebase.autoSquash, --autosquash and testing.
- Go back to interpreting rebase.autoSquash as a boolean, but document it as only affecting interactive mode.
- In the --autosquash documentation, bring back partial matching as a fallback and show what todo list command each squash marker corresponds to.

Thanks very much to Junio and Phillip for their reviews. I made plenty of use of non-interactive autosquash in preparing this version. :)

Andy Koppe (4):
rebase: fully ignore rebase.autoSquash without -i
rebase: support --autosquash without -i
rebase: test autosquash with and without -i
rebase: rewrite --(no-)autosquash documentation

 Documentation/config/rebase.txt        |  4 ++-
 Documentation/git-rebase.txt           | 34 +++++++++++++----------
 builtin/rebase.c                       | 17 +++++-------
 t/t3415-rebase-autosquash.sh           | 38 +++++++++++++++++++-------
 t/t3422-rebase-incompatible-options.sh | 12 --------
 5 files changed, 58 insertions(+), 47 deletions(-)
Signature · 1 line
2.43.0-rc1
author
#12 lore raw

PATCH v4 1/4 rebase: fully ignore rebase.autoSquash without -i

Setting the rebase.autoSquash config variable to true implies a couple of restrictions: it prevents preemptive fast-forwarding and it triggers conflicts with amend backend options. However, it only actually results in auto-squashing when combined with the --interactive (or -i) option, due to code in run_specific_rebase() that disables auto-squashing unless the REBASE_INTERACTIVE_EXPLICIT flag is set.

Doing autosquashing for rebase.autoSquash without --interactive would be problematic in terms of backward compatibility, but conversely, there is no need for the aforementioned restrictions without --interactive.

So drop the options.config_autosquash check from the conditions for clearing allow_preemptive_ff, as the case where it is combined with --interactive is already covered by the REBASE_INTERACTIVE_EXPLICIT flag check above it.

Also drop the "apply options are incompatible with rebase.autoSquash" error, because it is unreachable if it is restricted to --interactive, as apply options already cause an error when used with --interactive. Drop the tests for the error from t3422-rebase-incompatible-options.sh, which has separate tests for the conflicts of --interactive with apply options.

When neither --autosquash nor --no-autosquash are given, only set options.autosquash to true if rebase.autosquash is combined with --interactive.

Don't initialize options.config_autosquash to -1, as there is no need to distinguish between rebase.autoSquash being unset or explicitly set to false.

Finally, amend the rebase.autoSquash documentation to say it only affects interactive mode.

---
 Documentation/config/rebase.txt        |  4 +++-
 builtin/rebase.c                       | 13 ++++++-------
 t/t3422-rebase-incompatible-options.sh | 12 ------------
 3 files changed, 9 insertions(+), 20 deletions(-)
Documentation/config/rebase.txt +3 -1
index 9c248accec..d59576dbb2 100644
@@ -9,7 +9,9 @@ rebase.stat::
 	rebase. False by default.
 
 rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
+	If set to true, enable the `--autosquash` option of
+	linkgit:git-rebase[1] by default for interactive mode.
+	This can be overridden with the `--no-autosquash` option.
 
 rebase.autoStash::
 	When set to true, automatically create a temporary stash entry
builtin/rebase.c +6 -7
index 043c65dccd..a73de7892b 100644
@@ -149,7 +149,6 @@ struct rebase_options {
 		.reapply_cherry_picks = -1,             \
 		.allow_empty_message = 1,               \
 		.autosquash = -1,                       \
-		.config_autosquash = -1,                \
 		.rebase_merges = -1,                    \
 		.config_rebase_merges = -1,             \
 		.update_refs = -1,                      \
@@ -1405,7 +1404,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
 	    (options.action != ACTION_NONE) ||
 	    (options.exec.nr > 0) ||
-	    (options.autosquash == -1 && options.config_autosquash == 1) ||
 	    options.autosquash == 1) {
 		allow_preemptive_ff = 0;
 	}
@@ -1508,8 +1506,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 			if (is_merge(&options))
 				die(_("apply options and merge options "
 					  "cannot be used together"));
-			else if (options.autosquash == -1 && options.config_autosquash == 1)
-				die(_("apply options are incompatible with rebase.autoSquash.  Consider adding --no-autosquash"));
 			else if (options.rebase_merges == -1 && options.config_rebase_merges == 1)
 				die(_("apply options are incompatible with rebase.rebaseMerges.  Consider adding --no-rebase-merges"));
 			else if (options.update_refs == -1 && options.config_update_refs == 1)
@@ -1529,10 +1525,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	options.rebase_merges = (options.rebase_merges >= 0) ? options.rebase_merges :
 				((options.config_rebase_merges >= 0) ? options.config_rebase_merges : 0);
 
-	if (options.autosquash == 1)
+	if (options.autosquash == 1) {
 		imply_merge(&options, "--autosquash");
-	options.autosquash = (options.autosquash >= 0) ? options.autosquash :
-			     ((options.config_autosquash >= 0) ? options.config_autosquash : 0);
+	} else if (options.autosquash == -1) {
+		options.autosquash =
+			options.config_autosquash &&
+			(options.flags & REBASE_INTERACTIVE_EXPLICIT);
+	}
 
 	if (options.type == REBASE_UNSPECIFIED) {
 		if (!strcmp(options.default_backend, "merge"))
t/t3422-rebase-incompatible-options.sh +0 -12
index 2eba00bdf5..b40f26250b 100755
@@ -100,12 +100,6 @@ test_rebase_am_only () {
 		test_must_fail git rebase $opt --root A
 	"
 
-	test_expect_success "$opt incompatible with rebase.autosquash" "
-		git checkout B^0 &&
-		test_must_fail git -c rebase.autosquash=true rebase $opt A 2>err &&
-		grep -e --no-autosquash err
-	"
-
 	test_expect_success "$opt incompatible with rebase.rebaseMerges" "
 		git checkout B^0 &&
 		test_must_fail git -c rebase.rebaseMerges=true rebase $opt A 2>err &&
@@ -118,12 +112,6 @@ test_rebase_am_only () {
 		grep -e --no-update-refs err
 	"
 
-	test_expect_success "$opt okay with overridden rebase.autosquash" "
-		test_when_finished \"git reset --hard B^0\" &&
-		git checkout B^0 &&
-		git -c rebase.autosquash=true rebase --no-autosquash $opt A
-	"
-
 	test_expect_success "$opt okay with overridden rebase.rebaseMerges" "
 		test_when_finished \"git reset --hard B^0\" &&
 		git checkout B^0 &&
Signature · 1 line
2.43.0-rc1
#13 lore raw

Re: [PATCH v4 1/4] rebase: fully ignore rebase.autoSquash without -i

Hi Andy

Quoted 27 lines · Andy Koppe

Setting the rebase.autoSquash config variable to true implies a couple of restrictions: it prevents preemptive fast-forwarding and it triggers conflicts with amend backend options. However, it only actually results in auto-squashing when combined with the --interactive (or -i) option, due to code in run_specific_rebase() that disables auto-squashing unless the REBASE_INTERACTIVE_EXPLICIT flag is set.

Doing autosquashing for rebase.autoSquash without --interactive would be problematic in terms of backward compatibility, but conversely, there is no need for the aforementioned restrictions without --interactive.

So drop the options.config_autosquash check from the conditions for clearing allow_preemptive_ff, as the case where it is combined with --interactive is already covered by the REBASE_INTERACTIVE_EXPLICIT flag check above it.

Also drop the "apply options are incompatible with rebase.autoSquash" error, because it is unreachable if it is restricted to --interactive, as apply options already cause an error when used with --interactive. Drop the tests for the error from t3422-rebase-incompatible-options.sh, which has separate tests for the conflicts of --interactive with apply options.

When neither --autosquash nor --no-autosquash are given, only set options.autosquash to true if rebase.autosquash is combined with --interactive.

Quoted 6 lines

Don't initialize options.config_autosquash to -1, as there is no need to distinguish between rebase.autoSquash being unset or explicitly set to false.

Finally, amend the rebase.autoSquash documentation to say it only affects interactive mode.

Thanks for the well reasoned explanation of the changes. I think documenting rebase.autosquash as only applying to interactive rebases is a good way forward. The code changes all look sensible to me.

Best Wishes

Phillip

Quoted 98 lines
---
  Documentation/config/rebase.txt        |  4 +++-
  builtin/rebase.c                       | 13 ++++++-------
  t/t3422-rebase-incompatible-options.sh | 12 ------------
  3 files changed, 9 insertions(+), 20 deletions(-)
Documentation/config/rebase.txt +3 -1
index 9c248accec..d59576dbb2 100644
@@ -9,7 +9,9 @@ rebase.stat::
  	rebase. False by default.
 
  rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
+	If set to true, enable the `--autosquash` option of
+	linkgit:git-rebase[1] by default for interactive mode.
+	This can be overridden with the `--no-autosquash` option.
 
  rebase.autoStash::
  	When set to true, automatically create a temporary stash entry
builtin/rebase.c +6 -7
index 043c65dccd..a73de7892b 100644
@@ -149,7 +149,6 @@ struct rebase_options {
  		.reapply_cherry_picks = -1,             \
  		.allow_empty_message = 1,               \
  		.autosquash = -1,                       \
-		.config_autosquash = -1,                \
  		.rebase_merges = -1,                    \
  		.config_rebase_merges = -1,             \
  		.update_refs = -1,                      \
@@ -1405,7 +1404,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
  	if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
  	    (options.action != ACTION_NONE) ||
  	    (options.exec.nr > 0) ||
-	    (options.autosquash == -1 && options.config_autosquash == 1) ||
  	    options.autosquash == 1) {
  		allow_preemptive_ff = 0;
  	}
@@ -1508,8 +1506,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
  			if (is_merge(&options))
  				die(_("apply options and merge options "
  					  "cannot be used together"));
-			else if (options.autosquash == -1 && options.config_autosquash == 1)
-				die(_("apply options are incompatible with rebase.autoSquash.  Consider adding --no-autosquash"));
  			else if (options.rebase_merges == -1 && options.config_rebase_merges == 1)
  				die(_("apply options are incompatible with rebase.rebaseMerges.  Consider adding --no-rebase-merges"));
  			else if (options.update_refs == -1 && options.config_update_refs == 1)
@@ -1529,10 +1525,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
  	options.rebase_merges = (options.rebase_merges >= 0) ? options.rebase_merges :
  				((options.config_rebase_merges >= 0) ? options.config_rebase_merges : 0);
 
-	if (options.autosquash == 1)
+	if (options.autosquash == 1) {
  		imply_merge(&options, "--autosquash");
-	options.autosquash = (options.autosquash >= 0) ? options.autosquash :
-			     ((options.config_autosquash >= 0) ? options.config_autosquash : 0);
+	} else if (options.autosquash == -1) {
+		options.autosquash =
+			options.config_autosquash &&
+			(options.flags & REBASE_INTERACTIVE_EXPLICIT);
+	}
 
  	if (options.type == REBASE_UNSPECIFIED) {
  		if (!strcmp(options.default_backend, "merge"))
t/t3422-rebase-incompatible-options.sh +0 -12
index 2eba00bdf5..b40f26250b 100755
@@ -100,12 +100,6 @@ test_rebase_am_only () {
  		test_must_fail git rebase $opt --root A
  	"
 
-	test_expect_success "$opt incompatible with rebase.autosquash" "
-		git checkout B^0 &&
-		test_must_fail git -c rebase.autosquash=true rebase $opt A 2>err &&
-		grep -e --no-autosquash err
-	"
-
  	test_expect_success "$opt incompatible with rebase.rebaseMerges" "
  		git checkout B^0 &&
  		test_must_fail git -c rebase.rebaseMerges=true rebase $opt A 2>err &&
@@ -118,12 +112,6 @@ test_rebase_am_only () {
  		grep -e --no-update-refs err
  	"
 
-	test_expect_success "$opt okay with overridden rebase.autosquash" "
-		test_when_finished \"git reset --hard B^0\" &&
-		git checkout B^0 &&
-		git -c rebase.autosquash=true rebase --no-autosquash $opt A
-	"
-
  	test_expect_success "$opt okay with overridden rebase.rebaseMerges" "
  		test_when_finished \"git reset --hard B^0\" &&
  		git checkout B^0 &&
author
#14 lore raw

PATCH v4 2/4 rebase: support --autosquash without -i

In reply to Andy Koppe

The --autosquash option prevents preemptive fast-forwarding and triggers conflicts with amend backend options, yet it only actually performs auto-squashing when combined with the --interactive (or -i) option.

Remove the latter restriction and tweak the --autosquash description accordingly.

---
 Documentation/git-rebase.txt | 2 +-
 builtin/rebase.c             | 4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)
Documentation/git-rebase.txt +1 -1
index b4526ca246..10548e715c 100644
@@ -592,7 +592,7 @@ See also INCOMPATIBLE OPTIONS below.
 	When the commit log message begins with "squash! ..." or "fixup! ..."
 	or "amend! ...", and there is already a commit in the todo list that
 	matches the same `...`, automatically modify the todo list of
-	`rebase -i`, so that the commit marked for squashing comes right after
+	`rebase`, so that the commit marked for squashing comes right after
 	the commit to be modified, and change the action of the moved commit
 	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
 	matches the `...` if the commit subject matches, or if the `...` refers
builtin/rebase.c +1 -3
index a73de7892b..9f8192e0a5 100644
@@ -710,10 +710,8 @@ static int run_specific_rebase(struct rebase_options *opts)
 	if (opts->type == REBASE_MERGE) {
 		/* Run sequencer-based rebase */
 		setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1);
-		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
+		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT))
 			setenv("GIT_SEQUENCE_EDITOR", ":", 1);
-			opts->autosquash = 0;
-		}
 		if (opts->gpg_sign_opt) {
 			/* remove the leading "-S" */
 			char *tmp = xstrdup(opts->gpg_sign_opt + 2);
Signature · 1 line
2.43.0-rc1
#15 lore raw

Re: [PATCH v4 2/4] rebase: support --autosquash without -i

Hi Andy

Quoted 2 lines · Andy Koppe

The --autosquash option prevents preemptive fast-forwarding and triggers conflicts with amend backend options,

"amend" should be "apply". While this sentence is true I'm not quite sure how it relates to the change in this commit.

Quoted 5 lines

yet it only actually performs
auto-squashing when combined with the --interactive (or -i) option.

Remove the latter restriction and tweak the --autosquash description accordingly.

This seems like a reasonable change to me, thanks for working on it.

Best Wishes

Phillip

Quoted 35 lines
---
  Documentation/git-rebase.txt | 2 +-
  builtin/rebase.c             | 4 +---
  2 files changed, 2 insertions(+), 4 deletions(-)
Documentation/git-rebase.txt +1 -1
index b4526ca246..10548e715c 100644
@@ -592,7 +592,7 @@ See also INCOMPATIBLE OPTIONS below.
  	When the commit log message begins with "squash! ..." or "fixup! ..."
  	or "amend! ...", and there is already a commit in the todo list that
  	matches the same `...`, automatically modify the todo list of
-	`rebase -i`, so that the commit marked for squashing comes right after
+	`rebase`, so that the commit marked for squashing comes right after
  	the commit to be modified, and change the action of the moved commit
  	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
  	matches the `...` if the commit subject matches, or if the `...` refers
builtin/rebase.c +1 -3
index a73de7892b..9f8192e0a5 100644
@@ -710,10 +710,8 @@ static int run_specific_rebase(struct rebase_options *opts)
  	if (opts->type == REBASE_MERGE) {
  		/* Run sequencer-based rebase */
  		setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1);
-		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
+		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT))
  			setenv("GIT_SEQUENCE_EDITOR", ":", 1);
-			opts->autosquash = 0;
-		}
  		if (opts->gpg_sign_opt) {
  			/* remove the leading "-S" */
  			char *tmp = xstrdup(opts->gpg_sign_opt + 2);
author
#16 lore raw

PATCH v4 3/4 rebase: test autosquash with and without -i

In reply to Andy Koppe

Amend t3415-rebase-autosquash.sh to test the --autosquash option and rebase.autoSquash config with and without -i.

---
 t/t3415-rebase-autosquash.sh | 38 ++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)
t/t3415-rebase-autosquash.sh +28 -10
index a364530d76..fcc40d6fe1 100755
@@ -43,7 +43,7 @@ test_auto_fixup () {
 
 	git tag $1 &&
 	test_tick &&
-	git rebase $2 -i HEAD^^^ &&
+	git rebase $2 HEAD^^^ &&
 	git log --oneline >actual &&
 	if test -n "$no_squash"
 	then
@@ -61,15 +61,24 @@ test_auto_fixup () {
 }
 
 test_expect_success 'auto fixup (option)' '
-	test_auto_fixup final-fixup-option --autosquash
+	test_auto_fixup fixup-option --autosquash &&
+	test_auto_fixup fixup-option-i "--autosquash -i"
 '
 
-test_expect_success 'auto fixup (config)' '
+test_expect_success 'auto fixup (config true)' '
 	git config rebase.autosquash true &&
-	test_auto_fixup final-fixup-config-true &&
+	test_auto_fixup ! fixup-config-true &&
+	test_auto_fixup fixup-config-true-i -i &&
 	test_auto_fixup ! fixup-config-true-no --no-autosquash &&
+	test_auto_fixup ! fixup-config-true-i-no "-i --no-autosquash"
+'
+
+test_expect_success 'auto fixup (config false)' '
 	git config rebase.autosquash false &&
-	test_auto_fixup ! final-fixup-config-false
+	test_auto_fixup ! fixup-config-false &&
+	test_auto_fixup ! fixup-config-false-i -i &&
+	test_auto_fixup fixup-config-false-yes --autosquash &&
+	test_auto_fixup fixup-config-false-i-yes "-i --autosquash"
 '
 
 test_auto_squash () {
@@ -87,7 +96,7 @@ test_auto_squash () {
 	git commit -m "squash! first" -m "extra para for first" &&
 	git tag $1 &&
 	test_tick &&
-	git rebase $2 -i HEAD^^^ &&
+	git rebase $2 HEAD^^^ &&
 	git log --oneline >actual &&
 	if test -n "$no_squash"
 	then
@@ -105,15 +114,24 @@ test_auto_squash () {
 }
 
 test_expect_success 'auto squash (option)' '
-	test_auto_squash final-squash --autosquash
+	test_auto_squash squash-option --autosquash &&
+	test_auto_squash squash-option-i "--autosquash -i"
 '
 
-test_expect_success 'auto squash (config)' '
+test_expect_success 'auto squash (config true)' '
 	git config rebase.autosquash true &&
-	test_auto_squash final-squash-config-true &&
+	test_auto_squash ! squash-config-true &&
+	test_auto_squash squash-config-true-i -i &&
 	test_auto_squash ! squash-config-true-no --no-autosquash &&
+	test_auto_squash ! squash-config-true-i-no "-i --no-autosquash"
+'
+
+test_expect_success 'auto squash (config false)' '
 	git config rebase.autosquash false &&
-	test_auto_squash ! final-squash-config-false
+	test_auto_squash ! squash-config-false &&
+	test_auto_squash ! squash-config-false-i -i &&
+	test_auto_squash squash-config-false-yes --autosquash &&
+	test_auto_squash squash-config-false-i-yes "-i --autosquash"
 '
 
 test_expect_success 'misspelled auto squash' '
Signature · 1 line
2.43.0-rc1
#17 lore raw

Re: [PATCH v4 3/4] rebase: test autosquash with and without -i

Quoted 22 lines · Andy Koppe

Amend t3415-rebase-autosquash.sh to test the --autosquash option and rebase.autoSquash config with and without -i.

---
 t/t3415-rebase-autosquash.sh | 38 ++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)
t/t3415-rebase-autosquash.sh +1 -1
index a364530d76..fcc40d6fe1 100755
@@ -43,7 +43,7 @@ test_auto_fixup () {
 
 	git tag $1 &&
 	test_tick &&
-	git rebase $2 -i HEAD^^^ &&
+	git rebase $2 HEAD^^^ &&
 	git log --oneline >actual &&
 	if test -n "$no_squash"
 	then

t/t3415-rebase-autosquash.sh test_auto_fixup () { · line 66

Quoted 7 lines
t/t3415-rebase-autosquash.sh +2 -1
@@ -61,15 +61,24 @@ test_auto_fixup () {
 }
 
 test_expect_success 'auto fixup (option)' '
-	test_auto_fixup final-fixup-option --autosquash
+	test_auto_fixup fixup-option --autosquash &&
+	test_auto_fixup fixup-option-i "--autosquash -i"
 '

Nice. As test_auto_fixup (and test_auto_squash we see later) clears the slate with "git reset --hard base" before it starts its work, it is easy to rerun them with and without "-i".

#18 lore raw

Re: [PATCH v4 3/4] rebase: test autosquash with and without -i

In reply to Andy Koppe
Quoted 2 lines · Andy Koppe

Amend t3415-rebase-autosquash.sh to test the --autosquash option and rebase.autoSquash config with and without -i.

Thanks for adding these tests. I'd be happy to see this squashed into the previous commit, though that is probably not worth a re-roll on its own.

Best Wishes

Phillip

Quoted 85 lines
---
  t/t3415-rebase-autosquash.sh | 38 ++++++++++++++++++++++++++----------
  1 file changed, 28 insertions(+), 10 deletions(-)
t/t3415-rebase-autosquash.sh +28 -10
index a364530d76..fcc40d6fe1 100755
@@ -43,7 +43,7 @@ test_auto_fixup () {
 
  	git tag $1 &&
  	test_tick &&
-	git rebase $2 -i HEAD^^^ &&
+	git rebase $2 HEAD^^^ &&
  	git log --oneline >actual &&
  	if test -n "$no_squash"
  	then
@@ -61,15 +61,24 @@ test_auto_fixup () {
  }
 
  test_expect_success 'auto fixup (option)' '
-	test_auto_fixup final-fixup-option --autosquash
+	test_auto_fixup fixup-option --autosquash &&
+	test_auto_fixup fixup-option-i "--autosquash -i"
  '
 
-test_expect_success 'auto fixup (config)' '
+test_expect_success 'auto fixup (config true)' '
  	git config rebase.autosquash true &&
-	test_auto_fixup final-fixup-config-true &&
+	test_auto_fixup ! fixup-config-true &&
+	test_auto_fixup fixup-config-true-i -i &&
  	test_auto_fixup ! fixup-config-true-no --no-autosquash &&
+	test_auto_fixup ! fixup-config-true-i-no "-i --no-autosquash"
+'
+
+test_expect_success 'auto fixup (config false)' '
  	git config rebase.autosquash false &&
-	test_auto_fixup ! final-fixup-config-false
+	test_auto_fixup ! fixup-config-false &&
+	test_auto_fixup ! fixup-config-false-i -i &&
+	test_auto_fixup fixup-config-false-yes --autosquash &&
+	test_auto_fixup fixup-config-false-i-yes "-i --autosquash"
  '
 
  test_auto_squash () {
@@ -87,7 +96,7 @@ test_auto_squash () {
  	git commit -m "squash! first" -m "extra para for first" &&
  	git tag $1 &&
  	test_tick &&
-	git rebase $2 -i HEAD^^^ &&
+	git rebase $2 HEAD^^^ &&
  	git log --oneline >actual &&
  	if test -n "$no_squash"
  	then
@@ -105,15 +114,24 @@ test_auto_squash () {
  }
 
  test_expect_success 'auto squash (option)' '
-	test_auto_squash final-squash --autosquash
+	test_auto_squash squash-option --autosquash &&
+	test_auto_squash squash-option-i "--autosquash -i"
  '
 
-test_expect_success 'auto squash (config)' '
+test_expect_success 'auto squash (config true)' '
  	git config rebase.autosquash true &&
-	test_auto_squash final-squash-config-true &&
+	test_auto_squash ! squash-config-true &&
+	test_auto_squash squash-config-true-i -i &&
  	test_auto_squash ! squash-config-true-no --no-autosquash &&
+	test_auto_squash ! squash-config-true-i-no "-i --no-autosquash"
+'
+
+test_expect_success 'auto squash (config false)' '
  	git config rebase.autosquash false &&
-	test_auto_squash ! final-squash-config-false
+	test_auto_squash ! squash-config-false &&
+	test_auto_squash ! squash-config-false-i -i &&
+	test_auto_squash squash-config-false-yes --autosquash &&
+	test_auto_squash squash-config-false-i-yes "-i --autosquash"
  '
 
  test_expect_success 'misspelled auto squash' '
author
#19 lore raw

PATCH v4 4/4 docs: rewrite rebase --(no-)autosquash description

In reply to Andy Koppe

Rewrite the description of the rebase --(no-)autosquash options to try to make it a bit clearer. Don't use "the '...'" to refer to part of a commit message, mention how --interactive can be used to review the todo list, and add a bit more detail on commit --squash/amend.

---
 Documentation/git-rebase.txt | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +20 -14
index 10548e715c..1dd6555f66 100644
@@ -589,21 +589,27 @@ See also INCOMPATIBLE OPTIONS below.
 
 --autosquash::
 --no-autosquash::
-	When the commit log message begins with "squash! ..." or "fixup! ..."
-	or "amend! ...", and there is already a commit in the todo list that
-	matches the same `...`, automatically modify the todo list of
-	`rebase`, so that the commit marked for squashing comes right after
-	the commit to be modified, and change the action of the moved commit
-	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
-	matches the `...` if the commit subject matches, or if the `...` refers
-	to the commit's hash. As a fall-back, partial matches of the commit
-	subject work, too. The recommended way to create fixup/amend/squash
-	commits is by using the `--fixup`, `--fixup=amend:` or `--fixup=reword:`
-	and `--squash` options respectively of linkgit:git-commit[1].
+	Automatically squash commits with specially formatted messages into
+	previous commits being rebased.  If a commit message starts with
+	"squash! ", "fixup! " or "amend! ", the remainder of the subject line
+	is taken as a commit specifier, which matches a previous commit if it
+	matches the subject line or the hash of that commit.  If no commit
+	matches fully, matches of the specifier with the start of commit
+	subjects are considered.
 +
-If the `--autosquash` option is enabled by default using the
-configuration variable `rebase.autoSquash`, this option can be
-used to override and disable this setting.
+In the rebase todo list, the actions of squash, fixup and amend commits are
+changed from `pick` to `squash`, `fixup` or `fixup -C`, respectively, and they
+are moved right after the commit they modify.  The `--interactive` option can
+be used to review and edit the todo list before proceeding.
++
+The recommended way to create commits with squash markers is by using the
+`--squash`, `--fixup`, `--fixup=amend:` or `--fixup=reword:` options of
+linkgit:git-commit[1], which take the target commit as an argument and
+automatically fill in the subject line of the new commit from that.
++
+Settting configuration variable `rebase.autoSquash` to true enables
+auto-squashing by default for interactive rebase.  The `--no-autosquash`
+option can be used to override that setting.
 +
 See also INCOMPATIBLE OPTIONS below.
 
Signature · 1 line
2.43.0-rc1
author
#20 lore raw

Re: [PATCH v4 4/4] docs: rewrite rebase --(no-)autosquash description

Disregard this one in favour of the other patch 4/4 please:
"[PATCH v4 4/4] rebase: rewrite --(no-)autosquash documentation"

Sorry I failed to notice that I still had this lying around from the previous iteration.

Quoted 56 lines · Andy Koppe

Rewrite the description of the rebase --(no-)autosquash options to try to make it a bit clearer. Don't use "the '...'" to refer to part of a commit message, mention how --interactive can be used to review the todo list, and add a bit more detail on commit --squash/amend.

---
  Documentation/git-rebase.txt | 34 ++++++++++++++++++++--------------
  1 file changed, 20 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +20 -14
index 10548e715c..1dd6555f66 100644
@@ -589,21 +589,27 @@ See also INCOMPATIBLE OPTIONS below.
 
  --autosquash::
  --no-autosquash::
-	When the commit log message begins with "squash! ..." or "fixup! ..."
-	or "amend! ...", and there is already a commit in the todo list that
-	matches the same `...`, automatically modify the todo list of
-	`rebase`, so that the commit marked for squashing comes right after
-	the commit to be modified, and change the action of the moved commit
-	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
-	matches the `...` if the commit subject matches, or if the `...` refers
-	to the commit's hash. As a fall-back, partial matches of the commit
-	subject work, too. The recommended way to create fixup/amend/squash
-	commits is by using the `--fixup`, `--fixup=amend:` or `--fixup=reword:`
-	and `--squash` options respectively of linkgit:git-commit[1].
+	Automatically squash commits with specially formatted messages into
+	previous commits being rebased.  If a commit message starts with
+	"squash! ", "fixup! " or "amend! ", the remainder of the subject line
+	is taken as a commit specifier, which matches a previous commit if it
+	matches the subject line or the hash of that commit.  If no commit
+	matches fully, matches of the specifier with the start of commit
+	subjects are considered.
  +
-If the `--autosquash` option is enabled by default using the
-configuration variable `rebase.autoSquash`, this option can be
-used to override and disable this setting.
+In the rebase todo list, the actions of squash, fixup and amend commits are
+changed from `pick` to `squash`, `fixup` or `fixup -C`, respectively, and they
+are moved right after the commit they modify.  The `--interactive` option can
+be used to review and edit the todo list before proceeding.
++
+The recommended way to create commits with squash markers is by using the
+`--squash`, `--fixup`, `--fixup=amend:` or `--fixup=reword:` options of
+linkgit:git-commit[1], which take the target commit as an argument and
+automatically fill in the subject line of the new commit from that.
++
+Settting configuration variable `rebase.autoSquash` to true enables
+auto-squashing by default for interactive rebase.  The `--no-autosquash`
+option can be used to override that setting.
  +
  See also INCOMPATIBLE OPTIONS below.
 
author
#21 lore raw

PATCH v4 4/4 rebase: rewrite --(no-)autosquash documentation

In reply to Andy Koppe

Rewrite the description of the rebase --(no-)autosquash options to try to make it a bit clearer. Don't use "the '...'" to refer to part of a commit message, mention how --interactive can be used to review the todo list, and add a bit more detail on commit --squash/amend.

---
 Documentation/git-rebase.txt | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +20 -14
index 10548e715c..1dd6555f66 100644
@@ -589,21 +589,27 @@ See also INCOMPATIBLE OPTIONS below.
 
 --autosquash::
 --no-autosquash::
-	When the commit log message begins with "squash! ..." or "fixup! ..."
-	or "amend! ...", and there is already a commit in the todo list that
-	matches the same `...`, automatically modify the todo list of
-	`rebase`, so that the commit marked for squashing comes right after
-	the commit to be modified, and change the action of the moved commit
-	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
-	matches the `...` if the commit subject matches, or if the `...` refers
-	to the commit's hash. As a fall-back, partial matches of the commit
-	subject work, too. The recommended way to create fixup/amend/squash
-	commits is by using the `--fixup`, `--fixup=amend:` or `--fixup=reword:`
-	and `--squash` options respectively of linkgit:git-commit[1].
+	Automatically squash commits with specially formatted messages into
+	previous commits being rebased.  If a commit message starts with
+	"squash! ", "fixup! " or "amend! ", the remainder of the subject line
+	is taken as a commit specifier, which matches a previous commit if it
+	matches the subject line or the hash of that commit.  If no commit
+	matches fully, matches of the specifier with the start of commit
+	subjects are considered.
 +
-If the `--autosquash` option is enabled by default using the
-configuration variable `rebase.autoSquash`, this option can be
-used to override and disable this setting.
+In the rebase todo list, the actions of squash, fixup and amend commits are
+changed from `pick` to `squash`, `fixup` or `fixup -C`, respectively, and they
+are moved right after the commit they modify.  The `--interactive` option can
+be used to review and edit the todo list before proceeding.
++
+The recommended way to create commits with squash markers is by using the
+`--squash`, `--fixup`, `--fixup=amend:` or `--fixup=reword:` options of
+linkgit:git-commit[1], which take the target commit as an argument and
+automatically fill in the subject line of the new commit from that.
++
+Settting configuration variable `rebase.autoSquash` to true enables
+auto-squashing by default for interactive rebase.  The `--no-autosquash`
+option can be used to override that setting.
 +
 See also INCOMPATIBLE OPTIONS below.
 
Signature · 1 line
2.43.0-rc1
#22 lore raw

Re: [PATCH v4 4/4] rebase: rewrite --(no-)autosquash documentation

Documentation/git-rebase.txt See also INCOMPATIBLE OPTIONS below. · line 603

Quoted 4 lines · Andy Koppe
Documentation/git-rebase.txt +4 -0
+In the rebase todo list, the actions of squash, fixup and amend commits are
+changed from `pick` to `squash`, `fixup` or `fixup -C`, respectively, and they
+are moved right after the commit they modify.  The `--interactive` option can
+be used to review and edit the todo list before proceeding.

OK, this is good---exactly what I was looking for while reviewing the "lose -i from the description" step earlier in the series.

Nicely done.

#23 lore raw

Re: [PATCH v4 4/4] rebase: rewrite --(no-)autosquash documentation

In reply to Andy Koppe

Hi Andy

Quoted 4 lines · Andy Koppe

Rewrite the description of the rebase --(no-)autosquash options to try to make it a bit clearer. Don't use "the '...'" to refer to part of a commit message, mention how --interactive can be used to review the todo list, and add a bit more detail on commit --squash/amend.

This version looks good to me, thanks for working on it

Best Wishes

Phillip

Quoted 51 lines
---
  Documentation/git-rebase.txt | 34 ++++++++++++++++++++--------------
  1 file changed, 20 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +20 -14
index 10548e715c..1dd6555f66 100644
@@ -589,21 +589,27 @@ See also INCOMPATIBLE OPTIONS below.
 
  --autosquash::
  --no-autosquash::
-	When the commit log message begins with "squash! ..." or "fixup! ..."
-	or "amend! ...", and there is already a commit in the todo list that
-	matches the same `...`, automatically modify the todo list of
-	`rebase`, so that the commit marked for squashing comes right after
-	the commit to be modified, and change the action of the moved commit
-	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
-	matches the `...` if the commit subject matches, or if the `...` refers
-	to the commit's hash. As a fall-back, partial matches of the commit
-	subject work, too. The recommended way to create fixup/amend/squash
-	commits is by using the `--fixup`, `--fixup=amend:` or `--fixup=reword:`
-	and `--squash` options respectively of linkgit:git-commit[1].
+	Automatically squash commits with specially formatted messages into
+	previous commits being rebased.  If a commit message starts with
+	"squash! ", "fixup! " or "amend! ", the remainder of the subject line
+	is taken as a commit specifier, which matches a previous commit if it
+	matches the subject line or the hash of that commit.  If no commit
+	matches fully, matches of the specifier with the start of commit
+	subjects are considered.
  +
-If the `--autosquash` option is enabled by default using the
-configuration variable `rebase.autoSquash`, this option can be
-used to override and disable this setting.
+In the rebase todo list, the actions of squash, fixup and amend commits are
+changed from `pick` to `squash`, `fixup` or `fixup -C`, respectively, and they
+are moved right after the commit they modify.  The `--interactive` option can
+be used to review and edit the todo list before proceeding.
++
+The recommended way to create commits with squash markers is by using the
+`--squash`, `--fixup`, `--fixup=amend:` or `--fixup=reword:` options of
+linkgit:git-commit[1], which take the target commit as an argument and
+automatically fill in the subject line of the new commit from that.
++
+Settting configuration variable `rebase.autoSquash` to true enables
+auto-squashing by default for interactive rebase.  The `--no-autosquash`
+option can be used to override that setting.
  +
  See also INCOMPATIBLE OPTIONS below.
 
author
#24 lore raw

v5 cover rebase: support --autosquash without -i

In reply to Andy Koppe

Make rebase --autosquash work without --interactive, but limit rebase.autoSquash's effects to interactive mode, and improve testing and documentation.

Changes from v4:
- Fix amend vs apply backend thinko in commit messages.
- Squash patch 3 for testing into patch 2 and improve the commit message.
- No source changes.

Thanks again to Junio and Phillip for their reviews.

Andy Koppe (3):
rebase: fully ignore rebase.autoSquash without -i
rebase: support --autosquash without -i
rebase: rewrite --(no-)autosquash documentation

 Documentation/config/rebase.txt        |  4 ++-
 Documentation/git-rebase.txt           | 34 +++++++++++++----------
 builtin/rebase.c                       | 17 +++++-------
 t/t3415-rebase-autosquash.sh           | 38 +++++++++++++++++++-------
 t/t3422-rebase-incompatible-options.sh | 12 --------
 5 files changed, 58 insertions(+), 47 deletions(-)
Signature · 1 line
2.43.0-rc2
author
#25 lore raw

PATCH v5 1/3 rebase: fully ignore rebase.autoSquash without -i

Setting the rebase.autoSquash config variable to true implies a couple of restrictions: it prevents preemptive fast-forwarding and it triggers conflicts with apply backend options. However, it only actually results in auto-squashing when combined with the --interactive (or -i) option, due to code in run_specific_rebase() that disables auto-squashing unless the REBASE_INTERACTIVE_EXPLICIT flag is set.

Doing autosquashing for rebase.autoSquash without --interactive would be problematic in terms of backward compatibility, but conversely, there is no need for the aforementioned restrictions without --interactive.

So drop the options.config_autosquash check from the conditions for clearing allow_preemptive_ff, as the case where it is combined with --interactive is already covered by the REBASE_INTERACTIVE_EXPLICIT flag check above it.

Also drop the "apply options are incompatible with rebase.autoSquash" error, because it is unreachable if it is restricted to --interactive, as apply options already cause an error when used with --interactive. Drop the tests for the error from t3422-rebase-incompatible-options.sh, which has separate tests for the conflicts of --interactive with apply options.

When neither --autosquash nor --no-autosquash are given, only set options.autosquash to true if rebase.autosquash is combined with --interactive.

Don't initialize options.config_autosquash to -1, as there is no need to distinguish between rebase.autoSquash being unset or explicitly set to false.

Finally, amend the rebase.autoSquash documentation to say it only affects interactive mode.

---
 Documentation/config/rebase.txt        |  4 +++-
 builtin/rebase.c                       | 13 ++++++-------
 t/t3422-rebase-incompatible-options.sh | 12 ------------
 3 files changed, 9 insertions(+), 20 deletions(-)
Documentation/config/rebase.txt +3 -1
index 9c248accec..d59576dbb2 100644
@@ -9,7 +9,9 @@ rebase.stat::
 	rebase. False by default.
 
 rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
+	If set to true, enable the `--autosquash` option of
+	linkgit:git-rebase[1] by default for interactive mode.
+	This can be overridden with the `--no-autosquash` option.
 
 rebase.autoStash::
 	When set to true, automatically create a temporary stash entry
builtin/rebase.c +6 -7
index 043c65dccd..a73de7892b 100644
@@ -149,7 +149,6 @@ struct rebase_options {
 		.reapply_cherry_picks = -1,             \
 		.allow_empty_message = 1,               \
 		.autosquash = -1,                       \
-		.config_autosquash = -1,                \
 		.rebase_merges = -1,                    \
 		.config_rebase_merges = -1,             \
 		.update_refs = -1,                      \
@@ -1405,7 +1404,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
 	    (options.action != ACTION_NONE) ||
 	    (options.exec.nr > 0) ||
-	    (options.autosquash == -1 && options.config_autosquash == 1) ||
 	    options.autosquash == 1) {
 		allow_preemptive_ff = 0;
 	}
@@ -1508,8 +1506,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 			if (is_merge(&options))
 				die(_("apply options and merge options "
 					  "cannot be used together"));
-			else if (options.autosquash == -1 && options.config_autosquash == 1)
-				die(_("apply options are incompatible with rebase.autoSquash.  Consider adding --no-autosquash"));
 			else if (options.rebase_merges == -1 && options.config_rebase_merges == 1)
 				die(_("apply options are incompatible with rebase.rebaseMerges.  Consider adding --no-rebase-merges"));
 			else if (options.update_refs == -1 && options.config_update_refs == 1)
@@ -1529,10 +1525,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	options.rebase_merges = (options.rebase_merges >= 0) ? options.rebase_merges :
 				((options.config_rebase_merges >= 0) ? options.config_rebase_merges : 0);
 
-	if (options.autosquash == 1)
+	if (options.autosquash == 1) {
 		imply_merge(&options, "--autosquash");
-	options.autosquash = (options.autosquash >= 0) ? options.autosquash :
-			     ((options.config_autosquash >= 0) ? options.config_autosquash : 0);
+	} else if (options.autosquash == -1) {
+		options.autosquash =
+			options.config_autosquash &&
+			(options.flags & REBASE_INTERACTIVE_EXPLICIT);
+	}
 
 	if (options.type == REBASE_UNSPECIFIED) {
 		if (!strcmp(options.default_backend, "merge"))
t/t3422-rebase-incompatible-options.sh +0 -12
index 2eba00bdf5..b40f26250b 100755
@@ -100,12 +100,6 @@ test_rebase_am_only () {
 		test_must_fail git rebase $opt --root A
 	"
 
-	test_expect_success "$opt incompatible with rebase.autosquash" "
-		git checkout B^0 &&
-		test_must_fail git -c rebase.autosquash=true rebase $opt A 2>err &&
-		grep -e --no-autosquash err
-	"
-
 	test_expect_success "$opt incompatible with rebase.rebaseMerges" "
 		git checkout B^0 &&
 		test_must_fail git -c rebase.rebaseMerges=true rebase $opt A 2>err &&
@@ -118,12 +112,6 @@ test_rebase_am_only () {
 		grep -e --no-update-refs err
 	"
 
-	test_expect_success "$opt okay with overridden rebase.autosquash" "
-		test_when_finished \"git reset --hard B^0\" &&
-		git checkout B^0 &&
-		git -c rebase.autosquash=true rebase --no-autosquash $opt A
-	"
-
 	test_expect_success "$opt okay with overridden rebase.rebaseMerges" "
 		test_when_finished \"git reset --hard B^0\" &&
 		git checkout B^0 &&
Signature · 1 line
2.43.0-rc2
author
#26 lore raw

PATCH v5 2/3 rebase: support --autosquash without -i

In reply to Andy Koppe

The rebase --autosquash option is quietly ignored when used without --interactive (apart from preventing preemptive fast-forwarding and triggering conflicts with apply backend options).

Change that to support --autosquash without --interactive, by dropping its restriction to REBASE_INTERACTIVE_EXCPLICIT mode. When used this way, auto-squashing is done without opening the todo list editor.

Drop the -i requirement from the --autosquash description, and amend t3415-rebase-autosquash.sh to test the option and the rebase.autoSquash config variable with and without -i.

---
 Documentation/git-rebase.txt |  2 +-
 builtin/rebase.c             |  4 +---
 t/t3415-rebase-autosquash.sh | 38 ++++++++++++++++++++++++++----------
 3 files changed, 30 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +1 -1
index b4526ca246..10548e715c 100644
@@ -592,7 +592,7 @@ See also INCOMPATIBLE OPTIONS below.
 	When the commit log message begins with "squash! ..." or "fixup! ..."
 	or "amend! ...", and there is already a commit in the todo list that
 	matches the same `...`, automatically modify the todo list of
-	`rebase -i`, so that the commit marked for squashing comes right after
+	`rebase`, so that the commit marked for squashing comes right after
 	the commit to be modified, and change the action of the moved commit
 	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
 	matches the `...` if the commit subject matches, or if the `...` refers
builtin/rebase.c +1 -3
index a73de7892b..9f8192e0a5 100644
@@ -710,10 +710,8 @@ static int run_specific_rebase(struct rebase_options *opts)
 	if (opts->type == REBASE_MERGE) {
 		/* Run sequencer-based rebase */
 		setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1);
-		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
+		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT))
 			setenv("GIT_SEQUENCE_EDITOR", ":", 1);
-			opts->autosquash = 0;
-		}
 		if (opts->gpg_sign_opt) {
 			/* remove the leading "-S" */
 			char *tmp = xstrdup(opts->gpg_sign_opt + 2);
t/t3415-rebase-autosquash.sh +28 -10
index a364530d76..fcc40d6fe1 100755
@@ -43,7 +43,7 @@ test_auto_fixup () {
 
 	git tag $1 &&
 	test_tick &&
-	git rebase $2 -i HEAD^^^ &&
+	git rebase $2 HEAD^^^ &&
 	git log --oneline >actual &&
 	if test -n "$no_squash"
 	then
@@ -61,15 +61,24 @@ test_auto_fixup () {
 }
 
 test_expect_success 'auto fixup (option)' '
-	test_auto_fixup final-fixup-option --autosquash
+	test_auto_fixup fixup-option --autosquash &&
+	test_auto_fixup fixup-option-i "--autosquash -i"
 '
 
-test_expect_success 'auto fixup (config)' '
+test_expect_success 'auto fixup (config true)' '
 	git config rebase.autosquash true &&
-	test_auto_fixup final-fixup-config-true &&
+	test_auto_fixup ! fixup-config-true &&
+	test_auto_fixup fixup-config-true-i -i &&
 	test_auto_fixup ! fixup-config-true-no --no-autosquash &&
+	test_auto_fixup ! fixup-config-true-i-no "-i --no-autosquash"
+'
+
+test_expect_success 'auto fixup (config false)' '
 	git config rebase.autosquash false &&
-	test_auto_fixup ! final-fixup-config-false
+	test_auto_fixup ! fixup-config-false &&
+	test_auto_fixup ! fixup-config-false-i -i &&
+	test_auto_fixup fixup-config-false-yes --autosquash &&
+	test_auto_fixup fixup-config-false-i-yes "-i --autosquash"
 '
 
 test_auto_squash () {
@@ -87,7 +96,7 @@ test_auto_squash () {
 	git commit -m "squash! first" -m "extra para for first" &&
 	git tag $1 &&
 	test_tick &&
-	git rebase $2 -i HEAD^^^ &&
+	git rebase $2 HEAD^^^ &&
 	git log --oneline >actual &&
 	if test -n "$no_squash"
 	then
@@ -105,15 +114,24 @@ test_auto_squash () {
 }
 
 test_expect_success 'auto squash (option)' '
-	test_auto_squash final-squash --autosquash
+	test_auto_squash squash-option --autosquash &&
+	test_auto_squash squash-option-i "--autosquash -i"
 '
 
-test_expect_success 'auto squash (config)' '
+test_expect_success 'auto squash (config true)' '
 	git config rebase.autosquash true &&
-	test_auto_squash final-squash-config-true &&
+	test_auto_squash ! squash-config-true &&
+	test_auto_squash squash-config-true-i -i &&
 	test_auto_squash ! squash-config-true-no --no-autosquash &&
+	test_auto_squash ! squash-config-true-i-no "-i --no-autosquash"
+'
+
+test_expect_success 'auto squash (config false)' '
 	git config rebase.autosquash false &&
-	test_auto_squash ! final-squash-config-false
+	test_auto_squash ! squash-config-false &&
+	test_auto_squash ! squash-config-false-i -i &&
+	test_auto_squash squash-config-false-yes --autosquash &&
+	test_auto_squash squash-config-false-i-yes "-i --autosquash"
 '
 
 test_expect_success 'misspelled auto squash' '
Signature · 1 line
2.43.0-rc2
author
#27 lore raw

PATCH v5 3/3 rebase: rewrite --(no-)autosquash documentation

In reply to Andy Koppe

Rewrite the description of the rebase --(no-)autosquash options to try to make it a bit clearer. Don't use "the '...'" to refer to part of a commit message, mention how --interactive can be used to review the todo list, and add a bit more detail on commit --squash/amend.

---
 Documentation/git-rebase.txt | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +20 -14
index 10548e715c..1dd6555f66 100644
@@ -589,21 +589,27 @@ See also INCOMPATIBLE OPTIONS below.
 
 --autosquash::
 --no-autosquash::
-	When the commit log message begins with "squash! ..." or "fixup! ..."
-	or "amend! ...", and there is already a commit in the todo list that
-	matches the same `...`, automatically modify the todo list of
-	`rebase`, so that the commit marked for squashing comes right after
-	the commit to be modified, and change the action of the moved commit
-	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
-	matches the `...` if the commit subject matches, or if the `...` refers
-	to the commit's hash. As a fall-back, partial matches of the commit
-	subject work, too. The recommended way to create fixup/amend/squash
-	commits is by using the `--fixup`, `--fixup=amend:` or `--fixup=reword:`
-	and `--squash` options respectively of linkgit:git-commit[1].
+	Automatically squash commits with specially formatted messages into
+	previous commits being rebased.  If a commit message starts with
+	"squash! ", "fixup! " or "amend! ", the remainder of the subject line
+	is taken as a commit specifier, which matches a previous commit if it
+	matches the subject line or the hash of that commit.  If no commit
+	matches fully, matches of the specifier with the start of commit
+	subjects are considered.
 +
-If the `--autosquash` option is enabled by default using the
-configuration variable `rebase.autoSquash`, this option can be
-used to override and disable this setting.
+In the rebase todo list, the actions of squash, fixup and amend commits are
+changed from `pick` to `squash`, `fixup` or `fixup -C`, respectively, and they
+are moved right after the commit they modify.  The `--interactive` option can
+be used to review and edit the todo list before proceeding.
++
+The recommended way to create commits with squash markers is by using the
+`--squash`, `--fixup`, `--fixup=amend:` or `--fixup=reword:` options of
+linkgit:git-commit[1], which take the target commit as an argument and
+automatically fill in the subject line of the new commit from that.
++
+Settting configuration variable `rebase.autoSquash` to true enables
+auto-squashing by default for interactive rebase.  The `--no-autosquash`
+option can be used to override that setting.
 +
 See also INCOMPATIBLE OPTIONS below.
 
Signature · 1 line
2.43.0-rc2
#28 lore raw

Re: [PATCH v5 0/3] rebase: support --autosquash without -i

In reply to Andy Koppe

Hi Andy

Quoted 11 lines · Andy Koppe

Make rebase --autosquash work without --interactive, but limit rebase.autoSquash's effects to interactive mode, and improve testing and documentation.

Changes from v4:
- Fix amend vs apply backend thinko in commit messages.
- Squash patch 3 for testing into patch 2 and improve the commit message.
- No source changes.

Thanks again to Junio and Phillip for their reviews.

Thanks for the re-roll this version looks good to me

Best Wishes

Phillip

Quoted 13 lines

Andy Koppe (3):
rebase: fully ignore rebase.autoSquash without -i
rebase: support --autosquash without -i
rebase: rewrite --(no-)autosquash documentation

  Documentation/config/rebase.txt        |  4 ++-
  Documentation/git-rebase.txt           | 34 +++++++++++++----------
  builtin/rebase.c                       | 17 +++++-------
  t/t3415-rebase-autosquash.sh           | 38 +++++++++++++++++++-------
  t/t3422-rebase-incompatible-options.sh | 12 --------
  5 files changed, 58 insertions(+), 47 deletions(-)
#29 lore raw

Re: [PATCH v5 0/3] rebase: support --autosquash without -i

Quoted 7 lines · Phillip Wood

Hi Andy
...
Thanks for the re-roll this version looks good to me

Best Wishes

Phillip

Yup, looks good. Thanks, both.

Queued.

Quoted 12 lines
Quoted 12 lines

Andy Koppe (3):
rebase: fully ignore rebase.autoSquash without -i
rebase: support --autosquash without -i
rebase: rewrite --(no-)autosquash documentation

  Documentation/config/rebase.txt        |  4 ++-
  Documentation/git-rebase.txt           | 34 +++++++++++++----------
  builtin/rebase.c                       | 17 +++++-------
  t/t3415-rebase-autosquash.sh           | 38 +++++++++++++++++++-------
  t/t3422-rebase-incompatible-options.sh | 12 --------
  5 files changed, 58 insertions(+), 47 deletions(-)
#30 lore raw
In reply to Andy Koppe
Quoted 5 lines · Andy Koppe

So far, the rebase --autosquash option and rebase.autoSquash=true config setting are quietly ignored when used without --interactive, except that they prevent fast-forward and that they trigger conflicts with --apply and relatives, which is less than helpful particularly for the config setting.

OK. You do not explicitly say "So far," by the way. Our log message convention is to first describe what happens in the system in the present tense to illustrate why it is suboptimal, to prepare readers' minds to anticipate the solution, which is described next.

Quoted 3 lines

Since the "merge" backend used for interactive rebase also is the default for non-interactive rebase, there doesn't appear to be a reason not to do --autosquash without --interactive, so support that.

Nice.

Quoted 4 lines

Turn rebase.autoSquash into a comma-separated list of flags, with "interactive" or "i" enabling auto-squashing with --interactive, and "no-interactive" or "no-i" enabling it without. Make boolean true mean "interactive" for backward compatibility.

"i" and "no-i" are questionable (will talk about them later), but otherwise, nicely explained.

Quoted 9 lines

Don't prevent fast-forwards or report conflicts with --apply options when auto-squashing is not active.

Change the git-rebase and config/rebase documentation accordingly, and extend t3415-rebase-autosquash.sh to test the new rebase.autosquash values and combinations with and without --interactive.

---

When asking reviews on a new iteration [PATCH v(N+1)], please summarize the differences relative to [PATCH vN]. For explaining such incremental changes for individual patches, here between the three-dash line and the diffstat is the place to do so. When you have a cover letter [PATCH 0/X], it can be done in that messaage. Either way is OK. Doing both is also helpful as long as the explanation done in two places do not contradict with each other.

Quoted 16 lines
 Documentation/config/rebase.txt        | 11 +++-
 Documentation/git-rebase.txt           |  2 +-
 builtin/rebase.c                       | 63 ++++++++++++++-----
 t/t3415-rebase-autosquash.sh           | 83 +++++++++++++++++++++-----
 t/t3422-rebase-incompatible-options.sh |  2 +-
 5 files changed, 129 insertions(+), 32 deletions(-)
Documentation/config/rebase.txt +0 -1
index 9c248accec..68191e5673 100644
@@ -9,7 +9,16 @@ rebase.stat::
 	rebase. False by default.
 
 rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.

Documentation/config/rebase.txt rebase.stat:: · line 21

Quoted 10 lines
Documentation/config/rebase.txt +10 -0
+	A comma-separated list of flags for when to enable auto-squashing.
+	Specifying `interactive` or `i` enables auto-squashing for rebasing with
+	`--interactive`, whereas `no-interactive` or `no-i` enables it for
+	rebasing without that option. For example, setting this to `i,no-i`
+	enables auto-squashing for both types. Setting it to true is equivalent
+	to setting it to `interactive`.
+
+	The `--autosquash` and `--no-autosquash` options of
+	linkgit:git-rebase[1] override the setting here.
+	Auto-squashing is disabled by default.

If you trid to format the documentation before sending this patch, you'd have seen the second paragraph formatted as if it were a code snippet. Dedent the second paragraph (and later ones if you had more than one extra paragraphs), and turn the blank line between the paragraphs into a line with "+" (and nothing else) on it. See the description of --autosquash option in Documentation/git-rebase.txt for an example.

Quoted 63 lines
Documentation/git-rebase.txt +1 -1
index e7b39ad244..102ff91493 100644
@@ -592,7 +592,7 @@ See also INCOMPATIBLE OPTIONS below.
 	When the commit log message begins with "squash! ..." or "fixup! ..."
 	or "amend! ...", and there is already a commit in the todo list that
 	matches the same `...`, automatically modify the todo list of
-	`rebase -i`, so that the commit marked for squashing comes right after
+	`rebase`, so that the commit marked for squashing comes right after
 	the commit to be modified, and change the action of the moved commit
 	from `pick` to `squash` or `fixup` or `fixup -C` respectively. A commit
 	matches the `...` if the commit subject matches, or if the `...` refers
builtin/rebase.c +15 -5
index 261a9a61fc..0403c7415c 100644
@@ -131,7 +131,10 @@ struct rebase_options {
 	int reapply_cherry_picks;
 	int fork_point;
 	int update_refs;
-	int config_autosquash;
+	enum {
+		AUTOSQUASH_INTERACTIVE = 1 << 0,
+		AUTOSQUASH_NO_INTERACTIVE = 1 << 1,
+	} config_autosquash;
 	int config_rebase_merges;
 	int config_update_refs;
 };
@@ -149,7 +152,6 @@ struct rebase_options {
 		.reapply_cherry_picks = -1,             \
 		.allow_empty_message = 1,               \
 		.autosquash = -1,                       \
-		.config_autosquash = -1,                \
 		.rebase_merges = -1,                    \
 		.config_rebase_merges = -1,             \
 		.update_refs = -1,                      \
@@ -711,10 +713,8 @@ static int run_specific_rebase(struct rebase_options *opts)
 	if (opts->type == REBASE_MERGE) {
 		/* Run sequencer-based rebase */
 		setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1);
-		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
+		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT))
 			setenv("GIT_SEQUENCE_EDITOR", ":", 1);
-			opts->autosquash = 0;
-		}
 		if (opts->gpg_sign_opt) {
 			/* remove the leading "-S" */
 			char *tmp = xstrdup(opts->gpg_sign_opt + 2);
@@ -748,6 +748,27 @@ static int run_specific_rebase(struct rebase_options *opts)
 	return status ? -1 : 0;
 }
 
+static void parse_rebase_autosquash_value(struct rebase_options *opts,
+					  const char *var, const char *value)
+{
+	struct string_list tokens = STRING_LIST_INIT_NODUP;
+	char *buf = xstrdup(value);
+
+	opts->config_autosquash = 0;
+	string_list_split_in_place(&tokens, buf, ",", -1);
+
+	for (int i = 0; i < tokens.nr; i++) {

builtin/rebase.c static int run_specific_rebase(struct rebase_options *opts) · line 770

Quoted 10 lines
builtin/rebase.c +10 -0
+		const char *s = tokens.items[i].string;
+
+		if (!strcmp(s, "i") || !strcmp(s, "interactive"))
+			opts->config_autosquash |= AUTOSQUASH_INTERACTIVE;
+		else if (!strcmp(s, "no-i") || !strcmp(s, "no-interactive"))
+			opts->config_autosquash |= AUTOSQUASH_NO_INTERACTIVE;
+		else
+			die(_("invalid value for '%s': '%s'"), var, s);
+	}
+}

OK, by clearing opts->config_autosquash in this function, you keep the rebase.autosquash to be "the last one wins" as a whole. If a configuration file with lower precedence (e.g., /etc/gitconfig) says "[rebase] autosquash" to set it to "interactive,no-interactive", a separate setting in your ~/.gitconfig "[rebase] autosquash = false" would override both bits.

A more involved design may let the users override these bits independently by allowing something like "!no-i" (take whatever the lower precedence configuration file says for the interactive case, but disable autosquash when running a non-interactive rebase) as the value, but I think the approach taken by this patch to allow replacing as a whole is OK. It is simpler to explain.

Giving short-hands for often used command line options is one thing, but I do not think a short-hand is warranted here, especially when the other one needs to be a less-than-half legible "no-i" that does not allow "no-int" and friends, for configuration variable values. I'd strongly suggest dropping them.

Thanks.

author
#31 lore raw
Quoted 14 lines · Junio C Hamano

Andy Koppe <[email protected]> writes:
Our log
message convention is to first describe what happens in the system in the present tense to illustrate why it is suboptimal, to prepare readers' minds to anticipate the solution, which is described next.

When asking reviews on a new iteration [PATCH v(N+1)], please summarize the differences relative to [PATCH vN]. For explaining such incremental changes for individual patches, here between the three-dash line and the diffstat is the place to do so. When you have a cover letter [PATCH 0/X], it can be done in that messaage. Either way is OK. Doing both is also helpful as long as the explanation done in two places do not contradict with each other.

Quoted 7 lines

If you tried to format the documentation before sending this patch, you'd have seen the second paragraph formatted as if it were a code snippet. Dedent the second paragraph (and later ones if you had more than one extra paragraphs), and turn the blank line between the paragraphs into a line with "+" (and nothing else) on it. See the description of --autosquash option in Documentation/git-rebase.txt for an example.

Sad thing is that I knew most of that from reading the contribution guidelines and previous experience, but obviously I don't always remember. So thanks for you patience in re-explaining that.

Quoted 14 lines

OK, by clearing opts->config_autosquash in this function, you keep the rebase.autosquash to be "the last one wins" as a whole. If a configuration file with lower precedence (e.g., /etc/gitconfig) says "[rebase] autosquash" to set it to "interactive,no-interactive", a separate setting in your ~/.gitconfig "[rebase] autosquash = false" would override both bits.

A more involved design may let the users override these bits independently by allowing something like "!no-i" (take whatever the lower precedence configuration file says for the interactive case, but disable autosquash when running a non-interactive rebase) as the value, but I think the approach taken by this patch to allow replacing as a whole is OK. It is simpler to explain.

Quoted 5 lines

Giving short-hands for often used command line options is one thing, but I do not think a short-hand is warranted here, especially when the other one needs to be a less-than-half legible "no-i" that does not allow "no-int" and friends, for configuration variable values. I'd strongly suggest dropping them.

Dropped in v4, along with the attempt to expand rebase.autoSquash, following Phillip's review.

Regards,
Andy