Skip to content

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

fix(relocate): count template-error branches in human skip summary (#3688)

Worktrunk Botf316b0cf7bdd
diff --git a/src/commands/step/relocate.rs b/src/commands/step/relocate.rs
index 853b887b4..b91b59b5a 100644
--- a/src/commands/step/relocate.rs
+++ b/src/commands/step/relocate.rs
@@ -124,7 +124,9 @@ pub fn step_relocate(
all_skipped.extend(validation_skipped);
print_relocate_json(&[], &all_skipped, false)?;
} else {
- show_all_skipped(validation_skipped.len());
+ // Include template-error branches — the JSON path folds them into
+ // `all_skipped`, so the human count must match.
+ show_all_skipped(validation_skipped.len() + template_skips.len());
}
return Ok(());
}
@@ -149,7 +151,10 @@ pub fn step_relocate(
all_skipped.extend(executor.skipped_entries);
print_relocate_json(&relocated_views, &all_skipped, false)?;
} else {
- let total_skipped = validation_skipped.len() + executor.skipped_count();
+ // Template-error branches count as skips too — the JSON path folds
+ // them into `all_skipped`, so keep the human total consistent.
+ let total_skipped =
+ template_skips.len() + validation_skipped.len() + executor.skipped_count();
show_summary(executor.relocated_count(), total_skipped);
}
diff --git a/tests/integration_tests/step_relocate.rs b/tests/integration_tests/step_relocate.rs
index 6266e3822..952cb0406 100644
--- a/tests/integration_tests/step_relocate.rs
+++ b/tests/integration_tests/step_relocate.rs
@@ -1057,6 +1057,59 @@ worktree-path = "{{ nonexistent_variable }}"
);
}
+/// Regression test: the human-readable summary count must include
+/// template-error branches, matching the `--format=json` skip set.
+///
+/// When a valid candidate and a template-error branch coexist, the JSON path
+/// folds template errors into `all_skipped` but the human summary previously
+/// counted only validation/executor skips, undercounting by the number of
+/// template errors. The template here fails only for branch `bad` (via a
+/// branch-gated undefined variable) while `good` expands cleanly, so relocate
+/// moves `good` and skips `bad`.
+#[rstest]
+fn test_relocate_template_error_counted_in_summary(repo: TestRepo) {
+ let parent = worktree_parent(&repo);
+
+ // `good`: a mismatched worktree that will relocate successfully.
+ let good_wrong = parent.join("good-wrong");
+ repo.run_git(&[
+ "worktree",
+ "add",
+ "-b",
+ "good",
+ good_wrong.to_str().unwrap(),
+ ]);
+ // `bad`: a worktree whose template expansion fails.
+ let bad_path = parent.join("bad-loc");
+ repo.run_git(&["worktree", "add", "-b", "bad", bad_path.to_str().unwrap()]);
+
+ // Template errors only for branch `bad`; `good` renders the standard path.
+ let worktrunk_config = "worktree-path = \"{% if branch == 'bad' %}{{ undefined_var }}{% endif %}{{ repo_path }}/../{{ repo }}.{{ branch }}\"\n";
+ fs::write(repo.test_config_path(), worktrunk_config).unwrap();
+
+ let output = repo
+ .wt_command()
+ .args(["step", "relocate"])
+ .output()
+ .unwrap();
+ assert!(output.status.success(), "relocate should succeed");
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ stderr.contains("Relocated 1 worktree, skipped 1 worktree"),
+ "summary must count the template-error branch as skipped; stderr was:\n{stderr}"
+ );
+
+ // `good` relocated to its expected sibling path; `bad` untouched.
+ assert!(
+ parent.join("repo.good").exists(),
+ "good should have relocated"
+ );
+ assert!(
+ bad_path.exists(),
+ "bad should be untouched (template error)"
+ );
+}
+
/// Regression test: main worktree relocation must surface a failed
/// `git checkout <default_branch>` rather than silently claiming success.
///