feat: add --exec option to run commands after each patch during rebase #608
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add --exec option to run commands after each patch during rebases
Disclaimer
I wrote this pull request with the assistance of Claude Opus 4.5.
I can note this in the commit log if that is a desirable flag.
I am an experienced programmer and do not think this is slop, I have tried to actually implement this in a reasonable/sane manner.
I used a tool I made called deciduous while writing this and it provides a neat flow diagram of how it made the choices that are implemented, so I am including that just for fun.
The PR
This PR implements the
--execoption forstg rebase, as requested in #469. It allows running a shell command after each patch is successfully applied during a rebase operation, similar togit rebase --exec.Key features:
--execoptions (run in sequence)$SHELL(orshas fallback)Implementation Approach
Design Decision: Modular Architecture
We considered two approaches:
--execin rebase.rs only - simpler, more localizedtransaction/push_patches- more modular, reusableWe chose Option 2 (modular approach) because:
push_patches_with_execmethod could be reused by other commands in the futureCode Changes
src/stupid/context.rs: Addedexec_cmd()method to run shell commands via the user's$SHELLsrc/stack/transaction/mod.rs: Addedpush_patches_with_exec()method that pushes patches and runs exec commands after each successful pushsrc/stack/transaction/ui.rs: Addedprint_exec()method for user feedbacksrc/cmd/rebase.rs: Added--exec/-xargument with appropriate conflictsDesign Discussion Point: Failure Behavior
When an exec command fails, the entire transaction is rolled back (no patches remain applied). This differs from
git rebase --execwhich leaves you at the failing commit to fix things.Current behavior (rollback):
Git's behavior (partial state):
Rationale for rollback:
stg pushpatches one at a time with manual checksHowever, you / the community may prefer git's behavior for consistency. I'm happy to discuss and modify this if desired.
Personally, I have never wanted to keep the mid-run state that comes with an issue when running this command, so I just went with my own personal preference here. It would not be hard to change, let me know what you think @jpgrayson @fbenkstein
Usage Examples
Testing
t/t2206-rebase-exec.shManual Test Output
Implements: #469