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

feat(branch): add gs branch squash #564

Merged
merged 10 commits into from
Feb 3, 2025
Merged

Conversation

jonboiser
Copy link
Contributor

@jonboiser jonboiser commented Feb 3, 2025

Resolves #558, using the procedure discussed, namely

  1. Verifies that the current branch can be squashed
  2. Checks out the current branch in a detached state
  3. Resets the detached branch to the base branch
  4. Commits all staged changes, using either the original first commit msg an editable placeholder message consisting of all the squashed commit messages, or a provided message
  5. Updates the HEAD ref of the current branch to the hash that was created in the previous step
  6. Checks out the current branch

@@ -22,7 +22,7 @@ type branchCheckoutCmd struct {
checkoutOptions

Untracked bool `short:"u" config:"branchCheckout.showUntracked" help:"Show untracked branches if one isn't supplied"`
Branch string `arg:"" optional:"" help:"Name of the branch to delete" predictor:"branches"`
Branch string `arg:"" optional:"" help:"Name of the branch to checkout" predictor:"branches"`
Copy link
Owner

Choose a reason for hiding this comment

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

😅 thanks!

This will allow customizing the initial commit message a user sees
when a commit operation is run.
Combine the commit messages of the original N commits in-order
to form the initial commit message for the squashed commit.
This way, if the user aborts the operation,
we don't leave them in a detached state.
This will prevent loss of changes if the branch was updated
while the user was editing the commit message.
All commands that call Git.Commit should have a --no-verify flag.
@abhinav
Copy link
Owner

abhinav commented Feb 3, 2025

Thanks, @jonboiser.
I made a few follow up edits—mostly invisible stuff but with one significant behavioral change:
Instead of using the first/last commit as the commit message when one isn't provided, this will use the --template flag of git commit to fill one up with all of the messages of all of the commits being squashed, and the user will be able to edit that. So the options for a user are: provide a commit message with -m, or write one in an editor, with the old ones provided.

This should be good to merge as soon as the build passes.
Thanks for contributing!

@abhinav abhinav merged commit bffa35c into abhinav:main Feb 3, 2025
12 checks passed
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.

New command: gs branch squash (same as Graphite squash)
2 participants