Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rebase -i: reword empty commit after fast-forward #1860

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

phillipwood
Copy link

@phillipwood phillipwood commented Feb 4, 2025

Thanks to Junio for his comments on V1. I've added a comment explaining why we use a fixed set of commits flags as he suggested.

Cc: Junio C Hamano [email protected]

@phillipwood phillipwood force-pushed the rebase-reword-empty-commit branch from dc23839 to 06de47a Compare February 5, 2025 10:30
@phillipwood
Copy link
Author

/submit

Copy link

gitgitgadget bot commented Feb 5, 2025

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-1860/phillipwood/rebase-reword-empty-commit-v1

To fetch this version to local tag pr-1860/phillipwood/rebase-reword-empty-commit-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-1860/phillipwood/rebase-reword-empty-commit-v1

Copy link

gitgitgadget bot commented Feb 5, 2025

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Phillip Wood via GitGitGadget" <[email protected]> writes:

> @@ -2510,9 +2510,8 @@ static int do_pick_commit(struct repository *r,
>  		*check_todo = !!(flags & EDIT_MSG);
>  		if (!res && reword) {
>  fast_forward_edit:
> -			res = run_git_commit(NULL, opts, EDIT_MSG |
> -					     VERIFY_MSG | AMEND_MSG |
> -					     (flags & ALLOW_EMPTY));
> +			flags = EDIT_MSG | VERIFY_MSG | AMEND_MSG | ALLOW_EMPTY;
> +			res = run_git_commit(NULL, opts, flags);
>  			*check_todo = 1;
>  		}
>  	}

I am perfectly OK with the idea of run_git_commit() with the fixed
set of flags bits, ignoring everything the preceding code did to
incrementally compute it before the control reaches this point.  In
the fast-forward-edit scenario in which the control reaches this
point, the flag bits like CREATE_ROOT_COMMIT the earlier steps may
have added to "flags".

But the way "flags" variable is used elsewhere in this function is
"we check how this 'pick' step needs to work, and compute bits to
pass when we eventually call run_git_commit() or do_commit(),
incrementally", so making an unconditional assignment to it looked
a bit surprising.  At least the unconditional assignment deserves
a bit of comment explaining why other bits do not matter and these
bits are what we want to use here.

Thanks.

Copy link

gitgitgadget bot commented Feb 5, 2025

This patch series was integrated into seen via git@4826972.

@gitgitgadget gitgitgadget bot added the seen label Feb 5, 2025
Copy link

gitgitgadget bot commented Feb 6, 2025

This branch is now known as pw/rebase-i-ff-empty-commit.

Copy link

gitgitgadget bot commented Feb 6, 2025

This patch series was integrated into seen via git@e854fdd.

@phillipwood phillipwood force-pushed the rebase-reword-empty-commit branch from 06de47a to f7675fc Compare February 7, 2025 14:28
Copy link

gitgitgadget bot commented Feb 7, 2025

This patch series was integrated into seen via git@7a7f5d0.

Copy link

gitgitgadget bot commented Feb 7, 2025

There was a status update in the "New Topics" section about the branch pw/rebase-i-ff-empty-commit on the Git mailing list:

"git rebase -i" failed to allow rewording an empty commit that has
been fast-forwarded.

Expecting a reroll.
cf. <[email protected]>
source: <[email protected]>

Copy link

gitgitgadget bot commented Feb 10, 2025

This patch series was integrated into seen via git@d13b7aa.

Copy link

gitgitgadget bot commented Feb 11, 2025

There was a status update in the "Cooking" section about the branch pw/rebase-i-ff-empty-commit on the Git mailing list:

"git rebase -i" failed to allow rewording an empty commit that has
been fast-forwarded.

Expecting a reroll.
cf. <[email protected]>
source: <[email protected]>

When rebase rewords a commit it picks the commit and then runs "git
commit --amend" to reword it. When the commit is picked the sequencer
tries to reuse existing commits by fast-forwarding if the parents are
unchanged. Rewording an empty commit that has been fast-forwarded fails
because "git commit --amend" is called without "--allow-empty". This
happens because when a commit is fast-forwarded the logic that checks
whether we should pass "--allow-empty" is skipped. Fix this by always
passing "--allow-empty" when rewording a commit. This is safe because we
are amending a commit that has already been picked so if it had become
empty when it was picked we'd have already returned an error.

As "git commit" will happily create empty merge commits without
"--allow-empty" we do not need to pass that flag when rewording merge
commits.

Signed-off-by: Phillip Wood <[email protected]>
@phillipwood phillipwood force-pushed the rebase-reword-empty-commit branch from f7675fc to 826edd3 Compare February 11, 2025 15:57
@phillipwood
Copy link
Author

/submit

Copy link

gitgitgadget bot commented Feb 11, 2025

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-1860/phillipwood/rebase-reword-empty-commit-v2

To fetch this version to local tag pr-1860/phillipwood/rebase-reword-empty-commit-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-1860/phillipwood/rebase-reword-empty-commit-v2

Copy link

gitgitgadget bot commented Feb 11, 2025

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Phillip Wood via GitGitGadget" <[email protected]> writes:

> As "git commit" will happily create empty merge commits without
> "--allow-empty" we do not need to pass that flag when rewording merge
> commits.

Thanks, will queue.  Let's mark it for 'next'.

Copy link

gitgitgadget bot commented Feb 11, 2025

This patch series was integrated into seen via git@d40271f.

Copy link

gitgitgadget bot commented Feb 12, 2025

This patch series was integrated into seen via git@cd33264.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant