Skip to content

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

fix(list): use --no-optional-locks for git status to avoid index lock contention (#513)

Maximilian Roos55223adbc57f
diff --git a/src/commands/list/collect_progressive_impl.rs b/src/commands/list/collect_progressive_impl.rs
index fccb0cf2d..b86efa49e 100644
--- a/src/commands/list/collect_progressive_impl.rs
+++ b/src/commands/list/collect_progressive_impl.rs
@@ -580,8 +580,10 @@ impl Task for WorkingTreeDiffTask {
fn compute(ctx: TaskContext) -> Result<TaskResult, TaskError> {
let repo = ctx.repo();
+ // Use --no-optional-locks to avoid index lock contention with WorkingTreeConflictsTask's
+ // `git stash create` which needs the index lock.
let status_output = repo
- .run_command(&["status", "--porcelain"])
+ .run_command(&["--no-optional-locks", "status", "--porcelain"])
.map_err(|e| ctx.error(Self::KIND, e))?;
let (working_tree_status, is_dirty, has_conflicts) =
@@ -645,9 +647,10 @@ impl Task for WorkingTreeConflictsTask {
let base = ctx.require_default_branch(Self::KIND)?;
let repo = ctx.repo();
- // Quick check if working tree is dirty via git status
+ // Use --no-optional-locks to avoid index lock contention with WorkingTreeDiffTask.
+ // Both tasks run in parallel, and `git stash create` below needs the index lock.
let status_output = repo
- .run_command(&["status", "--porcelain"])
+ .run_command(&["--no-optional-locks", "status", "--porcelain"])
.map_err(|e| ctx.error(Self::KIND, e))?;
let is_dirty = !status_output.trim().is_empty();
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index eaef4f641..aa22d27b0 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -2197,24 +2197,6 @@ fn test_list_full_working_tree_conflicts(mut repo: TestRepo) {
// Now add uncommitted changes to feature that would conflict with main
std::fs::write(feature.join("shared.txt"), "feature's uncommitted version").unwrap();
- // Wait for git to detect the file change (handles "racy git" timing issues where
- // file modification within the same timestamp granularity may not be detected)
- crate::common::wait_for("git to detect dirty working tree", || {
- // Refresh index to pick up mtime changes
- let _ = repo
- .git_command()
- .args(["update-index", "--refresh"])
- .current_dir(&feature)
- .output();
- // Check if git sees the change
- repo.git_command()
- .args(["status", "--porcelain"])
- .current_dir(&feature)
- .output()
- .map(|o| !o.stdout.is_empty())
- .unwrap_or(false)
- });
-
// Without --full: no conflict symbol (only checks commit-level)
assert_cmd_snapshot!(
"working_tree_conflicts_without_full",