Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Refactor: Explicitly handle rebase results

Maximilian Roos133307d4e5e9
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index 384fb4072..d54aab76a 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -145,7 +145,10 @@ pub fn handle_merge(
// Rebase onto target (skip if --no-commit) - track whether rebasing occurred
let rebased = if commit {
- super::standalone::handle_rebase(Some(&target_branch))?
+ matches!(
+ super::standalone::handle_rebase(Some(&target_branch))?,
+ super::standalone::RebaseResult::Rebased
+ )
} else {
false
};
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 3b6206005..2d7b1796a 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -27,7 +27,7 @@ pub use merge::handle_merge;
#[cfg(unix)]
pub use select::handle_select;
pub use standalone::{
- handle_rebase, handle_squash, handle_standalone_ask_approvals,
+ RebaseResult, handle_rebase, handle_squash, handle_standalone_ask_approvals,
handle_standalone_clear_approvals, handle_standalone_commit, handle_standalone_run_hook,
};
pub use worktree::{handle_remove, handle_switch};
diff --git a/src/commands/standalone.rs b/src/commands/standalone.rs
index e1884ab56..c365b204a 100644
--- a/src/commands/standalone.rs
+++ b/src/commands/standalone.rs
@@ -255,9 +255,16 @@ pub fn handle_squash(
Ok(true)
}
+/// Result of a rebase operation
+pub enum RebaseResult {
+ /// Rebase occurred (either true rebase or fast-forward)
+ Rebased,
+ /// Already up-to-date with target branch
+ UpToDate(String),
+}
+
/// Handle shared rebase workflow (used by `wt step rebase` and `wt merge`)
-/// Returns true if rebasing occurred, false if already up-to-date
-pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<bool> {
+pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<RebaseResult> {
let repo = Repository::current();
// Get target branch (default to default branch if not provided)
@@ -272,7 +279,7 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<bool> {
if merge_base == target_sha {
// Already up-to-date, no rebase needed
- return Ok(false);
+ return Ok(RebaseResult::UpToDate(target_branch));
}
// Check if this is a fast-forward or true rebase
@@ -322,7 +329,7 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<bool> {
))?;
}
- Ok(true)
+ Ok(RebaseResult::Rebased)
}
/// Handle `wt config approvals ask` command - approve all commands in the project
diff --git a/src/main.rs b/src/main.rs
index 70e5122d6..24c2a6b43 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -24,11 +24,11 @@ use commands::command_executor::CommandContext;
use commands::handle_select;
use commands::worktree::{SwitchResult, handle_push};
use commands::{
- ConfigAction, handle_config_create, handle_config_list, handle_config_refresh_cache,
- handle_config_status_set, handle_config_status_unset, handle_configure_shell, handle_init,
- handle_list, handle_merge, handle_rebase, handle_remove, handle_squash,
- handle_standalone_ask_approvals, handle_standalone_clear_approvals, handle_standalone_commit,
- handle_standalone_run_hook, handle_switch,
+ ConfigAction, RebaseResult, handle_config_create, handle_config_list,
+ handle_config_refresh_cache, handle_config_status_set, handle_config_status_unset,
+ handle_configure_shell, handle_init, handle_list, handle_merge, handle_rebase, handle_remove,
+ handle_squash, handle_standalone_ask_approvals, handle_standalone_clear_approvals,
+ handle_standalone_commit, handle_standalone_run_hook, handle_switch,
};
use output::{execute_user_command, handle_remove_output, handle_switch_output};
@@ -316,13 +316,26 @@ fn main() {
let stage_final = stage
.or_else(|| config.commit.and_then(|c| c.stage))
.unwrap_or_default();
- handle_squash(target.as_deref(), force, !verify, false, stage_final).map(|_| ())
+ let did_work =
+ handle_squash(target.as_deref(), force, !verify, false, stage_final)?;
+ if !did_work {
+ crate::output::info("Nothing to squash")?;
+ }
+ Ok(())
}),
StepCommand::Push {
target,
allow_merge_commits,
} => handle_push(target.as_deref(), allow_merge_commits, "Pushed to", None),
- StepCommand::Rebase { target } => handle_rebase(target.as_deref()).map(|_| ()),
+ StepCommand::Rebase { target } => {
+ handle_rebase(target.as_deref()).and_then(|result| match result {
+ RebaseResult::Rebased => Ok(()),
+ RebaseResult::UpToDate(branch) => {
+ crate::output::info(format!("Already up-to-date with {branch}"))?;
+ Ok(())
+ }
+ })
+ }
StepCommand::PostCreate { force } => {
handle_standalone_run_hook(HookType::PostCreate, force)
}