11package git
22
33import (
4+ "fmt"
45 "io/ioutil"
56 "net/url"
67 "os"
@@ -43,7 +44,7 @@ func TestRepoName(t *testing.T) {
4344func TestCloneCreatesDirectory (t * testing.T ) {
4445 tempDir , cleanup := makeTempDir (t )
4546 defer cleanup ()
46- r , err := NewRepository (testRepository , path .Join (tempDir , "path" ))
47+ r , err := NewRepository (testRepository , path .Join (tempDir , "path" ), false )
4748 assertNoError (t , err )
4849 err = r .Clone ()
4950 assertNoError (t , err )
@@ -69,24 +70,6 @@ func TestClone(t *testing.T) {
6970 }
7071}
7172
72- /* TestCheckout relates to earlier behaviour that dealt with branches within repos. We can revisit this.
73- func TestCheckout(t *testing.T) {
74- r, cleanup := cloneTestRepository(t)
75- defer cleanup()
76-
77- err := r.Checkout("updated-version")
78- assertNoError(t, err)
79-
80- contents, err := ioutil.ReadFile(path.Join(r.LocalPath, "env-staging/service-a/deployment.txt"))
81- assertNoError(t, err)
82-
83- want := "This is an updated version of this file.\n"
84- if diff := cmp.Diff(want, string(contents)); diff != "" {
85- t.Fatalf("failed to read file: %s", diff)
86- }
87- }
88- */
89-
9073func TestWalk (t * testing.T ) {
9174 r , cleanup := cloneTestRepository (t )
9275 defer cleanup ()
@@ -201,7 +184,7 @@ func TestStageFiles(t *testing.T) {
201184 err = r .StageFiles ("services/service-a/new-file.txt" )
202185 assertNoError (t , err )
203186
204- out := assertExecGit (t , r .repoPath ("services/service-a" ), "status" , "--porcelain" )
187+ out := assertExecGit (t , r , r .repoPath ("services/service-a" ), "status" , "--porcelain" )
205188 want := "A services/service-a/new-file.txt\n "
206189 if diff := cmp .Diff (want , string (out )); diff != "" {
207190 t .Fatalf ("file status not modified: %s" , diff )
@@ -225,7 +208,7 @@ func TestCommit(t *testing.T) {
225208 err = r .
Commit (
"this is a test commit" ,
& Author {
Name :
"Test User" ,
Email :
"[email protected] " })
226209 assertNoError (t , err )
227210
228- out := strings .Split (string (assertExecGit (t , r .repoPath ("services/service-a" ), "log" , "-n" , "1" )), "\n " )
211+ out := strings .Split (string (assertExecGit (t , r , r .repoPath ("services/service-a" ), "log" , "-n" , "1" )), "\n " )
229212 want := []
string {
"Author: Test User <[email protected] >" ,
" this is a test commit" }
230213 if diff := cmp .Diff (want , out , cmpopts .IgnoreSliceElements (func (s string ) bool {
231214 return strings .HasPrefix (s , "commit" ) || strings .HasPrefix (s , "Date:" ) || s == ""
@@ -234,6 +217,23 @@ func TestCommit(t *testing.T) {
234217 }
235218}
236219
220+ func TestExecGit (t * testing.T ) {
221+ r , cleanup := cloneTestRepository (t )
222+ r .debug = true
223+ captured := ""
224+ r .logger = func (f string , v ... interface {}) {
225+ captured = fmt .Sprintf (f , v ... )
226+ }
227+ defer cleanup ()
228+ _ , err := r .execGit (r .repoPath (), nil , "unknown" )
229+ test .AssertErrorMatch (t , "exit status 1" , err )
230+
231+ want := "DEBUG: git: 'unknown' is not a git command. See 'git --help'."
232+ if strings .TrimSpace (captured ) != want {
233+ t .Fatalf ("execGit debug log failed: got %s, want %s" , captured , want )
234+ }
235+ }
236+
237237func TestPush (t * testing.T ) {
238238 if authToken () == "" {
239239 t .Skip ("no auth token to push the branch upstream" )
@@ -255,7 +255,7 @@ func TestPush(t *testing.T) {
255255
256256func cloneTestRepository (t * testing.T ) (* Repository , func ()) {
257257 tempDir , cleanup := makeTempDir (t )
258- r , err := NewRepository (authenticatedURL (t ), tempDir )
258+ r , err := NewRepository (authenticatedURL (t ), tempDir , false )
259259 assertNoError (t , err )
260260 err = r .Clone ()
261261 assertNoError (t , err )
@@ -282,9 +282,9 @@ func makeTempDir(t *testing.T) (string, func()) {
282282 }
283283}
284284
285- func assertExecGit (t * testing.T , gitPath string , args ... string ) []byte {
285+ func assertExecGit (t * testing.T , r * Repository , gitPath string , args ... string ) []byte {
286286 t .Helper ()
287- out , err := execGit (gitPath , nil , args ... )
287+ out , err := r . execGit (gitPath , nil , args ... )
288288 if err != nil {
289289 t .Fatalf ("assertExecGit failed: %s (%s)" , err , out )
290290 }
0 commit comments