export function findGitRoot(startDir: string, opts: { maxDepth?: number } = {}): string | null { // A `.git` file counts as a repo marker even if it is not a valid gitdir pointer. return walkUpFrom(startDir, opts, (repoRoot) => (hasGitMarker(repoRoot) ? repoRoot : null));
}
function resolveGitDirFromMarker(repoRoot: string): string | null { const gitPath = path.join(repoRoot, ".git"); try { const stat = fs.statSync(gitPath); if (stat.isDirectory()) { return gitPath;
} if (!stat.isFile()) { returnnull;
} const raw = fs.readFileSync(gitPath, "utf-8"); const match = raw.match(/gitdir:\s*(.+)/i); if (!match?.[1]) { returnnull;
} return path.resolve(repoRoot, match[1].trim());
} catch { returnnull;
}
}
export function resolveGitHeadPath(
startDir: string,
opts: { maxDepth?: number } = {},
): string | null { // Stricter than findGitRoot: keep walking until a resolvable git dir is found. return walkUpFrom(startDir, opts, (repoRoot) => { const gitDir = resolveGitDirFromMarker(repoRoot); return gitDir ? path.join(gitDir, "HEAD") : null;
});
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.