Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Differentiate rebase vs. fast-forward messages
Maximilian Roos341b0f8cf06e
diff --git a/src/commands/standalone.rs b/src/commands/standalone.rsindex 1d60c7e26..43dc66011 100644--- a/src/commands/standalone.rs+++ b/src/commands/standalone.rs@@ -256,10 +256,16 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<bool> {return Ok(false);}- // Rebase onto target- crate::output::progress(format!(- "{CYAN}Rebasing onto {CYAN_BOLD}{target_branch}{CYAN_BOLD:#}{CYAN}...{CYAN:#}"- ))?;+ // Check if this is a fast-forward or true rebase+ let head_sha = repo.run_command(&["rev-parse", "HEAD"])?.trim().to_string();+ let is_fast_forward = merge_base == head_sha;++ // Only show progress for true rebases (fast-forwards are instant)+ if !is_fast_forward {+ crate::output::progress(format!(+ "{CYAN}Rebasing onto {CYAN_BOLD}{target_branch}{CYAN_BOLD:#}{CYAN}...{CYAN:#}"+ ))?;+ }let rebase_result = repo.run_command(&["rebase", &target_branch]);@@ -287,9 +293,15 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<bool> {// Successuse worktrunk::styling::GREEN;- crate::output::success(format!(- "{GREEN}Rebased onto {GREEN_BOLD}{target_branch}{GREEN_BOLD:#}{GREEN:#}"- ))?;+ if is_fast_forward {+ crate::output::success(format!(+ "{GREEN}Fast-forwarded to {GREEN_BOLD}{target_branch}{GREEN_BOLD:#}{GREEN:#}"+ ))?;+ } else {+ crate::output::success(format!(+ "{GREEN}Rebased onto {GREEN_BOLD}{target_branch}{GREEN_BOLD:#}{GREEN:#}"+ ))?;+ }Ok(true)}diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex 0cfa4150e..ae057a166 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -2506,6 +2506,97 @@ fn test_merge_no_commits_with_changes() {);}+#[test]+fn test_merge_rebase_fast_forward() {+ // Test fast-forward case: branch has no commits, main moved ahead+ // Should show "Fast-forwarded to main" without progress message+ let mut repo = TestRepo::new();+ repo.commit("Initial commit");+ repo.setup_remote("main");++ // Create a feature worktree with NO commits (just branched from main)+ let feature_wt = repo.add_worktree("fast-forward-test", "fast-forward-test");++ // Advance main with a new commit (in the primary worktree which is on main)+ fs::write(repo.root_path().join("main-update.txt"), "main content")+ .expect("Failed to write file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["add", "main-update.txt"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to add file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["commit", "-m", "Update main"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to commit");++ // Merge - should fast-forward (no commits to replay)+ snapshot_merge(+ "merge_rebase_fast_forward",+ &repo,+ &["main"],+ Some(&feature_wt),+ );+}++#[test]+fn test_merge_rebase_true_rebase() {+ // Test true rebase case: branch has commits and main moved ahead+ // Should show "Rebasing onto main..." progress message+ let mut repo = TestRepo::new();+ repo.commit("Initial commit");+ repo.setup_remote("main");++ // Create a feature worktree with a commit+ let feature_wt = repo.add_worktree("true-rebase-test", "true-rebase-test");+ fs::write(feature_wt.join("feature.txt"), "feature content").expect("Failed to write file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["add", "feature.txt"])+ .current_dir(&feature_wt)+ .output()+ .expect("Failed to add file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["commit", "-m", "Add feature"])+ .current_dir(&feature_wt)+ .output()+ .expect("Failed to commit");++ // Advance main with a new commit (in the primary worktree which is on main)+ fs::write(repo.root_path().join("main-update.txt"), "main content")+ .expect("Failed to write file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["add", "main-update.txt"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to add file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["commit", "-m", "Update main"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to commit");++ // Merge - should show rebasing progress (has commits to replay)+ snapshot_merge(+ "merge_rebase_true_rebase",+ &repo,+ &["main"],+ Some(&feature_wt),+ );+}+#[test]fn test_merge_primary_on_different_branch() {let mut repo = TestRepo::new();diff --git a/tests/snapshots/integration__integration_tests__merge__merge_rebase_fast_forward.snap b/tests/snapshots/integration__integration_tests__merge__merge_rebase_fast_forward.snapnew file mode 100644index 000000000..eb2c6b7f1--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_rebase_fast_forward.snap@@ -0,0 +1,29 @@+---+source: tests/integration_tests/merge.rs+info:+ program: wt+ args:+ - merge+ - main+ env:+ CLICOLOR_FORCE: "1"+ COLUMNS: "150"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ LANG: C+ LC_ALL: C+ SOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+---+success: true+exit_code: 0+----- stdout -----+β [32mFast-forwarded to [1m[32mmain[0m[0m+β [32mMerged to [1m[32mmain[0m[0m (no new commits)+π [36mRemoving worktree & branch...[0m+β [32mRemoved worktree & branch for [1m[32mfast-forward-test[0m[32m, changed directory to [1m[32m[REPO][0m[0m++----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__merge__merge_rebase_true_rebase.snap b/tests/snapshots/integration__integration_tests__merge__merge_rebase_true_rebase.snapnew file mode 100644index 000000000..f35932115--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_rebase_true_rebase.snap@@ -0,0 +1,34 @@+---+source: tests/integration_tests/merge.rs+info:+ program: wt+ args:+ - merge+ - main+ env:+ CLICOLOR_FORCE: "1"+ COLUMNS: "150"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ LANG: C+ LC_ALL: C+ SOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+---+success: true+exit_code: 0+----- stdout -----+π [36mRebasing onto [1m[36mmain[0m[36m...[0m+β [32mRebased onto [1m[32mmain[0m[0m+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no commit/squash needed)+[107m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mtrue-rebase-test[m[33m)[m Add feature+[107m [0m feature.txt | 1 [32m+[m+[107m [0m 1 file changed, 1 insertion(+)+β [32mMerged to [1m[32mmain[0m[0m (1 commit, 1 file, [32m+1[0m)+π [36mRemoving worktree & branch...[0m+β [32mRemoved worktree & branch for [1m[32mtrue-rebase-test[0m[32m, changed directory to [1m[32m[REPO][0m[0m++----- stderr -----