mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 10:41:19 -08:00
util/httpm: narrow test cache git dependency
Be cacheable in git worktrees.
Revision to earlier b39ee0445d
Updates tailscale/corp#40359
Change-Id: Ib374d90bf6ee833caabaa3c159ec9f09d991aa41
Signed-off-by: Brad Fitzpatrick <[email protected]>
This commit is contained in:
1 parent
4c4d1c35f8
commit
91c1bbecb1
1 file changed
+14
-9
@@ -18,18 +18,23 @@ func TestUsedConsistently(t *testing.T) {
|
||||
}
|
||||
rootDir := filepath.Join(dir, "../..")
|
||||
|
||||
// If we don't have a .git directory, we're not in a git checkout (e.g.
|
||||
// a downstream package); skip this test.
|
||||
if _, err := os.Stat(filepath.Join(rootDir, ".git")); err != nil {
|
||||
t.Skipf("skipping test since .git doesn't exist: %v", err)
|
||||
}
|
||||
|
||||
// Open .git/index so Go's test cache tracks it as an input.
|
||||
// Open the git index so Go's test cache tracks it as an input.
|
||||
// The index file changes on git reset, checkout, pull, etc.,
|
||||
// so the cache is properly invalidated when moving between commits.
|
||||
if f, err := os.Open(filepath.Join(rootDir, ".git", "index")); err == nil {
|
||||
f.Close()
|
||||
// Ask git for the path because .git is a file in a git worktree. Opening
|
||||
// only the index avoids recording the broader .git directory metadata.
|
||||
indexCmd := exec.Command("git", "rev-parse", "--path-format=absolute", "--git-path", "index")
|
||||
indexCmd.Dir = rootDir
|
||||
indexOut, err := indexCmd.Output()
|
||||
if err != nil {
|
||||
t.Skipf("skipping test since git index cannot be found: %v", err)
|
||||
}
|
||||
indexPath := strings.TrimSpace(string(indexOut))
|
||||
f, err := os.Open(indexPath)
|
||||
if err != nil {
|
||||
t.Fatalf("opening git index %q: %v", indexPath, err)
|
||||
}
|
||||
f.Close()
|
||||
|
||||
cmd := exec.Command("git", "grep", "-l", "-F", "http.Method")
|
||||
cmd.Dir = rootDir
|
||||
|
||||
Reference in new issue
Block a user