Skip to content

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

fix(config): keep config show --full working outside a git repository (#4255)

Worktrunk Botbbab727d7d05
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rs
index 29e34aae0..4dcbadff9 100644
--- a/src/commands/config/show.rs
+++ b/src/commands/config/show.rs
@@ -125,7 +125,7 @@ pub fn handle_config_show(full: bool, format: SwitchFormat) -> anyhow::Result<()
// Run full diagnostic checks if requested (includes slow network calls)
if full {
show_output.push('\n');
- render_diagnostics(&mut show_output)?;
+ render_diagnostics(&mut show_output, repo.as_ref())?;
}
// Render runtime info at the bottom (version, binary name, shell integration status)
@@ -555,14 +555,14 @@ fn render_runtime_info(out: &mut String) -> anyhow::Result<()> {
}
/// Run full diagnostic checks (CI tools, commit generation) and render to buffer
-fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {
+fn render_diagnostics(out: &mut String, repo: Option<&Repository>) -> anyhow::Result<()> {
writeln!(out, "{}", format_heading("DIAGNOSTICS", None))?;
// Check the CI tool for this repo's platform (configured forge platform,
- // else remote URL).
- let repo = Repository::current()?;
- match repo.ci_platform(None) {
- Some(ForgeKind::GitHub) => {
+ // else remote URL). Outside a repository there is no platform, so this
+ // falls through to the hint and the remaining checks still run.
+ match repo.and_then(|repo| Some((repo, repo.ci_platform(None)?))) {
+ Some((_, ForgeKind::GitHub)) => {
let ci_tools = CiToolsStatus::detect(None);
render_ci_tool_status(
out,
@@ -572,7 +572,7 @@ fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {
ci_tools.gh_authenticated,
)?;
}
- Some(ForgeKind::GitLab) => {
+ Some((_, ForgeKind::GitLab)) => {
let ci_tools = CiToolsStatus::detect(None);
render_ci_tool_status(
out,
@@ -582,7 +582,7 @@ fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {
ci_tools.glab_authenticated,
)?;
}
- Some(ForgeKind::Gitea) => {
+ Some((_, ForgeKind::Gitea)) => {
let ci_tools = CiToolsStatus::detect(None);
render_ci_tool_status(
out,
@@ -592,7 +592,7 @@ fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {
ci_tools.tea_authenticated,
)?;
}
- Some(ForgeKind::AzureDevOps) => {
+ Some((repo, ForgeKind::AzureDevOps)) => {
let ci_tools = CiToolsStatus::detect(None);
render_ci_tool_status(
out,
@@ -628,7 +628,7 @@ fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {
// Test commit generation - use effective config for current project
let config = UserConfig::load().context("Failed to load config")?;
- let project_id = repo.project_identifier().ok();
+ let project_id = repo.and_then(|repo| repo.project_identifier().ok());
let commit_config = config.commit_generation(project_id.as_deref());
if !commit_config.is_configured() {
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index 4887df954..044f2b59b 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -799,6 +799,38 @@ fn test_config_show_outside_git_repo(mut repo: TestRepo, temp_home: TempDir) {
});
}
+/// `--full` outside a repository still renders every section: the
+/// diagnostics skip the repo-specific CI check instead of failing the report.
+#[rstest]
+fn test_config_show_full_outside_git_repo(mut repo: TestRepo, temp_home: TempDir) {
+ let temp_dir = worktrunk::testing::test_tempdir();
+ repo.setup_mock_ci_tools_unauthenticated();
+
+ let mut cmd = wt_command();
+ repo.configure_mock_commands(&mut cmd);
+ cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"));
+ cmd.args(["config", "show", "--full"])
+ .current_dir(temp_dir.path());
+ set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
+
+ let output = cmd.output().unwrap();
+ let stdout = String::from_utf8_lossy(&output.stdout)
+ .ansi_strip()
+ .to_string();
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ output.status.success(),
+ "config show --full outside a repo failed: {stderr}"
+ );
+ assert!(stdout.contains("USER CONFIG"), "stdout: {stdout}");
+ assert!(stdout.contains("DIAGNOSTICS"), "stdout: {stdout}");
+ assert!(
+ stdout.contains("CI status requires"),
+ "outside a repo the CI check should fall back to its hint, stdout: {stdout}"
+ );
+}
+
#[rstest]
fn test_config_show_zsh_compinit_warning(mut repo: TestRepo, temp_home: TempDir) {
// Setup mock gh/glab for deterministic BINARIES output