Skip to content

Commit 00a6a29

Browse files
committed
check for .git in all tests
1 parent 517d5bf commit 00a6a29

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

cmd/git-sg/catfile_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
)
1010

1111
func TestInfo(t *testing.T) {
12+
setGitDir(t)
13+
1214
p, err := startGitCatFileBatch("")
1315
if err != nil {
1416
t.Fatal(err)
@@ -43,6 +45,8 @@ func TestInfo(t *testing.T) {
4345
}
4446

4547
func TestContents(t *testing.T) {
48+
setGitDir(t)
49+
4650
p, err := startGitCatFileBatch("")
4751
if err != nil {
4852
t.Fatal(err)

cmd/git-sg/main_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ import (
77
)
88

99
func TestDo(t *testing.T) {
10-
dir, err := filepath.Abs("../../.git")
11-
if err != nil {
12-
t.Fatal(err)
13-
}
14-
t.Setenv("GIT_DIR", dir)
15-
16-
if _, err := os.Stat(dir); os.Getenv("CI") != "" && os.IsNotExist(err) {
17-
t.Skipf("skipping since on CI and this is not a git checkout: %v", err)
18-
}
10+
setGitDir(t)
1911

2012
for _, envvar := range []string{"", "GIT_SG_BUFFER", "GIT_SG_FILTER", "GIT_SG_CATFILE", "GIT_SG_LSTREE"} {
2113
name := envvar
@@ -27,7 +19,7 @@ func TestDo(t *testing.T) {
2719
t.Setenv(envvar, "1")
2820
}
2921
var w countingWriter
30-
err = do(&w)
22+
err := do(&w)
3123
if err != nil {
3224
t.Fatal(err)
3325
}
@@ -47,3 +39,17 @@ func (w *countingWriter) Write(b []byte) (int, error) {
4739
w.N += len(b)
4840
return len(b), nil
4941
}
42+
43+
func setGitDir(t *testing.T) {
44+
t.Helper()
45+
46+
dir, err := filepath.Abs("../../.git")
47+
if err != nil {
48+
t.Fatal(err)
49+
}
50+
t.Setenv("GIT_DIR", dir)
51+
52+
if _, err := os.Stat(dir); os.Getenv("CI") != "" && os.IsNotExist(err) {
53+
t.Skipf("skipping since on CI and this is not a git checkout: %v", err)
54+
}
55+
}

0 commit comments

Comments
 (0)