fix: is_inside_git_repo should take the directory as a param

This commit is contained in:
Michael Bolin
2025-05-04 11:21:53 -07:00
parent cd12f0c24a
commit bb06b80404
3 changed files with 28 additions and 32 deletions
+9 -14
View File
@@ -5,6 +5,8 @@ use rand::Rng;
use tokio::sync::Notify;
use tracing::debug;
use crate::config::Config;
const INITIAL_DELAY_MS: u64 = 200;
const BACKOFF_FACTOR: f64 = 1.3;
@@ -33,26 +35,19 @@ pub(crate) fn backoff(attempt: u64) -> Duration {
Duration::from_millis((base as f64 * jitter) as u64)
}
/// Return `true` if the current working directory is inside a Git repository.
/// Return `true` if the specified folder is inside a Git repository.
///
/// The check walks up the directory hierarchy looking for a `.git` folder. This
/// The check walks up the directory hierarchy looking for a `.git` file or
/// directory (note `.git` can be a file that contains a `gitdir` entry). This
/// approach does **not** require the `git` binary or the `git2` crate and is
/// therefore fairly lightweight. It intentionally only looks for the
/// presence of a *directory* named `.git` – this is good enough for regular
/// work‑trees and bare repos that live inside a work‑tree (common for
/// developers running Codex locally).
/// therefore fairly lightweight.
///
/// Note that this does **not** detect *work‑trees* created with
/// `git worktree add` where the checkout lives outside the main repository
/// directory. If you need Codex to work from such a checkout simply pass the
/// directory. If you need Codex to work from such a checkout simply pass the
/// `--allow-no-git-exec` CLI flag that disables the repo requirement.
pub fn is_inside_git_repo() -> bool {
// Best‑effort: any IO error is treated as "not a repo" – the caller can
// decide what to do with the result.
let mut dir = match std::env::current_dir() {
Ok(d) => d,
Err(_) => return false,
};
pub fn is_inside_git_repo(config: &Config) -> bool {
let mut dir = config.cwd.to_path_buf();
loop {
if dir.join(".git").exists() {