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

Edit all messages of consecutive squashed commits in one go #92

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

Conversation

krobelus
Copy link
Contributor

@krobelus krobelus commented May 18, 2021

Closes #77

The CI has some unrelated false positives, which will be fixed in Pylint 2.9 ("Suppress consider-using-with inside context managers.")

@krobelus
Copy link
Contributor Author

this broke sequences like pick + fixup + pick + squash which is fixed now.

Still it has the potential to break scripts that override GIT_EDITOR to edit the commit message, but that risk is fairly low.

Comment on lines -254 to +299
elif step.kind == StepKind.FIXUP:
elif is_fixup(step):
if current is None:
raise ValueError("Cannot apply fixup as first commit")
if not fixups:
fixup_target_message = current.message
fixups.append((step.kind, rebased.message))
current = current.update(tree=rebased.tree())
is_last_fixup = index + 1 == len(todos) or not is_fixup(todos[index + 1])
if is_last_fixup:
if any(kind == StepKind.SQUASH for kind, message in fixups):
current = current.update(
message=squash_message_template(fixup_target_message, fixups)
)
current = edit_commit_message(current)
fixups.clear()
Copy link
Contributor

@anordal anordal Jun 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Since you need to look ahead of at least squash and fixup steps, to see if there are more, you might check the same predicate unconditionally (for all step kinds) for the benefit of discovering the beginning of the sequence in the iteration it happens. Then, the first commit could go into the same list as the rest instead of having a separate variable. The same check negated:

is_squashed_into = index + 1 < len(todos) and is_fixup(todos[index + 1])

Do you know what else could use this? If a later commit that is squashed into this commit has a known tree (#133), we can also avoid raising any conflict on this commit, because this commit's tree is to be discarded.

This happens when part of commit A belongs in commit B: When you have carved out a fixup of B from A, you have the situation where "fixup B" comes before B. To preserve the metadata of the right commit, you may prefer to squash "fixup B" into B instead of the opposite. Hm, maybe this particular case is better supported by an actual "prefix" action that doesn't require the user to reorder and us to be smart about it.

Comment on lines +245 to +246
def is_fixup(todo: Step) -> bool:
return todo.kind in (StepKind.FIXUP, StepKind.SQUASH)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Is "squash" or "fixup" the generalization of the two? I would say "squash", since you can say

I squashed my fixups.

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

Successfully merging this pull request may close these issues.

Combine message of consecutive squashed commits in one go
2 participants