diff options
author | Nickolay Ponomarev <asqueella@gmail.com> | 2019-07-15 02:54:41 +0300 |
---|---|---|
committer | Nickolay Ponomarev <asqueella@gmail.com> | 2019-07-15 04:02:08 +0300 |
commit | 2c363a5f14f793e8b9e76ac643725ca49c96ddd8 (patch) | |
tree | 808a44debebf3aca760b50d525a4f68c448e742e /src/lib.rs | |
parent | 5e625392adad459cad561b1529aa48035623e6f1 (diff) |
Add --and-rebase flag to run `git rebase` automatically
Fixes #18.
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -14,6 +14,7 @@ pub struct Config<'a> { pub dry_run: bool, pub force: bool, pub base: Option<&'a str>, + pub and_rebase: bool, pub logger: &'a slog::Logger, } @@ -249,6 +250,22 @@ pub fn run(config: &Config) -> Result<(), failure::Error> { config.logger, "No additions staged, try adding something to the index." ); + } else if config.and_rebase { + use std::process::Command; + // unwrap() is safe here, as we exit early if the stack is empty + let last_commit_in_stack = &stack.last().unwrap().0; + // The stack isn't supposed to have any merge commits, per the check in working_stack() + assert_eq!(last_commit_in_stack.parents().len(), 1); + + // Use a range that is guaranteed to include all the commits we might have + // committed "fixup!" commits for. + let base_commit_sha = last_commit_in_stack.parent(0)?.id().to_string(); + // Don't check that we have successfully absorbed everything, nor git's + // exit code -- as git will print helpful messages on its own. + Command::new("git") + .args(&["rebase", "--interactive", "--autosquash", &base_commit_sha]) + .status() + .expect("could not run git rebase"); } Ok(()) |