feat(history): add Atuin context scopes
This commit is contained in:
@@ -108,6 +108,21 @@ func detectGitInfo(cwd string) (hasGit bool, branch string) {
|
||||
return hasGit, ""
|
||||
}
|
||||
|
||||
// GitRoot returns the repository root containing cwd, or an empty string.
|
||||
func GitRoot(cwd string) string {
|
||||
dir := filepath.Clean(cwd)
|
||||
for {
|
||||
if _, err := os.Stat(filepath.Join(dir, ".git")); err == nil {
|
||||
return dir
|
||||
}
|
||||
parent := filepath.Dir(dir)
|
||||
if parent == dir {
|
||||
return ""
|
||||
}
|
||||
dir = parent
|
||||
}
|
||||
}
|
||||
|
||||
type cacheEntry struct {
|
||||
key string // cwd + "|" + dirModTime
|
||||
info WorkspaceInfo
|
||||
|
||||
@@ -44,6 +44,24 @@ func TestDetect_EmptyDirectory(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGitRoot(t *testing.T) {
|
||||
repo := t.TempDir()
|
||||
nested := filepath.Join(repo, "internal", "pkg")
|
||||
if err := os.MkdirAll(filepath.Join(repo, ".git"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.MkdirAll(nested, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if got := GitRoot(nested); got != repo {
|
||||
t.Fatalf("expected git root %q, got %q", repo, got)
|
||||
}
|
||||
if got := GitRoot(t.TempDir()); got != "" {
|
||||
t.Fatalf("expected no git root, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetect_NodeProject(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
_ = os.WriteFile(filepath.Join(tmp, "package.json"), []byte("{}"), 0644)
|
||||
@@ -135,7 +153,7 @@ func TestDetectCached_BranchSwitchWithoutDirChange(t *testing.T) {
|
||||
// Simulate branch switch by updating .git/HEAD only
|
||||
// (this does not update the modtime of tmp on typical filesystems since tmp's direct children didn't change)
|
||||
_ = os.WriteFile(headPath, []byte("ref: refs/heads/feature\n"), 0644)
|
||||
|
||||
|
||||
// Force the modtime of HEAD to be distinct to avoid flakiness on low-res file systems
|
||||
infoAfter, _ := os.Stat(headPath)
|
||||
newMod := infoAfter.ModTime().Add(2 * time.Second)
|
||||
|
||||
Reference in New Issue
Block a user