diff --git a/git/gogit/client.go b/git/gogit/client.go index 9fc0b86e..62da4a31 100644 --- a/git/gogit/client.go +++ b/git/gogit/client.go @@ -409,12 +409,13 @@ func (g *Client) Push(ctx context.Context, cfg repository.PushConfig) error { } err = g.repository.PushContext(ctx, &extgogit.PushOptions{ - RefSpecs: refspecs, - Force: cfg.Force, - RemoteName: extgogit.DefaultRemoteName, - Auth: authMethod, - Progress: nil, - CABundle: caBundle(g.authOpts), + RefSpecs: refspecs, + Force: cfg.Force, + RemoteName: extgogit.DefaultRemoteName, + Auth: authMethod, + Progress: nil, + CABundle: caBundle(g.authOpts), + ProxyOptions: g.proxy, }) return goGitError(err) } diff --git a/git/gogit/clone_test.go b/git/gogit/clone_test.go index 31b95ee9..f5078d63 100644 --- a/git/gogit/clone_test.go +++ b/git/gogit/clone_test.go @@ -1128,7 +1128,7 @@ func Test_ssh_HostKeyAlgos(t *testing.T) { } } -func TestClone_WithProxy(t *testing.T) { +func TestCloneAndPush_WithProxy(t *testing.T) { g := NewWithT(t) server, err := gittestserver.NewTempGitServer() @@ -1178,6 +1178,27 @@ func TestClone_WithProxy(t *testing.T) { }) g.Expect(err).ToNot(HaveOccurred()) g.Expect(proxiedRequests).To(BeNumerically(">", 0)) + + // reset proxy requests counter + proxiedRequests = 0 + // make a commit on master and push it. + cc1, err := commitFile(ggc.repository, "test", "testing gogit push", time.Now()) + g.Expect(err).ToNot(HaveOccurred()) + err = ggc.Push(context.TODO(), repository.PushConfig{}) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(proxiedRequests).To(BeNumerically(">", 0)) + + // check if we indeed pushed the commit to remote. + ggc, err = NewClient(t.TempDir(), authOpts, WithDiskStorage(), WithProxy(proxyOpts)) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(ggc.proxy.URL).ToNot(BeEmpty()) + cc2, err := ggc.Clone(context.TODO(), repoURL, repository.CloneConfig{ + CheckoutStrategy: repository.CheckoutStrategy{ + Branch: git.DefaultBranch, + }, + }) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(cc1.String()).To(Equal(cc2.Hash.String())) } func Test_getRemoteHEAD(t *testing.T) { diff --git a/git/internal/e2e/run.sh b/git/internal/e2e/run.sh index 6f69227f..48ab17f2 100755 --- a/git/internal/e2e/run.sh +++ b/git/internal/e2e/run.sh @@ -17,4 +17,4 @@ if [[ "${GO_TEST_PREFIX}" = "" ]] || [[ "${GO_TEST_PREFIX}" = *"TestGitLabCEE2E" fi cd "${DIR}" -CGO_ENABLED=1 go test -v -tags 'netgo,osusergo,static_build,e2e' -race -run "^${GO_TEST_PREFIX}.*" ./... +go test -v -tags 'netgo,osusergo,static_build,e2e' -race -run "^${GO_TEST_PREFIX}.*" ./... diff --git a/git/internal/e2e/utils.go b/git/internal/e2e/utils.go index 125acdfd..02174fc4 100644 --- a/git/internal/e2e/utils.go +++ b/git/internal/e2e/utils.go @@ -44,6 +44,8 @@ import ( var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz1234567890") +const timeout = time.Second * 20 + func testUsingClone(g *WithT, client repository.Client, repoURL *url.URL, upstreamRepo upstreamRepoInfo) { // clone repo _, err := client.Clone(context.TODO(), repoURL.String(), repository.CloneConfig{ @@ -62,8 +64,16 @@ func testUsingClone(g *WithT, client repository.Client, repoURL *url.URL, upstre ) g.Expect(err).ToNot(HaveOccurred(), "first commit") - err = client.Push(context.TODO(), repository.PushConfig{}) - g.Expect(err).ToNot(HaveOccurred()) + // GitHub sometimes takes a long time to propogate its deploy key and this leads + // to mysterious push errors like "unknown error: ERROR: Unknown public SSH key". + // This helps us get around that by retrying for a fixed amount of time. + g.Eventually(func() bool { + err = client.Push(context.TODO(), repository.PushConfig{}) + if err != nil { + return false + } + return true + }, timeout).Should(BeTrue()) headCommit, _, err := headCommitWithBranch(upstreamRepo.url, "main", upstreamRepo.username, upstreamRepo.password) g.Expect(err).ToNot(HaveOccurred()) @@ -120,8 +130,13 @@ func testUsingInit(g *WithT, client repository.Client, repoURL *url.URL, upstrea ) g.Expect(err).ToNot(HaveOccurred(), "first commit") - err = client.Push(context.TODO(), repository.PushConfig{}) - g.Expect(err).ToNot(HaveOccurred()) + g.Eventually(func() bool { + err = client.Push(context.TODO(), repository.PushConfig{}) + if err != nil { + return false + } + return true + }, timeout).Should(BeTrue()) headCommit, _, err := headCommitWithBranch(upstreamRepo.url, "main", upstreamRepo.username, upstreamRepo.password) g.Expect(err).ToNot(HaveOccurred()) @@ -157,6 +172,7 @@ func testUsingInit(g *WithT, client repository.Client, repoURL *url.URL, upstrea g.Expect(err).ToNot(HaveOccurred(), "third commit") err = client.Push(context.TODO(), repository.PushConfig{}) g.Expect(err).ToNot(HaveOccurred()) + headCommit, _, err = headCommitWithBranch(upstreamRepo.url, "new", upstreamRepo.username, upstreamRepo.password) g.Expect(err).ToNot(HaveOccurred()) g.Expect(headCommit).To(Equal(cc))