feat(context): centralize RepoContext API for git operations (#1102)

Centralizes repository context resolution via RepoContext API, fixing bugs where git commands run in the wrong repo when BEADS_DIR points elsewhere or in worktree scenarios.
This commit is contained in:
Peter Chanthamynavong
2026-01-15 07:55:08 -08:00
committed by GitHub
parent 159114563b
commit 0a48519561
33 changed files with 3211 additions and 327 deletions

View File

@@ -187,3 +187,18 @@ func NormalizePathForComparison(path string) string {
func PathsEqual(path1, path2 string) bool {
return NormalizePathForComparison(path1) == NormalizePathForComparison(path2)
}
// CanonicalizeIfRelative ensures a path is absolute for filepath.Rel() compatibility.
// If the path is non-empty and relative, it is canonicalized using CanonicalizePath.
// Absolute paths and empty strings are returned unchanged.
//
// This guards against code paths that might set paths to relative values,
// which would cause filepath.Rel() to fail or produce incorrect results.
//
// See GH#959 for root cause analysis of the original autoflush bug.
func CanonicalizeIfRelative(path string) string {
if path != "" && !filepath.IsAbs(path) {
return CanonicalizePath(path)
}
return path
}