blob: 4530c60431f44fb15f9c569218e48a79fd999f88 (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
package testgit
import (
"errors"
"os"
"testing"
)
// OpenRoot opens the repository root directory and registers cleanup on the
// caller.
func (testRepo *TestRepo) OpenRoot(tb testing.TB) *os.Root {
tb.Helper()
root, err := os.OpenRoot(testRepo.dir)
if err != nil {
tb.Fatalf("os.OpenRoot: %v", err)
}
tb.Cleanup(func() {
_ = root.Close()
})
return root
}
// OpenGitRoot opens the repository gitdir and registers cleanup on the caller.
//
// For bare repositories, this is the repository root itself. For non-bare
// repositories, this is the .git directory under the worktree root.
func (testRepo *TestRepo) OpenGitRoot(tb testing.TB) *os.Root {
tb.Helper()
repoRoot := testRepo.OpenRoot(tb)
gitRoot, err := repoRoot.OpenRoot(".git")
if err == nil {
tb.Cleanup(func() {
_ = gitRoot.Close()
})
return gitRoot
}
if !errors.Is(err, os.ErrNotExist) {
tb.Fatalf("OpenRoot(.git): %v", err)
}
return repoRoot
}
// OpenObjectsRoot opens the objects directory and registers cleanup on the
// caller.
func (testRepo *TestRepo) OpenObjectsRoot(tb testing.TB) *os.Root {
tb.Helper()
gitRoot := testRepo.OpenGitRoot(tb)
objectsRoot, err := gitRoot.OpenRoot("objects")
if err != nil {
tb.Fatalf("OpenRoot(objects): %v", err)
}
tb.Cleanup(func() {
_ = objectsRoot.Close()
})
return objectsRoot
}
// OpenPackRoot opens the objects/pack directory and registers cleanup on the
// caller.
func (testRepo *TestRepo) OpenPackRoot(tb testing.TB) *os.Root {
tb.Helper()
objectsRoot := testRepo.OpenObjectsRoot(tb)
packRoot, err := objectsRoot.OpenRoot("pack")
if err != nil {
tb.Fatalf("OpenRoot(pack): %v", err)
}
tb.Cleanup(func() {
_ = packRoot.Close()
})
return packRoot
}
|