@@ -17,6 +17,7 @@ package testutils
1717import (
1818 "os"
1919 "path/filepath"
20+ "testing"
2021 "time"
2122
2223 "github.com/go-git/go-git/v5"
@@ -31,14 +32,17 @@ type TestRepo struct {
3132
3233// NewTestRepo creates a new TestRepo with the given files committed into a
3334// single commit in the repo.
34- func NewTestRepo (dir , author , email string , files []* File , links []* Symlink ) * TestRepo {
35+ func NewTestRepo (t * testing.T , dir , author , email string , files []* File , links []* Symlink ) * TestRepo {
36+ t .Helper ()
37+
3538 testRepo := & TestRepo {
3639 dir : dir ,
3740 }
41+ repoDir , err := git .PlainInit (testRepo .dir , false )
42+ testRepo .repo = Must (t , repoDir , err )
3843
39- testRepo .repo = Must (git .PlainInit (testRepo .dir , false ))
40-
41- worktree := Must (testRepo .repo .Worktree ())
44+ worktree , err := testRepo .repo .Worktree ()
45+ Check (t , err )
4246
4347 const readWriteExec = os .FileMode (0o700 )
4448
@@ -47,47 +51,51 @@ func NewTestRepo(dir, author, email string, files []*File, links []*Symlink) *Te
4751 fullPath := filepath .Join (testRepo .dir , f .Path )
4852
4953 // Create necessary sub-directories.
50- Check (os .MkdirAll (filepath .Dir (fullPath ), readWriteExec ))
54+ Check (t , os .MkdirAll (filepath .Dir (fullPath ), readWriteExec ))
5155
5256 // Write the file
53- Check (os .WriteFile (fullPath , f .Contents , f .Mode ))
57+ Check (t , os .WriteFile (fullPath , f .Contents , f .Mode ))
5458
5559 // git add <file>
56- _ = Must (worktree .Add (f .Path ))
60+ _ , err := worktree .Add (f .Path )
61+ Check (t , err )
5762 }
5863
5964 // git commit <file>
60- _ = Must ( worktree .Commit ("add files" , & git.CommitOptions {
65+ _ , err := worktree .Commit ("add files" , & git.CommitOptions {
6166 Author : & object.Signature {
6267 Name : author ,
6368 Email : email ,
6469 When : time .Now (),
6570 },
66- }))
71+ })
72+ Check (t , err )
6773 }
6874
6975 if len (links ) > 0 {
7076 for _ , link := range links {
7177 fullPath := filepath .Join (testRepo .dir , link .Path )
7278
7379 // Create necessary sub-directories.
74- Check (os .MkdirAll (filepath .Dir (fullPath ), readWriteExec ))
80+ Check (t , os .MkdirAll (filepath .Dir (fullPath ), readWriteExec ))
7581
7682 // Create the symbolic link.
77- Check (os .Symlink (link .Target , fullPath ))
83+ Check (t , os .Symlink (link .Target , fullPath ))
7884
7985 // git add <file>
80- _ = Must (worktree .Add (link .Path ))
86+ _ , err := worktree .Add (link .Path )
87+ Check (t , err )
8188 }
8289
8390 // git commit <file>
84- _ = Must ( worktree .Commit ("add links" , & git.CommitOptions {
91+ _ , err := worktree .Commit ("add links" , & git.CommitOptions {
8592 Author : & object.Signature {
8693 Name : author ,
8794 Email : email ,
8895 When : time .Now (),
8996 },
90- }))
97+ })
98+ Check (t , err )
9199 }
92100
93101 return testRepo
0 commit comments