git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] wt-status: suggest 'git rebase --continue' to conclude 'merge' instruction

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Mar 31, 2025, 15:38 UTC
Message-ID
<f0d1f0ba-84ab-4914-9dd1-81a5d2e0dbc3@gmail.com>
In-Reply-To
<db01acdd062a17b1cca62428eba8c3ed62ca7c6a.1743181401.git.gitgitgadget@gmail.com>
Hi Philippe
On 28/03/2025 17:03, Philippe Blain via GitGitGadget wrote:
Show 12 quoted lines
> From: Philippe Blain <levraiphilippeblain@gmail.com>
> 
> Since 982288e9bd (status: rebase and merge can be in progress at the
> same time, 2018-11-12), when a merge is in progress as part of a 'git
> rebase -r' operation, 'wt_longstatus_print_state' shows information
> about the in-progress rebase (via show_rebase_information), and then
> calls 'show_merge_in_progress' to help the user conclude the merge. This
> function suggests using 'git commit' to do so, but this throws away the
> authorship information from the original merge, which is not ideal.
> Using 'git rebase --continue' instead preserves the authorship
> information, since we enter 'sequencer.c:run_git_commit' which calls
> read_env_script to read the author-script file.
Good catch
Show 17 quoted lines
> Note however that this only works when a merge was scheduled using a
> 'merge' instruction in the rebase todo list. Indeed, when using 'exec
> git merge', the state files necessary for 'git rebase --continue' are
> not present, and one must use 'git commit' (or 'git merge --continue')
> in that case.
> 
> Be more helpful to the user by suggesting either 'git rebase
> --continue', when the merge was scheduled using a 'merge' instruction,
> and 'git commit' otherwise. As such, add a
> 'merge_during_rebase_in_progress' field to 'struct wt_status_state', and
> detect this situation in wt_status_check_rebase by looking at the last
> command done. Adjust wt_longstatus_print_state to check this field and
> suggest 'git rebase --continue' if a merge came from a 'merge'
> instruction, by calling show_rebase_in_progress directly.
> 
> Add two tests for the new behaviour, using 'merge' and 'exec git merge'
> instructions.
Nice, thanks for adding the tests
Show 21 quoted lines
>   
> +test_expect_success 'status during rebase -ir after conflicted merge (exec git merge)' '
> +	git reset --hard main &&
> +	git checkout -b rebase_i_merge &&
> +	test_commit unrelated &&
> +	git checkout -b rebase_i_merge_side &&
> +	test_commit side2 main.txt &&
> +	git checkout rebase_i_merge &&
> +	test_commit side1 main.txt &&
> +	PICK=$(git rev-parse --short rebase_i_merge) &&
> +	test_must_fail git merge rebase_i_merge_side &&
> +	echo side1 >main.txt &&
> +	git add main.txt &&
> +	test_tick &&
> +	git commit --no-edit &&
> +	MERGE=$(git rev-parse --short rebase_i_merge) &&
> +	ONTO=$(git rev-parse --short main) &&
> +	test_when_finished "git rebase --abort" &&
> +	FAKE_LINES="1 2 3 5 6 7 8 9 10 exec_git_merge_refs/rewritten/rebase-i-merge-side" &&
> +	export FAKE_LINES &&
> +	test_must_fail git rebase -ir main &&
As with the other patch this should be
	test_must_fail env FAKE_LINES=... git rebase ...

and the same for the test below. These tests show just how opaque the FAKE_LINES mechanism is - I've got no idea what it's doing. If it is not too much work it might be worth writing out the desired todo list to a file and using set_replace_editor. If you do that note that you can use tag names in the todo list you don't need to get the oid for each commit and you probably don't need to rebase the side branch, just the merge.

Show 7 quoted lines
> @@ -1760,8 +1761,12 @@ int wt_status_check_rebase(const struct worktree *wt,
>   			state->rebase_interactive_in_progress = 1;
>   		else
>   			state->rebase_in_progress = 1;
> +		read_rebase_todolist("rebase-merge/done", &have_done);
> +		if (have_done.nr > 0 && starts_with(have_done.items[have_done.nr - 1].string, "merge"))
> +				state->merge_during_rebase_in_progress = 1;

We already read and parse the done list in show_rebase_information() - is it possible to avoid doing that twice by setting this flag there?

Show 21 quoted lines
>   		state->branch = get_branch(wt, "rebase-merge/head-name");
>   		state->onto = get_branch(wt, "rebase-merge/onto");
> +		string_list_clear(&have_done, 0);
>   	} else
>   		return 0;
>   	return 1;
> @@ -1855,10 +1860,15 @@ static void wt_longstatus_print_state(struct wt_status *s)
>   
>   	if (state->merge_in_progress) {
>   		if (state->rebase_interactive_in_progress) {
> -			show_rebase_information(s, state_color);
> -			fputs("\n", s->fp);
> -		}
> -		show_merge_in_progress(s, state_color);
> +			if (state->merge_during_rebase_in_progress)
> +				show_rebase_in_progress(s, state_color);
> +			else {
> +				show_rebase_information(s, state_color);
> +				fputs("\n", s->fp);
> +				show_merge_in_progress(s, state_color);
> +			}
The indentation here looks strange
Thanks
Phillip
Show 17 quoted lines
> +		} else
> +			show_merge_in_progress(s, state_color);
>   	} else if (state->am_in_progress)
>   		show_am_in_progress(s, state_color);
>   	else if (state->rebase_in_progress || state->rebase_interactive_in_progress)
> diff --git a/wt-status.h b/wt-status.h
> index 4e377ce62b8..84bedfcd48f 100644
> --- a/wt-status.h
> +++ b/wt-status.h
> @@ -87,6 +87,7 @@ struct wt_status_state {
>   	int am_empty_patch;
>   	int rebase_in_progress;
>   	int rebase_interactive_in_progress;
> +	int merge_during_rebase_in_progress;
>   	int cherry_pick_in_progress;
>   	int bisect_in_progress;
>   	int revert_in_progress;
Previous: Philippe Blain via GitGitGadgetNext: Johannes Schindelin
Message 10 of 17 in “rebase -r: a bugfix and two status-related improvements”
  1. 0/3 rebase -r: a bugfix and two status-related improvementsPhilippe Blain via GitGitGadget, Mar 28, 2025
  2. 1/3 rebase -r: do create merge commit after empty resolutionPhilippe Blain via GitGitGadget, Mar 28, 2025
  3. Eric SunshineMar 28, 2025
  4. Eric SunshineMar 28, 2025
  5. Johannes SchindelinApr 1, 2025
  6. Phillip WoodMar 31, 2025
  7. 2/3 wt-status: also abbreviate 'merge' and 'fixup -C' lines during rebasePhilippe Blain via GitGitGadget, Mar 28, 2025
  8. Phillip WoodMar 31, 2025
  9. 3/3 wt-status: suggest 'git rebase --continue' to conclude 'merge' instructionPhilippe Blain via GitGitGadget, Mar 28, 2025
  10. Phillip WoodMar 31, 2025
  11. Johannes SchindelinApr 1, 2025
  12. phillip.wood123@gmail.comApr 2, 2025
  13. Johannes SchindelinApr 3, 2025
  14. phillip.wood123@gmail.comApr 3, 2025
  15. Johannes SchindelinApr 4, 2025
  16. Phillip WoodApr 4, 2025
  17. Phillip WoodMar 31, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.