Skip to content

fix: propagate error from is_bare() instead of panicking - #1221

Merged
max-sixty merged 1 commit into
max-sixty:mainfrom
bendrucker:git-timeout-panic
Feb 27, 2026
Merged

max-sixty merged 1 commit into
max-sixty:mainfrom
bendrucker:git-timeout-panic

Conversation

@bendrucker

@bendrucker bendrucker commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

is_bare() panics when git rev-parse --is-bare-repository times out because it uses .expect() on the Cmd::run() result. This changes the return type to Result<bool> so the error propagates instead.

I don't know why git was slow in this case, but it was:

thread '<unnamed>' (84001037) panicked at src/git/repository/mod.rs:459:18:
git rev-parse failed on valid repo: Custom { kind: TimedOut, error: "command timed out" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Rayon: detected unexpected panic; aborting

Changes

  • is_bare() returns Result<bool> using get_or_try_init (doesn't cache errors, so transient timeouts retry on next call)
  • repo_path() uses unwrap_or(false) since it returns &Path via OnceCell<PathBuf> with many callers. Cascading Result would be disproportionate, and the non-bare fallback handles normal repos correctly
  • All other callers already return Result, so they just add ?

@bendrucker
bendrucker marked this pull request as ready for review February 27, 2026 04:34
@bendrucker

Copy link
Copy Markdown
Contributor Author

The unwrap_or(false) in repo_path() means that for bare repos, if is_bare() fails (same mystery git timeout), we fall through to parent() which gives the wrong cached path. Ideas to address this without changing the signature:

// Submodules: --show-toplevel succeeds (git has explicit core.worktree config)
if let Ok(out) = Cmd::new("git")
    .args(["rev-parse", "--show-toplevel"])
    .current_dir(&self.git_common_dir)
    .context(path_to_logging_context(&self.git_common_dir))
    .run()
    && out.status.success()
{
    return PathBuf::from(String::from_utf8_lossy(&out.stdout).trim());
}

// --show-toplevel failed:
// 1. Bare repos (no working tree) → git_common_dir IS the repo
// 2. Normal repos from inside .git → parent is the repo
match self.is_bare() {
    Ok(true) | Err(_) => self.git_common_dir.clone(),
    Ok(false) => self.git_common_dir
        .parent()
        .expect("Git directory has no parent")
        .to_path_buf(),
}

Figured I'd ask before implementing (or not).

@max-sixty

Copy link
Copy Markdown
Owner

thanks a lot @bendrucker ! nice spot

I will merge this

@worktrunk-bot could you draft the follow-up change for our review please?

@max-sixty
max-sixty merged commit 78f0451 into max-sixty:main Feb 27, 2026
21 of 22 checks passed
@max-sixty max-sixty mentioned this pull request Feb 27, 2026
worktrunk-bot pushed a commit that referenced this pull request Feb 27, 2026
Move `--show-toplevel` check before `is_bare()` in `repo_path()` and
treat `is_bare()` errors as bare. Previously `unwrap_or(false)` meant a
git timeout on a bare repo would fall through to `parent()`, caching
a nonsensical path. Now `Err(_)` maps to `git_common_dir`, which is
correct for bare repos. For normal repos a git timeout is a bigger
problem anyway, so the wrong cached path is moot.

Follow-up to #1221.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Follow-up PR: #1225

Restructures repo_path() to try --show-toplevel first, then use is_bare() with Err(_) treated as bare — matching @bendrucker's suggestion above.

worktrunk-bot pushed a commit that referenced this pull request Feb 27, 2026
The `claude-code-action` requires write permission by default, which
blocks reviews on PRs from external contributors (e.g. #1221). Add
`allowed_non_write_users: "*"` to bypass this check.

This is safe for the review workflow since it uses `pull_request_target`
(runs base branch code) and the prompt is controlled by the workflow.

Closes #1224

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants