Skip to content

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

Prioritize current worktree in list output

Maximilian Roosde7cc4a3fdfa
diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rs
index 65f45b3ea..1ed863186 100644
--- a/src/commands/list/collect.rs
+++ b/src/commands/list/collect.rs
@@ -322,7 +322,7 @@ pub fn collect(
let current_worktree_path = repo.worktree_root().ok();
let previous_branch = repo.get_switch_history().and_then(|h| h.previous);
- // Sort worktrees: main first, current second, then by timestamp descending
+ // Sort worktrees: current first, main second, then by timestamp descending
let sorted_worktrees = sort_worktrees(
worktrees.worktrees.clone(),
&main_worktree,
@@ -708,7 +708,7 @@ where
indexed.into_iter().map(|(_, item)| item).collect()
}
-/// Sort worktrees: main first, current second, then by timestamp descending.
+/// Sort worktrees: current first, main second, then by timestamp descending.
fn sort_worktrees(
worktrees: Vec<Worktree>,
main_worktree: &Worktree,
@@ -725,10 +725,10 @@ fn sort_worktrees(
let mut indexed: Vec<_> = worktrees.into_iter().enumerate().collect();
indexed.sort_by_key(|(idx, wt)| {
- let priority = if wt.path == main_worktree.path {
- 0 // Main first
- } else if current_path.map(|cp| &wt.path == cp).unwrap_or(false) {
- 1 // Current second
+ let priority = if current_path.map(|cp| &wt.path == cp).unwrap_or(false) {
+ 0 // Current first
+ } else if wt.path == main_worktree.path {
+ 1 // Main second
} else {
2 // Rest by timestamp
};
diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rs
index bb6ed6c72..516f652cb 100644
--- a/src/commands/list/mod.rs
+++ b/src/commands/list/mod.rs
@@ -19,7 +19,7 @@
//! - Refresh with `wt config cache refresh`
//!
//! 3. **Sort worktrees** (<1ms)
-//! - Orders by: current → main → rest alphabetically
+//! - Orders by: current → main → rest by timestamp (most recent first)
//! - Pure Rust, no git calls
//!
//! 4. **Branch listing** (only with `--branches`, ~10-30ms)
diff --git a/src/commands/select.rs b/src/commands/select.rs
index 4cdf634f6..f0339d19f 100644
--- a/src/commands/select.rs
+++ b/src/commands/select.rs
@@ -496,9 +496,6 @@ pub fn handle_select(is_directive_mode: bool) -> anyhow::Result<()> {
return Ok(());
};
- // Get current worktree path for styling
- let _current_worktree_path = repo.worktree_root().ok();
-
// Use the same layout system as `wt list` for proper column alignment
// Skim uses ~50% of terminal width for the list (rest is preview), so calculate
// layout based on available width to avoid truncation
diff --git a/tests/snapshots/integration__integration_tests__list__list_ordering_rules.snap b/tests/snapshots/integration__integration_tests__list__list_ordering_rules.snap
index aa9076884..6e9580db4 100644
--- a/tests/snapshots/integration__integration_tests__list__list_ordering_rules.snap
+++ b/tests/snapshots/integration__integration_tests__list__list_ordering_rules.snap
@@ -24,8 +24,8 @@ exit_code: 0
----- stderr -----
Branch Status HEAD± main↕ Path Remote⇅ Commit Age Message
-^ main ^ ./repo 6c3da842 1d Initial commit on main
@ feature-current ↑ ↑1 ./repo.feature-current fc28a4d1 23h Commit at 01:00
+^ main ^ ./repo 6c3da842 1d Initial commit on main
+ feature-newest ↑ ↑1 ./repo.feature-newest 136358eb 21h Commit at 03:00
+ feature-middle ↑ ↑1 ./repo.feature-middle a0a4851a 22h Commit at 02:00
+ feature-oldest ↑ ↑1 ./repo.feature-oldest 1b1a2d78 23h Commit at 00:30
diff --git a/tests/snapshots/integration__integration_tests__list__task_dag_ordering_stability.snap b/tests/snapshots/integration__integration_tests__list__task_dag_ordering_stability.snap
index 08c1b091e..ebbdcec92 100644
--- a/tests/snapshots/integration__integration_tests__list__task_dag_ordering_stability.snap
+++ b/tests/snapshots/integration__integration_tests__list__task_dag_ordering_stability.snap
@@ -25,8 +25,8 @@ exit_code: 0
----- stderr -----
Branch Status HEAD± main↕ Path Remote⇅ Commit Age Message
-^ main ^ ./repo 6c3da842 1d Initial commit on main
@ feature-current ↑ ↑1 ./repo.feature-current fc28a4d1 23h Commit at 01:00
+^ main ^ ./repo 6c3da842 1d Initial commit on main
+ feature-newest ↑ ↑1 ./repo.feature-newest 136358eb 21h Commit at 03:00
+ feature-middle ↑ ↑1 ./repo.feature-middle a0a4851a 22h Commit at 02:00
+ feature-oldest ↑ ↑1 ./repo.feature-oldest 1b1a2d78 23h Commit at 00:30