/** * @file Git repository discovery + foundational lazy fs/path/cwd helpers shared * across `git/*` leaves. Owns `findGitRoot`, `findOutermostGitRoot`, the * realpath cache, the cwd resolver, and the lazy `node:fs` / `node:path` * loaders — pulling these together keeps the dependency direction one-way: * `shared.ts` and the public-surface leaves all import from here. */ import type { GitDiffOptions } from './types.js'; export declare const realpathCache: Map; export declare const gitRootCache: Map; /** * Find git repository root by walking up from the given directory. * * Searches for a `.git` directory or file by traversing parent directories * upward until found or filesystem root is reached. Returns the original path * if no git repository is found. * * This function is exported primarily for testing purposes. * * @example * ;```typescript * const root = findGitRoot('/path/to/repo/src/subdir') * // => '/path/to/repo' * * const notFound = findGitRoot('/not/a/repo') * // => '/not/a/repo' * ``` * * @param startPath - Directory path to start searching from. * * @returns Git repository root path, or `startPath` if not found. */ export declare function findGitRoot(startPath: string): string; /** * Walk up from a directory to the OUTERMOST ancestor that holds a `.git` * marker. Returns the input when no ancestor has one. * * @example * ;```typescript * findOutermostGitRoot('/repo/vendor/nested/src') // '/repo' * ``` */ export declare function findOutermostGitRoot(dirPath: string): string; /** * Get the real path with caching to avoid repeated filesystem calls. Validates * cache with existsSync() which is cheaper than realpathSync(). * * ENOENT/ENOTDIR are re-thrown because the caller explicitly passed a path they * expect to exist — swallowing these would turn "file not found" into a silent * no-op. Other errors (EACCES, EPERM, EIO) fall back to the input path since * they can happen on container/overlay filesystems where the path exists but * realpath resolution is restricted. */ export declare function getCachedRealpath(pathname: string): string; /** * Get the current working directory for git operations. * * Returns the real path to handle symlinks correctly. This is important because * symlinked directories like `/tmp -> /private/tmp` can cause path mismatches * when comparing git output. * * @example * ;```typescript * const cwd = getCwd() * // In /tmp (symlink to /private/tmp): * // => '/private/tmp' * ``` * * @returns The resolved real path of `process.cwd()`. */ export declare function getCwd(): string; export declare function resolveGitRelativePath(pathname: string, options?: GitDiffOptions | undefined): string;