Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(picker): apply per-project pager override to the diff preview (#4398)
Worktrunk Bot3ad9dd9830f1
diff --git a/src/commands/picker/items.rs b/src/commands/picker/items.rsindex d6bcf86b9..fbd27c6d9 100644--- a/src/commands/picker/items.rs+++ b/src/commands/picker/items.rs@@ -1360,20 +1360,33 @@ impl PickerRow {) -> (String, bool) {match mode {PreviewMode::UnifiedDiff => (- Self::page_diff(Self::compute_unified_diff_preview(repo, item, width), width),+ Self::page_diff(+ repo,+ Self::compute_unified_diff_preview(repo, item, width),+ width,+ ),false,),PreviewMode::WorkingTree => (- Self::page_diff(Self::compute_working_tree_preview(repo, item, width), width),+ Self::page_diff(+ repo,+ Self::compute_working_tree_preview(repo, item, width),+ width,+ ),false,),PreviewMode::Log => Self::compute_log_preview(repo, item, width, height),PreviewMode::BranchDiff => (- Self::page_diff(Self::compute_branch_diff_preview(repo, item, width), width),+ Self::page_diff(+ repo,+ Self::compute_branch_diff_preview(repo, item, width),+ width,+ ),false,),PreviewMode::UpstreamDiff => (Self::page_diff(+ repo,Self::compute_upstream_diff_preview(repo, item, width),width,),@@ -1389,8 +1402,8 @@ impl PickerRow {}}- fn page_diff(content: String, width: usize) -> String {- if let Some(pager_cmd) = diff_pager() {+ fn page_diff(repo: &Repository, content: String, width: usize) -> String {+ if let Some(pager_cmd) = diff_pager(repo) {pipe_through_pager(&content, pager_cmd, width)} else {contentdiff --git a/src/commands/picker/pager.rs b/src/commands/picker/pager.rsindex ab63656bb..9f320e76b 100644--- a/src/commands/picker/pager.rs+++ b/src/commands/picker/pager.rs@@ -13,7 +13,7 @@ use std::time::{Duration, Instant};use shared_child::SharedChild;-use worktrunk::config::UserConfig;+use worktrunk::git::Repository;use worktrunk::shell::extract_filename_from_path;use crate::pager::git_pager;@@ -45,20 +45,21 @@ fn needs_paging_disabled(pager_cmd: &str) -> bool {////// Returns the pager command with any necessary flags (like `--paging=never`)/// already appended. Precedence:-/// 1. `[switch.picker] pager` in user config (used as-is)-/// 2. `[select] pager` in user config (deprecated, used as-is)-/// 3. `GIT_PAGER` environment variable (auto-detection applied)-/// 4. `core.pager` git config (auto-detection applied)-pub(super) fn diff_pager() -> Option<&'static String> {+/// 1. `[switch.picker] pager` in user config, with any `[projects."<id>"]`+/// override for `repo` applied (used as-is). A deprecated `[select] pager`+/// is migrated into `[switch.picker]` before the config parses.+/// 2. `GIT_PAGER` environment variable (auto-detection applied)+/// 3. `core.pager` git config (auto-detection applied)+///+/// The cache is process-wide: the picker runs against one repository.+pub(super) fn diff_pager(repo: &Repository) -> Option<&'static String> {CACHED_PAGER.get_or_init(|| {- // Check user config first - use exactly as specified (no auto-detection)- // Uses switch_picker() accessor which handles [switch.picker] → [select] fallback- if let Ok(config) = UserConfig::load()- && let Some(pager) = config.switch_picker(None).pager+ // Configured pager first - use exactly as specified (no auto-detection)+ if let Some(pager) = repo.config().switch_picker.pager()&& !pager.trim().is_empty(){- return Some(pager);+ return Some(pager.to_string());}// GIT_PAGER or core.pager - apply auto-detection for delta/bat@@ -220,13 +221,6 @@ mod tests {assert!(needs_paging_disabled("Delta.EXE"));}- #[test]- fn test_get_diff_pager_initializes() {- // Exercise the config initialization path- // Returns None or Some depending on user's pager config- let _ = diff_pager();- }-#[test]fn test_pipe_through_pager_passthrough() {// Use cat as a simple pager that passes through input unchangeddiff --git a/tests/integration_tests/switch_picker.rs b/tests/integration_tests/switch_picker.rsindex 657ed58c1..2b9427a8f 100644--- a/tests/integration_tests/switch_picker.rs+++ b/tests/integration_tests/switch_picker.rs@@ -1067,6 +1067,54 @@ fn test_switch_picker_preview_navigation_and_log_panel(mut repo: TestRepo) {});}+/// A `[projects."<id>".switch.picker] pager` override reaches the diff preview.+/// The picker used to resolve the pager with no project, so only the global+/// `[switch.picker]` setting took effect.+#[rstest]+fn test_switch_picker_project_pager_override(mut repo: TestRepo) {+ repo.run_git(&["remote", "remove", "origin"]);+ let feature_path = repo.add_worktree("feature");+ std::fs::write(feature_path.join("file.txt"), "content\n").unwrap();+ repo.run_git_in(&feature_path, &["add", "file.txt"]);+ repo.run_git_in(+ &feature_path,+ &["commit", "-m", "Commit for pager override"],+ );+ seed_ci_status(&repo, "feature", "null");++ repo.write_test_config(&format!(+ r#"[projects.'{}'.switch.picker]+pager = 'echo PROJECT-PAGER; cat'+"#,+ repo.project_id()+ ));++ let env_vars = repo.test_env_vars();+ let PickerSession {+ child,+ _master,+ writer,+ rx,+ mut parser,+ } = boot_picker_pty(+ wt_bin().to_str().unwrap(),+ &["switch"],+ repo.root_path(),+ &env_vars,+ );++ send_input_awaiting_content(&writer, &rx, &mut parser, "\x1b[B", Some("feature"));+ wait_for_stable_with_content(&rx, &mut parser, Some("PROJECT-PAGER"));+ let preview = preview_pane_text(parser.screen());+ let exit_code = abort_and_exit_code(child, writer, rx);+ assert_valid_abort_exit_code(exit_code);++ assert!(+ preview.contains("PROJECT-PAGER"),+ "the project-scoped pager should page the diff preview:\n{preview}"+ );+}+/// The completed diff proves pager selection has finished before checking that/// an interactive fallback was not launched. All cases run from outside -C.#[cfg(unix)]