Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Clarify branch cleanup conditions and rename has_marginal_contribution
Maximilian Roos46e539890c8d
diff --git a/docs/content/remove.md b/docs/content/remove.mdindex 29810ee03..70f7d1766 100644--- a/docs/content/remove.md+++ b/docs/content/remove.md@@ -43,11 +43,11 @@ Branches delete automatically when their content is already in the target branchA branch is safe to delete when its content is already reflected in the target. Worktrunk checks three conditions:-1. **Branch is ancestor** — Three-dot diff (`main...branch`) shows no files. All commits on branch are reachable from main.+1. **No added changes** — Three-dot diff (`main...branch`) shows no files. The branch has no file changes beyond the merge-base.2. **Tree contents match** — Branch tree SHA equals main tree SHA. Commit history differs but file contents are identical (e.g., after a revert or merge commit pulling in main).3. **Merge adds nothing** — Simulated merge (`git merge-tree`) produces the same tree as main. Handles squash-merged branches where main has since advanced.-In `wt list`, `_` indicates condition 1 (no commits ahead) and `≡` indicates condition 2 (contents match). Rows with either are dimmed.+In `wt list`, `_` indicates no commits ahead of main, and `≡` indicates tree contents match. Branches showing either are dimmed as safe to delete.Use `-D` to force-delete branches with unmerged changes. Use `--no-delete-branch` to keep the branch regardless of status.diff --git a/src/cli.rs b/src/cli.rsindex 802c5bbdf..d6e59bf2a 100644--- a/src/cli.rs+++ b/src/cli.rs@@ -1262,11 +1262,11 @@ Branches delete automatically when their content is already in the target branchA branch is safe to delete when its content is already reflected in the target. Worktrunk checks three conditions:-1. **Branch is ancestor** — Three-dot diff (`main...branch`) shows no files. All commits on branch are reachable from main.+1. **No added changes** — Three-dot diff (`main...branch`) shows no files. The branch has no file changes beyond the merge-base.2. **Tree contents match** — Branch tree SHA equals main tree SHA. Commit history differs but file contents are identical (e.g., after a revert or merge commit pulling in main).3. **Merge adds nothing** — Simulated merge (`git merge-tree`) produces the same tree as main. Handles squash-merged branches where main has since advanced.-In `wt list`, `_` indicates condition 1 (no commits ahead) and `≡` indicates condition 2 (contents match). Rows with either are dimmed.+In `wt list`, `_` indicates no commits ahead of main, and `≡` indicates tree contents match. Branches showing either are dimmed as safe to delete.Use `-D` to force-delete branches with unmerged changes. Use `--no-delete-branch` to keep the branch regardless of status.diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rsindex 99a81a9cd..eae523858 100644--- a/src/git/repository/mod.rs+++ b/src/git/repository/mod.rs@@ -607,14 +607,11 @@ impl Repository {self.run_command_check(&["merge-base", "--is-ancestor", base, head])}- /// Check if a branch has any marginal contribution compared to a target.+ /// Check if a branch has file changes beyond the merge-base with target.///- /// Uses three-dot diff (`target...branch`) which shows changes from the merge-base- /// to the branch. Returns false (no marginal contribution) when:- /// - Branch is an ancestor of target (merge-base = branch)- /// - Branch merged target and resolved back to merge-base state- /// - Branch's net changes are empty for any other reason- pub fn has_marginal_contribution(&self, branch: &str, target: &str) -> anyhow::Result<bool> {+ /// Uses three-dot diff (`target...branch`) which shows files changed from merge-base+ /// to branch. Returns false when the diff is empty (no added changes).+ pub fn has_added_changes(&self, branch: &str, target: &str) -> anyhow::Result<bool> {// git diff --name-only target...branch shows files changed from merge-base to branchlet range = format!("{target}...{branch}");let stdout = self.run_command(&["diff", "--name-only", &range])?;diff --git a/src/output/handlers.rs b/src/output/handlers.rsindex e1932bc46..408af9c9e 100644--- a/src/output/handlers.rs+++ b/src/output/handlers.rs@@ -48,8 +48,8 @@ fn format_switch_success_message(/// Why a branch is considered integrated into the target.#[derive(Debug, Clone, Copy, PartialEq, Eq)]enum IntegrationReason {- /// Branch has no marginal contribution to target (ancestor, merged back to base, etc.)- NoMarginalContribution,+ /// Branch has no file changes beyond the merge-base with target+ NoAddedChanges,/// Branch's tree SHA matches target's tree SHA (squash merge/rebase)ContentsMatch,/// Merge simulation shows branch would add nothing to target@@ -60,7 +60,7 @@ enum IntegrationReason {/// Check if a branch's content has been integrated into the target.////// Returns the reason if the branch is safe to delete:-/// - `NoMarginalContribution`: The branch has no marginal contribution to target (ancestor, merged back, etc.)+/// - `NoAddedChanges`: Branch has no file changes beyond merge-base (empty three-dot diff)/// - `ContentsMatch`: The branch's tree SHA matches the target's tree SHA (squash merge/rebase)/// - `MergeAddsNothing`: Merge simulation shows branch would add nothing (squash + target advanced)///@@ -72,13 +72,10 @@ fn get_integration_reason(branch_name: &str,target: &str,) -> Option<IntegrationReason> {- // Check if branch has no marginal contribution to target (covers ancestors and merged-back-to-base)- // On error, conservatively assume branch HAS marginal contribution (won't delete)- if !repo- .has_marginal_contribution(branch_name, target)- .unwrap_or(true)- {- return Some(IntegrationReason::NoMarginalContribution);+ // Check if branch has no file changes beyond merge-base (empty three-dot diff)+ // On error, conservatively assume branch HAS changes (won't delete)+ if !repo.has_added_changes(branch_name, target).unwrap_or(true) {+ return Some(IntegrationReason::NoAddedChanges);}// Check if tree content matches (handles squash merge/rebase)@@ -177,7 +174,7 @@ fn get_flag_note(} else if let Some(target) = target_branch {// Show integration reason when branch is deleted (both wt merge and wt remove)match deletion_result {- Some(Some(IntegrationReason::NoMarginalContribution)) => {+ Some(Some(IntegrationReason::NoAddedChanges)) => {format!(" (already in {target})")}Some(Some(IntegrationReason::ContentsMatch)) => format!(" (files match {target})"),diff --git a/tests/snapshots/integration__integration_tests__help__help_remove_long.snap b/tests/snapshots/integration__integration_tests__help__help_remove_long.snapindex cff68cdf1..97cb599fd 100644--- a/tests/snapshots/integration__integration_tests__help__help_remove_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_remove_long.snap@@ -74,11 +74,11 @@ Branches delete automatically when their content is already in the target branchA branch is safe to delete when its content is already reflected in the target. Worktrunk checks three conditions:-1. [1mBranch is ancestor[0m — Three-dot diff ([2mmain...branch[0m) shows no files. All commits on branch are reachable from main.+1. [1mNo added changes[0m — Three-dot diff ([2mmain...branch[0m) shows no files. The branch has no file changes beyond the merge-base.2. [1mTree contents match[0m — Branch tree SHA equals main tree SHA. Commit history differs but file contents are identical (e.g., after a revert or merge commit pulling in main).3. [1mMerge adds nothing[0m — Simulated merge ([2mgit merge-tree[0m) produces the same tree as main. Handles squash-merged branches where main has since advanced.-In [2mwt list[0m, [2m_[0m indicates condition 1 (no commits ahead) and [2m≡[0m indicates condition 2 (contents match). Rows with either are dimmed.+In [2mwt list[0m, [2m_[0m indicates no commits ahead of main, and [2m≡[0m indicates tree contents match. Branches showing either are dimmed as safe to delete.Use [2m-D[0m to force-delete branches with unmerged changes. Use [2m--no-delete-branch[0m to keep the branch regardless of status.