Skip to content

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

feat: Add `base_branch` to all `collect` calls

Maximilian Roos278dfaa17dbb
diff --git a/.claude-plugin/skills/worktrunk/reference/README.md b/.claude-plugin/skills/worktrunk/reference/README.md
index f875a6787..a8b0f2e67 100644
--- a/.claude-plugin/skills/worktrunk/reference/README.md
+++ b/.claude-plugin/skills/worktrunk/reference/README.md
@@ -83,6 +83,7 @@ Worktrunk is opinionated! It's not designed to be all things to all people. The
- Shell navigation
- Commits are squashed into linear histories
- Maximum automation
+- Branches as handles, one branch per worktree
Adopting Worktrunk for a portion of a workflow doesn't require adopting it for
everything — standard `git worktree` commands continue working fine.
diff --git a/CLAUDE.md b/CLAUDE.md
index 0edafabea..d46fa632d 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -555,3 +555,9 @@ ANSI-formatted strings for human-readable output:
- `upstream_display`, `ci_status_display` (optional)
- `status_display`: rendered status symbols + user status
- `working_diff_display` (worktrees only, optional)
+
+## Worktree Model
+
+- Worktrees are **addressed by branch name**, not by filesystem path.
+- Each worktree should map to **exactly one branch**.
+- We **never retarget an existing worktree** to a different branch; instead create/switch/remove worktrees.
diff --git a/README.md b/README.md
index f875a6787..a8b0f2e67 100644
--- a/README.md
+++ b/README.md
@@ -83,6 +83,7 @@ Worktrunk is opinionated! It's not designed to be all things to all people. The
- Shell navigation
- Commits are squashed into linear histories
- Maximum automation
+- Branches as handles, one branch per worktree
Adopting Worktrunk for a portion of a workflow doesn't require adopting it for
everything — standard `git worktree` commands continue working fine.
diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rs
index 18664b531..4941c8108 100644
--- a/src/commands/list/collect.rs
+++ b/src/commands/list/collect.rs
@@ -206,6 +206,8 @@ fn determine_worktree_branch_state(
/// It will recompute with the latest available data.
///
/// Branches get a subset of status symbols (no working tree, git operation, or worktree attrs).
+// TODO(status-indicator): show a status glyph when a worktree's checked-out branch
+// differs from the branch name we associate with it (e.g., worktree exists but on another branch).
fn compute_item_status_symbols(
item: &mut ListItem,
base_branch: Option<&str>,
@@ -443,6 +445,7 @@ pub fn collect(
return Ok(None);
}
+ let base_branch = repo.default_branch()?;
let primary = worktrees.worktrees[0].clone();
let current_worktree_path = repo.worktree_root().ok();
@@ -620,21 +623,28 @@ pub fn collect(
// Create channel for cell updates
let (tx, rx) = chan::unbounded();
+ // Create collection options
+ let options = super::collect_progressive_impl::CollectOptions {
+ fetch_ci,
+ check_conflicts,
+ };
+
// Spawn worktree collection in background thread
let sorted_worktrees_clone = sorted_worktrees.clone();
- let primary_clone = primary.clone();
let tx_worktrees = tx.clone();
+ let base_branch_clone = base_branch.clone();
std::thread::spawn(move || {
sorted_worktrees_clone
.par_iter()
.enumerate()
.for_each(|(idx, wt)| {
+ // Always pass base_branch for ahead/behind/diff computation
+ // Status symbols will filter based on is_primary flag
super::collect_progressive_impl::collect_worktree_progressive(
wt,
- &primary_clone,
idx,
- fetch_ci,
- check_conflicts,
+ &base_branch_clone,
+ &options,
tx_worktrees.clone(),
);
});
@@ -643,8 +653,9 @@ pub fn collect(
// Spawn branch collection in background thread (if requested)
if show_branches {
let branches_clone = branches_without_worktrees.clone();
- let primary_clone = primary.clone();
+ let primary_path = primary.path.clone();
let tx_branches = tx.clone();
+ let base_branch_clone = base_branch.clone();
std::thread::spawn(move || {
branches_clone
.par_iter()
@@ -654,10 +665,10 @@ pub fn collect(
super::collect_progressive_impl::collect_branch_progressive(
branch_name,
commit_sha,
- &primary_clone,
+ &primary_path,
item_idx,
- fetch_ci,
- check_conflicts,
+ &base_branch_clone,
+ &options,
tx_branches.clone(),
);
});
@@ -671,15 +682,17 @@ pub fn collect(
let mut completed_cells = 0;
// Drain cell updates with conditional progressive rendering
- let base_branch = primary.branch.as_deref();
drain_cell_updates(
rx,
&mut all_items,
|item_idx, info, has_conflicts, user_status| {
// Compute/recompute status symbols as data arrives (both modes)
// This is idempotent and updates status as new data (like upstream) arrives
- // Base branch is None for primary worktree, Some(primary.branch) for others
- let item_base_branch = if info.is_primary() { None } else { base_branch };
+ let item_base_branch = if info.is_primary() {
+ None
+ } else {
+ Some(base_branch.as_str())
+ };
compute_item_status_symbols(info, item_base_branch, has_conflicts, user_status);
// Progressive mode only: update UI
diff --git a/src/commands/list/collect_progressive_impl.rs b/src/commands/list/collect_progressive_impl.rs
index 4e91d8559..fa6862ebe 100644
--- a/src/commands/list/collect_progressive_impl.rs
+++ b/src/commands/list/collect_progressive_impl.rs
@@ -18,6 +18,13 @@ use super::ci_status::PrStatus;
use super::collect::{CellUpdate, detect_worktree_state};
use super::model::{AheadBehind, BranchDiffTotals, CommitDetails, UpstreamStatus};
+/// Options for controlling what data to collect.
+#[derive(Clone, Copy)]
+pub struct CollectOptions {
+ pub fetch_ci: bool,
+ pub check_conflicts: bool,
+}
+
/// Context for spawning parallel tasks.
struct TaskContext {
repo_path: PathBuf,
@@ -312,22 +319,16 @@ fn spawn_ci_status<'scope>(
/// Errors are handled with TODO for simplicity (simplest thing for now).
pub fn collect_worktree_progressive(
wt: &Worktree,
- primary: &Worktree,
item_idx: usize,
- fetch_ci: bool,
- check_conflicts: bool,
+ base_branch: &str,
+ options: &CollectOptions,
tx: Sender<CellUpdate>,
) {
- let base_branch = primary
- .branch
- .as_deref()
- .filter(|_| wt.path != primary.path);
-
let ctx = TaskContext {
repo_path: wt.path.clone(),
commit_sha: wt.head.clone(),
branch: wt.branch.clone(),
- base_branch: base_branch.map(String::from),
+ base_branch: Some(base_branch.to_string()),
item_idx,
};
@@ -336,11 +337,11 @@ pub fn collect_worktree_progressive(
spawn_ahead_behind(s, &ctx, tx.clone());
spawn_branch_diff(s, &ctx, tx.clone());
spawn_working_tree_diff(s, &ctx, tx.clone());
- spawn_conflicts(s, &ctx, check_conflicts, true, tx.clone());
+ spawn_conflicts(s, &ctx, options.check_conflicts, true, tx.clone());
spawn_worktree_state(s, &ctx, tx.clone());
spawn_user_status(s, &ctx, tx.clone());
spawn_upstream(s, &ctx, true, tx.clone());
- spawn_ci_status(s, &ctx, fetch_ci, tx);
+ spawn_ci_status(s, &ctx, options.fetch_ci, tx);
});
}
@@ -418,17 +419,17 @@ fn parse_status_for_symbols(status_output: &str) -> (String, bool) {
pub fn collect_branch_progressive(
branch_name: &str,
commit_sha: &str,
- primary: &Worktree,
+ repo_path: &std::path::Path,
item_idx: usize,
- fetch_ci: bool,
- check_conflicts: bool,
+ base_branch: &str,
+ options: &CollectOptions,
tx: Sender<CellUpdate>,
) {
let ctx = TaskContext {
- repo_path: primary.path.clone(),
+ repo_path: repo_path.to_path_buf(),
commit_sha: commit_sha.to_string(),
branch: Some(branch_name.to_string()),
- base_branch: primary.branch.as_deref().map(String::from),
+ base_branch: Some(base_branch.to_string()),
item_idx,
};
@@ -437,7 +438,7 @@ pub fn collect_branch_progressive(
spawn_ahead_behind(s, &ctx, tx.clone());
spawn_branch_diff(s, &ctx, tx.clone());
spawn_upstream(s, &ctx, false, tx.clone());
- spawn_conflicts(s, &ctx, check_conflicts, false, tx.clone());
- spawn_ci_status(s, &ctx, fetch_ci, tx);
+ spawn_conflicts(s, &ctx, options.check_conflicts, false, tx.clone());
+ spawn_ci_status(s, &ctx, options.fetch_ci, tx);
});
}
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index 60d84b689..e1d0a4336 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -90,9 +90,13 @@ pub fn handle_merge(
// Get target branch (default to default branch if not provided)
let target_branch = repo.resolve_target_branch(target)?;
+ let worktrees = repo.list_worktrees()?;
+ // Worktree for target is optional: if present we use it for safety checks and as destination.
+ let target_worktree_path = repo.worktree_for_branch(&target_branch)?;
- // When current == target, force --no-remove (can't remove the worktree we're on)
- let no_remove_effective = no_remove || current_branch == target_branch;
+ // When current == target or we're in the primary worktree, force --no-remove (can't remove it)
+ let in_primary = !repo.is_in_worktree().unwrap_or(false);
+ let no_remove_effective = no_remove || current_branch == target_branch || in_primary;
// Collect and approve all commands upfront for batch permission request
let (all_commands, project_id) = MergeCommandCollector {
@@ -172,16 +176,10 @@ pub fn handle_merge(
}),
)?;
- // Get primary worktree path before cleanup (while we can still run git commands)
- let worktrees = repo.list_worktrees()?;
- let primary_worktree_dir = worktrees.worktrees[0].path.clone();
-
- // Determine destination: target branch's worktree if it exists, otherwise primary worktree
- let target_worktree_path = repo.worktree_for_branch(&target_branch)?;
+ // Destination: prefer the target branch's worktree; fall back to primary when absent
let destination_path = target_worktree_path
- .as_ref()
- .unwrap_or(&primary_worktree_dir)
- .clone();
+ .clone()
+ .unwrap_or_else(|| worktrees.worktrees[0].path.clone());
// Finish worktree unless --no-remove was specified
if !no_remove_effective {
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index eb74d3217..20c6d6701 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -247,7 +247,7 @@ pub fn handle_switch(
None => {}
}
- // No existing worktree, create one
+ // No existing worktree, create one (or reuse target path if available)
let repo_root = repo.worktree_base()?;
let repo_name = repo_root
@@ -262,6 +262,20 @@ pub fn handle_switch(
.map_err(|e| GitError::message(format!("Failed to format worktree path: {}", e)))?,
);
+ // If the target path already exists but no worktree is registered for this branch,
+ // surface a helpful error instead of letting git fail with "already exists".
+ if repo.worktree_for_branch(&resolved_branch)?.is_none() && worktree_path.exists() {
+ let occupant = Repository::at(&worktree_path)
+ .current_branch()
+ .ok()
+ .flatten();
+ return Err(GitError::WorktreePathOccupied {
+ branch: resolved_branch.clone(),
+ path: worktree_path.clone(),
+ occupant,
+ });
+ }
+
// Create the worktree
// Build git worktree add command
let mut args = vec!["worktree", "add", worktree_path.to_str().unwrap()];
@@ -474,6 +488,11 @@ pub fn handle_push(
// Get target branch (default to default branch if not provided)
let target_branch = repo.resolve_target_branch(target)?;
+ // A worktree for the target branch is optional for push:
+ // - If present, we use it to check for overlapping dirty files.
+ // - If absent, we skip that safety step but still allow the push (git itself is fine).
+ let target_worktree_path = repo.worktree_for_branch(&target_branch)?;
+
// Check if it's a fast-forward
if !repo.is_ancestor(&target_branch, "HEAD")? {
// Get formatted commit log (commits in target that we don't have)
@@ -522,9 +541,8 @@ pub fn handle_push(
}
// Check for conflicting changes in target worktree (auto-stash safe changes)
- let target_worktree = repo.worktree_for_branch(&target_branch)?;
let mut target_worktree_stash =
- repo.prepare_target_worktree(target_worktree.as_ref(), &target_branch)?;
+ repo.prepare_target_worktree(target_worktree_path.as_ref(), &target_branch)?;
// Count commits and show what will be pushed
let commit_count = repo.count_commits(&target_branch, "HEAD")?;
diff --git a/src/git/error.rs b/src/git/error.rs
index e884b3f30..65df10910 100644
--- a/src/git/error.rs
+++ b/src/git/error.rs
@@ -30,6 +30,12 @@ pub enum GitError {
WorktreeMissing { branch: String },
/// No worktree found for branch
NoWorktreeFound { branch: String },
+ /// Expected branch has no worktree and its target path is already used by another branch
+ WorktreePathOccupied {
+ branch: String,
+ path: PathBuf,
+ occupant: Option<String>,
+ },
/// Cannot push due to conflicting uncommitted changes
ConflictingChanges {
files: Vec<String>,
@@ -172,6 +178,23 @@ impl std::fmt::Display for GitError {
)
}
+ GitError::WorktreePathOccupied {
+ branch,
+ path,
+ occupant,
+ } => {
+ let occupant_note = occupant
+ .as_ref()
+ .map(|b| format!(" (currently on {ERROR_BOLD}{b}{ERROR_BOLD:#})"))
+ .unwrap_or_default();
+ write!(
+ f,
+ "{ERROR_EMOJI} {ERROR}Cannot create worktree for {ERROR_BOLD}{branch}{ERROR_BOLD:#}{ERROR}: target path already exists{ERROR:#}\n\n{HINT_EMOJI} {HINT}Reuse the existing worktree at {}{} or remove it before retrying{HINT:#}",
+ format_path_for_display(path),
+ occupant_note
+ )
+ }
+
// Conflicting changes
GitError::ConflictingChanges {
files,
diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rs
index 3e9663be1..995846f47 100644
--- a/src/git/repository/mod.rs
+++ b/src/git/repository/mod.rs
@@ -373,16 +373,7 @@ impl Repository {
return Ok(branches[0].clone());
}
- // 2. Use the branch HEAD points to (from main worktree)
- // This is what the main worktree is currently on
- if let Ok(current) = self.run_command(&["symbolic-ref", "--short", "HEAD"]) {
- let branch = current.trim().to_string();
- if !branch.is_empty() {
- return Ok(branch);
- }
- }
-
- // 3. Check git config init.defaultBranch
+ // 2. Check git config init.defaultBranch
if let Ok(default) = self.run_command(&["config", "--get", "init.defaultBranch"]) {
let branch = default.trim().to_string();
if !branch.is_empty() && branches.contains(&branch) {
@@ -390,14 +381,14 @@ impl Repository {
}
}
- // 4. Look for common branch names
+ // 3. Look for common branch names
for name in ["main", "master", "develop", "trunk"] {
if branches.contains(&name.to_string()) {
return Ok(name.to_string());
}
}
- // 5. Give up - can't infer
+ // 4. Give up - can't infer
Err(GitError::CommandFailed(
"Could not infer default branch. Please specify target branch explicitly or set up a remote.".to_string()
))
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index 8e476a47e..b18b5ced6 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -1742,3 +1742,13 @@ fn test_list_maximum_status_symbols() {
assert_cmd_snapshot!("maximum_status_symbols", cmd);
});
}
+
+#[test]
+fn test_list_warns_when_default_branch_missing_worktree() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ // Move primary worktree off the default branch so no worktree holds it
+ repo.switch_primary_to("develop");
+
+ snapshot_list("default_branch_missing_worktree", &repo);
+}
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index 4ebe2c859..33e3e5e75 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -78,6 +78,45 @@ fn test_merge_fast_forward() {
snapshot_merge("merge_fast_forward", &repo, &["main"], Some(&feature_wt));
}
+#[test]
+fn test_merge_when_primary_not_on_default_but_default_has_worktree() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ repo.setup_remote("main");
+
+ // Move the primary worktree off main
+ repo.switch_primary_to("develop");
+
+ // Ensure main still has a worktree (secondary)
+ let _main_wt = repo.add_main_worktree();
+
+ // Create a feature worktree and commit
+ let feature_wt = repo.add_worktree("feature", "feature");
+ std::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 file"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ snapshot_merge(
+ "merge_when_primary_not_on_default_but_default_has_worktree",
+ &repo,
+ &["main"],
+ Some(&feature_wt),
+ );
+}
+
#[test]
fn test_merge_with_no_remove_flag() {
let mut repo = TestRepo::new();
@@ -2884,3 +2923,13 @@ fn test_merge_squash_with_working_tree_creates_backup() {
reflog
);
}
+
+#[test]
+fn test_merge_when_default_branch_missing_worktree() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ // Move primary off default branch so no worktree holds it
+ repo.switch_primary_to("develop");
+
+ snapshot_merge("merge_default_branch_missing_worktree", &repo, &[], None);
+}
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__bare_repository__bare_repo_list_worktrees.snap b/tests/integration_tests/snapshots/integration__integration_tests__bare_repository__bare_repo_list_worktrees.snap
index 6b04798cc..cbbaabc35 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__bare_repository__bare_repo_list_worktrees.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__bare_repository__bare_repo_list_worktrees.snap
@@ -9,12 +9,11 @@ info:
COLUMNS: "150"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
NO_COLOR: ""
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpkoXSyA/test-config.toml
+ WORKTRUNK_CONFIG: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpgORGdp/test-config.toml
---
success: true
exit_code: 0
@@ -22,7 +21,7 @@ exit_code: 0
----- stderr -----
Branch Status HEAD± main↕ Path Remote⇅ Commit Age Message
-feature ./test-repo.feature 72413a3b 10 months ago Work on feature
-main ∅ ↓ ↓1 ./test-repo.main 6c3da842 10 months ago Initial commit on main
+feature ↑ ./test-repo.feature 72413a3b 10 months ago Work on feature
+main ≡ ./test-repo.main 6c3da842 10 months ago Initial commit on main
-⚪ Showing 2 worktrees
+⚪ Showing 2 worktrees, 1 ahead
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index 5af8c23ab..8123d6f04 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -535,3 +535,14 @@ fn test_create_with_base_main() {
&["--create", "new-feature", "--base", "^"],
);
}
+
+#[test]
+fn test_switch_default_branch_missing_worktree() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Move the primary worktree off the default branch so no worktree holds it
+ repo.switch_primary_to("develop");
+
+ snapshot_switch("switch_default_branch_missing_worktree", &repo, &["main"]);
+}
diff --git a/tests/snapshots/integration__integration_tests__list__default_branch_missing_worktree.snap b/tests/snapshots/integration__integration_tests__list__default_branch_missing_worktree.snap
new file mode 100644
index 000000000..49a1d9cf1
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__list__default_branch_missing_worktree.snap
@@ -0,0 +1,31 @@
+---
+source: tests/integration_tests/list.rs
+info:
+ program: wt
+ args:
+ - list
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_COUNT: "1"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_KEY_0: advice.mergeConflict
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_CONFIG_VALUE_0: "false"
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpNVebpx/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+Branch Status HEAD± main↕ Path Remote⇅ Commit Age Message
+develop . b834638e 10 months ago Initial commit
+
+⚪ Showing 1 worktree
diff --git a/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snap b/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snap
index 2d3f9fb5b..f96471045 100644
--- a/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snap
+++ b/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snap
@@ -10,13 +10,16 @@ info:
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_COUNT: "1"
GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_KEY_0: advice.mergeConflict
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_CONFIG_VALUE_0: "false"
GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpwJxOR9/test-config.toml
---
success: true
exit_code: 0
@@ -27,6 +30,12 @@ exit_code: 0
"branch": "main",
"timestamp": 0,
"commit_message": "Main commit 2",
+ "ahead": 0,
+ "behind": 0,
+ "branch_diff": {
+ "added": 0,
+ "deleted": 0
+ },
"upstream_remote": null,
"upstream_ahead": 0,
"upstream_behind": 0,
diff --git a/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap b/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap
index f8c19eb37..f5061484d 100644
--- a/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap
+++ b/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap
@@ -10,13 +10,16 @@ info:
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_COUNT: "1"
GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_KEY_0: advice.mergeConflict
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_CONFIG_VALUE_0: "false"
GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpsNi9Qf/test-config.toml
---
success: true
exit_code: 0
@@ -27,6 +30,12 @@ exit_code: 0
"branch": "main",
"timestamp": 0,
"commit_message": "Initial commit",
+ "ahead": 0,
+ "behind": 0,
+ "branch_diff": {
+ "added": 0,
+ "deleted": 0
+ },
"upstream_remote": null,
"upstream_ahead": 0,
"upstream_behind": 0,
diff --git a/tests/snapshots/integration__integration_tests__list__json_with_user_status.snap b/tests/snapshots/integration__integration_tests__list__json_with_user_status.snap
index 95978c4b1..7e4f4f453 100644
--- a/tests/snapshots/integration__integration_tests__list__json_with_user_status.snap
+++ b/tests/snapshots/integration__integration_tests__list__json_with_user_status.snap
@@ -10,13 +10,16 @@ info:
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_COUNT: "1"
GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_KEY_0: advice.mergeConflict
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_CONFIG_VALUE_0: "false"
GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpKOi1g7/test-config.toml
---
success: true
exit_code: 0
@@ -27,6 +30,12 @@ exit_code: 0
"branch": "main",
"timestamp": 0,
"commit_message": "Initial commit",
+ "ahead": 0,
+ "behind": 0,
+ "branch_diff": {
+ "added": 0,
+ "deleted": 0
+ },
"upstream_remote": null,
"upstream_ahead": 0,
"upstream_behind": 0,
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_default_branch_missing_worktree.snap b/tests/snapshots/integration__integration_tests__merge__merge_default_branch_missing_worktree.snap
new file mode 100644
index 000000000..67b25f328
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__merge__merge_default_branch_missing_worktree.snap
@@ -0,0 +1,28 @@
+---
+source: tests/integration_tests/merge.rs
+info:
+ program: wt
+ args:
+ - merge
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_COUNT: "1"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_KEY_0: advice.mergeConflict
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_CONFIG_VALUE_0: "false"
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmprsBxfk/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+✅ Merged to main (no new commits, no rebase needed)
+✅ Worktree preserved (--no-remove)
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap
index 252389a3d..3d8d23830 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap
@@ -9,8 +9,11 @@ info:
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_COUNT: "1"
GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_KEY_0: advice.mergeConflict
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_CONFIG_VALUE_0: "false"
GIT_EDITOR: ""
LANG: C
LC_ALL: C
@@ -20,7 +23,12 @@ info:
success: true
exit_code: 0
----- stdout -----
-✅ Merged to feature (no new commits, no rebase needed)
-✅ Worktree preserved (--no-remove)
+🔄 Merging 1 commit to main @ [SHA] (no commit/squash/rebase needed)
+  * [SHA] (HEAD -> feature) Add feature file
+  feature.txt | 1 +
+  1 file changed, 1 insertion(+)
+✅ Merged to main (1 commit, 1 file, +1)
+🔄 Removing worktree & branch...
+✅ Removed worktree & branch for feature, changed directory to [REPO]
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_when_primary_not_on_default_but_default_has_worktree.snap b/tests/snapshots/integration__integration_tests__merge__merge_when_primary_not_on_default_but_default_has_worktree.snap
new file mode 100644
index 000000000..122dd5c20
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__merge__merge_when_primary_not_on_default_but_default_has_worktree.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/merge.rs
+assertion_line: 12
+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_COUNT: "1"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_KEY_0: advice.mergeConflict
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_CONFIG_VALUE_0: "false"
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmplZVJ0R/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+🔄 Merging 1 commit to main @ [SHA] (no commit/squash/rebase needed)
+  * [SHA] (HEAD -> feature) Add feature file
+  feature.txt | 1 +
+  1 file changed, 1 insertion(+)
+✅ Merged to main (1 commit, 1 file, +1)
+🔄 Removing worktree & branch...
+✅ Removed worktree & branch for feature, changed directory to [REPO].main-wt
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__push__push_no_remote.snap b/tests/snapshots/integration__integration_tests__push__push_no_remote.snap
index d1cbea7ad..8da9736e5 100644
--- a/tests/snapshots/integration__integration_tests__push__push_no_remote.snap
+++ b/tests/snapshots/integration__integration_tests__push__push_no_remote.snap
@@ -10,8 +10,11 @@ info:
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_COUNT: "1"
GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_KEY_0: advice.mergeConflict
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_CONFIG_VALUE_0: "false"
GIT_EDITOR: ""
LANG: C
LC_ALL: C
@@ -21,6 +24,10 @@ info:
success: true
exit_code: 0
----- stdout -----
-✅ Pushed to feature
+🔄 Pushing 1 commit to main @ [SHA]
+  * [SHA] (HEAD -> feature) Add feature file
+  feature.txt | 1 +
+  1 file changed, 1 insertion(+)
+✅ Pushed to main (1 commit, 1 file, +1)
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_default_branch_missing_worktree.snap b/tests/snapshots/integration__integration_tests__switch__switch_default_branch_missing_worktree.snap
new file mode 100644
index 000000000..62c4d2cdc
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_default_branch_missing_worktree.snap
@@ -0,0 +1,30 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - 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_COUNT: "1"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_KEY_0: advice.mergeConflict
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_CONFIG_VALUE_0: "false"
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+✅ Switched to worktree for main at [REPO].main
+💡 To enable automatic cd, run: wt config shell
+
+----- stderr -----