Skip to contentSkip to conversation

git rebase fast-forward fails with abbreviateCommands

PATCH In review Jan Alexander Steffens (heftig) 5 participants 11 messages Mar 27, 2020 – Mar 30, 2020

lore
Share & tools
lore
#0 lore raw

Hi,

Since 2.26.0 a simple "git rebase" fails to fast-forward a branch, reporting "error: nothing to do."

It started to work again after removing my gitconfig. I've reduced it to the following:

git init foo; cd foo
git commit --allow-empty -m foo
git commit --allow-empty -m bar
git checkout -tb foo
git reset HEAD~
git -c rebase.abbreviateCommands=true rebase

#1 lore raw

Hi Jan,

+cc Johannes, Elijah, and Phillip.

Le 27/03/2020 à 12:44, Jan Alexander Steffens (heftig) a écrit :

Quoted 8 lines

Hi,

Since 2.26.0 a simple "git rebase" fails to fast-forward a branch, reporting "error: nothing to do."

It started to work again after removing my gitconfig. I've reduced it to the following:

Quoted 7 lines

git init foo; cd foo
git commit --allow-empty -m foo
git commit --allow-empty -m bar
git checkout -tb foo
git reset HEAD~
git -c rebase.abbreviateCommands=true rebase

Thank you for reporting this bug.

Since git 2.26, the default rebase backend switched from "am" to "merge". So, by default, a todo list is created, even if you can't see it.

In this case, the todo list contains only a `noop', but this command has no short form, and is abbreviated with a comment mark. As there is no more commands in the list, the backend will fail with the error "nothing to do".

Three approach to fix this:

1) add an abbreviation to `noop'; this is the simplest fix, and "n" is
not taken.
2) if a command has no short form, do not abbreviate it; this is
trivial to do, and should not break anything.

A third approach would be to change the meaning of an empty buffer, but this would break some tests (at least t3404.3) and cause more confusion for users than necessary.

Thank you again for reporting this.

Cheers,
Alban

#2 lore raw

Hi Alban,

Quoted 32 lines · Alban Gruin

Hi Jan,

+cc Johannes, Elijah, and Phillip.

Quoted 8 lines · Jan Alexander Steffens (heftig)

Hi,

Since 2.26.0 a simple "git rebase" fails to fast-forward a branch, reporting "error: nothing to do."

It started to work again after removing my gitconfig. I've reduced it to the following:

Quoted 7 lines

git init foo; cd foo
git commit --allow-empty -m foo
git commit --allow-empty -m bar
git checkout -tb foo
git reset HEAD~
git -c rebase.abbreviateCommands=true rebase

Thank you for reporting this bug.

Since git 2.26, the default rebase backend switched from "am" to "merge". So, by default, a todo list is created, even if you can't see it.

In this case, the todo list contains only a `noop', but this command has no short form, and is abbreviated with a comment mark. As there is no more commands in the list, the backend will fail with the error "nothing to do".

Quoted 6 lines

Three approach to fix this:

1) add an abbreviation to `noop'; this is the simplest fix, and "n" is
not taken.
2) if a command has no short form, do not abbreviate it; this is
trivial to do, and should not break anything.

Both sound reasonable to me.

Quoted 3 lines

A third approach would be to change the meaning of an empty buffer, but this would break some tests (at least t3404.3) and cause more confusion for users than necessary.

Well, "error: nothing to do" probably makes sense if the user specifies a list of empty commands or sees a list of empty commands and agrees to pass these to the backend. But I'm not sure that message makes sense for implicitly interactive runs as opposed to explicitly interactive ones. Perhaps we could change the message to just be "Already up to date" if the buffer is empty and the run is not explicitly interactive?

Elijah

#3 lore raw
Quoted 55 lines · Elijah Newren

Hi Alban,

Quoted 35 lines · Alban Gruin

Hi Jan,

+cc Johannes, Elijah, and Phillip.

Quoted 8 lines · Jan Alexander Steffens (heftig)

Hi,

Since 2.26.0 a simple "git rebase" fails to fast-forward a branch, reporting "error: nothing to do."

It started to work again after removing my gitconfig. I've reduced it to the following:

Quoted 7 lines

git init foo; cd foo
git commit --allow-empty -m foo
git commit --allow-empty -m bar
git checkout -tb foo
git reset HEAD~
git -c rebase.abbreviateCommands=true rebase

Thank you for reporting this bug.

Since git 2.26, the default rebase backend switched from "am" to "merge". So, by default, a todo list is created, even if you can't see it.

In this case, the todo list contains only a `noop', but this command has
no short form, and is abbreviated with a comment mark. As there is no
more commands in the list, the backend will fail with the error "nothing
to do".

Quoted 7 lines

Three approach to fix this:

1) add an abbreviation to `noop'; this is the simplest fix, and
"n" is
not taken.
2) if a command has no short form, do not abbreviate it; this is
trivial to do, and should not break anything.

Both sound reasonable to me.

Quoted 5 lines

A third approach would be to change the meaning of an empty buffer, but
this would break some tests (at least t3404.3) and cause more confusion
for users than necessary.

Quoted 8 lines

Well, "error: nothing to do" probably makes sense if the user specifies a list of empty commands or sees a list of empty commands and agrees to pass these to the backend. But I'm not sure that message makes sense for implicitly interactive runs as opposed to explicitly interactive ones. Perhaps we could change the message to just be "Already up to date" if the buffer is empty and the run is not
explicitly interactive?

Changing just the message and return code wouldn't be enough, as the empty todo results in the rebase being aborted without fast-forwarding the branch.

#4 lore raw
In reply to Elijah Newren

Hi Elijah,

Le 27/03/2020 à 19:39, Elijah Newren a écrit :

Quoted 4 lines
Quoted 3 lines

A third approach would be to change the meaning of an empty buffer, but this would break some tests (at least t3404.3) and cause more confusion for users than necessary.

Quoted 9 lines

Well, "error: nothing to do" probably makes sense if the user specifies a list of empty commands or sees a list of empty commands and agrees to pass these to the backend. But I'm not sure that message makes sense for implicitly interactive runs as opposed to explicitly interactive ones. Perhaps we could change the message to just be "Already up to date" if the buffer is empty and the run is not explicitly interactive?

Is this even supposed to happen in non-interactive mode? When I try to rebase an already up-to-date branch, rebase fails with the message "Current branch … is up to date."

Quoted 2 lines

Elijah

Cheers,
Alban

#5 lore raw
In reply to Alban Gruin
Quoted 6 lines · Alban Gruin

Three approach to fix this:

1) add an abbreviation to `noop'; this is the simplest fix, and "n" is
not taken.
2) if a command has no short form, do not abbreviate it; this is
trivial to do, and should not break anything.

I think the second is the most sensible. Thanks.

#6 lore raw

cover rebase --merge: fix fast forwarding when `rebase.abbreviateCommands' is set

In reply to Jan Alexander Steffens (heftig)

Jan Alexander Steffens reported that when rebase.abbreviateCommands' is set, the merge backend fails to fast forward. This is because the backend generates a todo list with only a noop', and since this command has no abbreviated form, it is replaced by a comment mark. The sequencer then interprets it as if there is nothing to do, and fails.

This patch series fixes this issue by teaching the sequencer not to abbreviate a command if it does not have a short form, and adds a bunch of regression tests.

This series is based on 9fadedd637 ("Merge branch 'ds/default-pack-use-sparse-to-true'", 2020-03-29).

The tip of this series is tagged as "rebase-dont-abbreviate-v1" at
https://github.com/agrn/git.

Alban Gruin (2):
sequencer: don't abbreviate a command if it doesn't have a short form
t3432: test --merge' with rebase.abbreviateCommands = true', too

 sequencer.c                    |  9 ++++++---
 t/t3432-rebase-fast-forward.sh | 24 +++++++++++++++++++-----
 2 files changed, 25 insertions(+), 8 deletions(-)
Signature · 1 line
2.25.0
#7 lore raw

PATCH 1/2 sequencer: don't abbreviate a command if it doesn't have a short form

When the sequencer is requested to abbreviate commands, it will replace those that does not have a short form (eg. noop') by a comment mark. noop' serves no purpose, except when fast-forwarding (ie. by running git rebase'). Removing it will break this command when rebase.abbreviateCommands' is set to true.

This changes todo_list_to_strbuf() to check if a command has an actual short form, and to ignore it if not.

---
 sequencer.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
sequencer.c +6 -3
index 6fd2674632..79d0c5cb2e 100644
@@ -1578,7 +1578,7 @@ static const char *command_to_string(const enum todo_command command)
 
 static char command_to_char(const enum todo_command command)
 {
-	if (command < TODO_COMMENT && todo_command_info[command].c)
+	if (command < TODO_COMMENT)
 		return todo_command_info[command].c;
 	return comment_line_char;
 }
@@ -4963,6 +4963,8 @@ static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis
 		max = num;
 
 	for (item = todo_list->items, i = 0; i < max; i++, item++) {
+		char cmd;
+
 		/* if the item is not a command write it and continue */
 		if (item->command >= TODO_COMMENT) {
 			strbuf_addf(buf, "%.*s\n", item->arg_len,
@@ -4971,8 +4973,9 @@ static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis
 		}
 
 		/* add command to the buffer */
-		if (flags & TODO_LIST_ABBREVIATE_CMDS)
-			strbuf_addch(buf, command_to_char(item->command));
+		cmd = command_to_char(item->command);
+		if (flags & TODO_LIST_ABBREVIATE_CMDS && cmd)
+			strbuf_addch(buf, cmd);
 		else
 			strbuf_addstr(buf, command_to_string(item->command));
 
Signature · 1 line
2.25.0
#8 lore raw

Re: [PATCH v1 1/2] sequencer: don't abbreviate a command if it doesn't have a short form

sequencer.c static const char *command_to_string(const enum todo_command command) · line 1584

Quoted 7 lines · Alban Gruin

static char command_to_char(const enum todo_command command) {

sequencer.c +1 -1
-	if (command < TODO_COMMENT && todo_command_info[command].c)
+	if (command < TODO_COMMENT)
 		return todo_command_info[command].c;
 	return comment_line_char;
 }

This is not a new issue, and it may not even be an issue at all, but it is curious that command_to_string() barfs with "unknown command" when fed an int outside enum todo_command or TODO_COMMENT iteslf, while this returns comment_line_char. Makes a reader wonder if both of them should be dying the same way.

Quoted 10 lines
sequencer.c +2 -0
@@ -4963,6 +4963,8 @@ static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis
 		max = num;
 
 	for (item = todo_list->items, i = 0; i < max; i++, item++) {
+		char cmd;
+
 		/* if the item is not a command write it and continue */
 		if (item->command >= TODO_COMMENT) {
 			strbuf_addf(buf, "%.*s\n", item->arg_len,

sequencer.c static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis · line 4977

Quoted 7 lines
sequencer.c +2 -2
@@ -4971,8 +4973,9 @@ static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis
 		}
 
 		/* add command to the buffer */
-		if (flags & TODO_LIST_ABBREVIATE_CMDS)
-			strbuf_addch(buf, command_to_char(item->command));
+		cmd = command_to_char(item->command);
+		if (flags & TODO_LIST_ABBREVIATE_CMDS && cmd)

Even though the precedence rule may not require it, for readability's sake, it would be easier to see the association if this is written with an extra set of parentheses, i.e.

		if ((flags & TODO_LIST_ABBREVIATE_CMDS) && cmd)

sequencer.c static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis · line 4980

Quoted 3 lines
sequencer.c +1 -0
+			strbuf_addch(buf, cmd);
 		else
 			strbuf_addstr(buf, command_to_string(item->command));

The logic is quite clear. If there is an abbreviation and the user prefers to see it, we use it, but otherwise we'll give the full spelling.

We are sure we will never get TODO_COMMENT here in item->command at this point (the loop would have already continued after adding it to the buffer), so it does not affect us that command_to_string() would die. For that matter, if we made command_to_char() die, just like command_to_string() would, nobody will get hurt and the resulting code would become saner. But obviously it is outside the scope of this fix (#leftoverbits).

Thanks.

#9 lore raw

Re: [PATCH v1 1/2] sequencer: don't abbreviate a command if it doesn't have a short form

In reply to Alban Gruin
Quoted 2 lines · Alban Gruin

When the sequencer is requested to abbreviate commands, it will replace those that does not have a short form (eg. `noop') by a comment mark.

s/does/do/

Quoted 6 lines

noop' serves no purpose, except when fast-forwarding (ie. by running git rebase'). Removing it will break this command when `rebase.abbreviateCommands' is set to true.

This changes todo_list_to_strbuf() to check if a command has an actual short form, and to ignore it if not.

Perhaps: s/This changes/Change/

Quoted 1 line
#10 lore raw

PATCH 2/2 t3432: test `--merge' with `rebase.abbreviateCommands = true', too

In reply to Alban Gruin

When fast forwarding, git --merge' should act the same whether rebase.abbreviateCommands' is set or not, but so far it was not the case. This duplicates the tests ensuring that `--merge' works when fast forwarding to check if it also works with abbreviated commands.

---
 t/t3432-rebase-fast-forward.sh | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
t/t3432-rebase-fast-forward.sh +19 -5
index 6c9d4a1375..6f0452c0ea 100755
@@ -28,10 +28,12 @@ test_rebase_same_head () {
 	shift &&
 	cmp_f="$1" &&
 	shift &&
-	test_rebase_same_head_ $status_n $what_n $cmp_n " --apply" "$*" &&
-	test_rebase_same_head_ $status_f $what_f $cmp_f " --apply --no-ff" "$*"
-	test_rebase_same_head_ $status_n $what_n $cmp_n " --merge" "$*" &&
-	test_rebase_same_head_ $status_f $what_f $cmp_f " --merge --no-ff" "$*"
+	test_rebase_same_head_ $status_n $what_n $cmp_n 0 " --apply" "$*" &&
+	test_rebase_same_head_ $status_f $what_f $cmp_f 0 " --apply --no-ff" "$*"
+	test_rebase_same_head_ $status_n $what_n $cmp_n 0 " --merge" "$*" &&
+	test_rebase_same_head_ $status_f $what_f $cmp_f 0 " --merge --no-ff" "$*"
+	test_rebase_same_head_ $status_n $what_n $cmp_n 1 " --merge" "$*" &&
+	test_rebase_same_head_ $status_f $what_f $cmp_f 1 " --merge --no-ff" "$*"
 }
 
 test_rebase_same_head_ () {
@@ -41,9 +43,21 @@ test_rebase_same_head_ () {
 	shift &&
 	cmp="$1" &&
 	shift &&
+	abbreviate="$1" &&
+	shift &&
 	flag="$1"
 	shift &&
-	test_expect_$status "git rebase$flag $* with $changes is $what with $cmp HEAD" "
+	if test $abbreviate -eq 1
+	then
+		msg="git rebase$flag $* (rebase.abbreviateCommands = true) with $changes is $what with $cmp HEAD"
+	else
+		msg="git rebase$flag $* with $changes is $what with $cmp HEAD"
+	fi &&
+	test_expect_$status "$msg" "
+		if test $abbreviate -eq 1
+		then
+			test_config rebase.abbreviateCommands true
+		fi &&
 		oldhead=\$(git rev-parse HEAD) &&
 		test_when_finished 'git reset --hard \$oldhead' &&
 		cp .git/logs/HEAD expect &&
Signature · 1 line
2.25.0