@@ -2,14 +2,14 @@ package controllers
22
33import (
44 "context"
5+ "fmt"
56 "os"
67 "path/filepath"
78 "testing"
89 "time"
910
1011 "github.com/go-git/go-billy/v5/memfs"
1112 gogit "github.com/go-git/go-git/v5"
12- "github.com/go-git/go-git/v5/plumbing"
1313 "github.com/go-git/go-git/v5/plumbing/object"
1414 "github.com/go-git/go-git/v5/storage/memory"
1515 "github.com/go-logr/logr"
@@ -144,18 +144,11 @@ func TestPushRejected(t *testing.T) {
144144 t .Fatal (err )
145145 }
146146
147- tmp , err := os .MkdirTemp ("" , "gotest-imageauto-git" )
148- if err != nil {
149- t .Fatal (err )
150- }
151- repoURL := gitServer .HTTPAddress () + "/appconfig.git"
152- repo , err := gogit .PlainClone (tmp , false , & gogit.CloneOptions {
153- URL : repoURL ,
154- ReferenceName : plumbing .NewBranchReferenceName ("main" ),
155- })
147+ repoURL := gitServer .HTTPAddressWithCredentials () + "/appconfig.git"
148+ repo , err := clone (repoURL , "origin" , "main" )
156149
157150 // This is here to guard against push in general being broken
158- err = push (context .TODO (), tmp , "main" , repoAccess {
151+ err = push (context .TODO (), repo . Workdir () , "main" , repoAccess {
159152 url : repoURL ,
160153 auth : nil ,
161154 })
@@ -164,13 +157,13 @@ func TestPushRejected(t *testing.T) {
164157 }
165158
166159 // This is not under test, but needed for the next bit
167- if err = switchBranch ( repo , branch ); err != nil {
160+ if err = repo . SetHead ( fmt . Sprintf ( "refs/heads/%s" , branch ) ); err != nil {
168161 t .Fatal (err )
169162 }
170163
171164 // This is supposed to fail, because the hook rejects the branch
172165 // pushed to.
173- err = push (context .TODO (), tmp , branch , repoAccess {
166+ err = push (context .TODO (), repo . Workdir () , branch , repoAccess {
174167 url : repoURL ,
175168 auth : nil ,
176169 })
0 commit comments