Skip to content

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.rs
index 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> {
// Success
use 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.rs
index 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.snap
new file mode 100644
index 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 -----
+βœ… Fast-forwarded to main
+βœ… Merged to main (no new commits)
+πŸ”„ Removing worktree & branch...
+βœ… Removed worktree & branch for fast-forward-test, changed directory to [REPO]
+
+----- 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.snap
new file mode 100644
index 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 -----
+πŸ”„ Rebasing onto main...
+βœ… Rebased onto main
+πŸ”„ Merging 1 commit to main @ [SHA] (no commit/squash needed)
+  * [SHA] (HEAD -> true-rebase-test) Add feature
+  feature.txt | 1 +
+  1 file changed, 1 insertion(+)
+βœ… Merged to main (1 commit, 1 file, +1)
+πŸ”„ Removing worktree & branch...
+βœ… Removed worktree & branch for true-rebase-test, changed directory to [REPO]
+
+----- stderr -----