Skip to content

Commit 6b88b91

Browse files
committed
git: styling nitpicks
Signed-off-by: Hidde Beydals <hello@hidde.co>
1 parent 59dc284 commit 6b88b91

File tree

5 files changed

+41
-41
lines changed

5 files changed

+41
-41
lines changed

pkg/git/git.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ type Commit struct {
6262

6363
// String returns a string representation of the Commit, composed
6464
// out the last part of the Reference element, and/or Hash.
65-
// For example:
66-
// 'tags/a0c14dc8580a23f79bc654faa79c4f62b46c2c22'.
65+
// For example: 'tag-1/a0c14dc8580a23f79bc654faa79c4f62b46c2c22',
66+
// for a "tag-1" tag.
6767
func (c *Commit) String() string {
6868
if short := strings.SplitAfterN(c.Reference, "/", 3); len(short) == 3 {
6969
return fmt.Sprintf("%s/%s", short[2], c.Hash)

pkg/git/gogit/checkout.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (c *CheckoutBranch) Checkout(ctx context.Context, path, url string, opts *g
8989
if err != nil {
9090
return nil, fmt.Errorf("failed to resolve commit object for HEAD '%s': %w", head.Hash(), err)
9191
}
92-
return commitWithRef(cc, ref)
92+
return buildCommitWithRef(cc, ref)
9393
}
9494

9595
type CheckoutTag struct {
@@ -127,7 +127,7 @@ func (c *CheckoutTag) Checkout(ctx context.Context, path, url string, opts *git.
127127
if err != nil {
128128
return nil, fmt.Errorf("failed to resolve commit object for HEAD '%s': %w", head.Hash(), err)
129129
}
130-
return commitWithRef(cc, ref)
130+
return buildCommitWithRef(cc, ref)
131131
}
132132

133133
type CheckoutCommit struct {
@@ -175,7 +175,7 @@ func (c *CheckoutCommit) Checkout(ctx context.Context, path, url string, opts *g
175175
if err != nil {
176176
return nil, fmt.Errorf("failed to checkout commit '%s': %w", c.Commit, err)
177177
}
178-
return commitWithRef(cc, cloneOpts.ReferenceName)
178+
return buildCommitWithRef(cc, cloneOpts.ReferenceName)
179179
}
180180

181181
type CheckoutSemVer struct {
@@ -287,15 +287,15 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, opts *g
287287
if err != nil {
288288
return nil, fmt.Errorf("failed to resolve commit object for HEAD '%s': %w", head.Hash(), err)
289289
}
290-
return commitWithRef(cc, ref)
290+
return buildCommitWithRef(cc, ref)
291291
}
292292

293-
func commitWithRef(c *object.Commit, ref plumbing.ReferenceName) (*git.Commit, error) {
293+
func buildCommitWithRef(c *object.Commit, ref plumbing.ReferenceName) (*git.Commit, error) {
294294
if c == nil {
295295
return nil, errors.New("failed to construct commit: no object")
296296
}
297297

298-
// Encode commit components, excluding signature into SignedData..
298+
// Encode commit components excluding signature into SignedData.
299299
encoded := &plumbing.MemoryObject{}
300300
if err := c.EncodeWithoutSignature(encoded); err != nil {
301301
return nil, fmt.Errorf("failed to encode commit '%s': %w", c.Hash, err)
@@ -311,14 +311,14 @@ func commitWithRef(c *object.Commit, ref plumbing.ReferenceName) (*git.Commit, e
311311
return &git.Commit{
312312
Hash: []byte(c.Hash.String()),
313313
Reference: ref.String(),
314-
Author: signature(c.Author),
315-
Committer: signature(c.Committer),
314+
Author: buildSignature(c.Author),
315+
Committer: buildSignature(c.Committer),
316316
Signature: c.PGPSignature,
317317
Encoded: b,
318318
}, nil
319319
}
320320

321-
func signature(s object.Signature) git.Signature {
321+
func buildSignature(s object.Signature) git.Signature {
322322
return git.Signature{
323323
Name: s.Name,
324324
Email: s.Email,

pkg/git/libgit2/checkout.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *CheckoutBranch) Checkout(ctx context.Context, path, url string, opts *g
8181
return nil, fmt.Errorf("could not find commit '%s' in branch '%s': %w", head.Target(), c.Branch, err)
8282
}
8383
defer cc.Free()
84-
return commit(cc, "refs/heads/"+c.Branch), nil
84+
return buildCommit(cc, "refs/heads/"+c.Branch), nil
8585
}
8686

8787
type CheckoutTag struct {
@@ -104,7 +104,7 @@ func (c *CheckoutTag) Checkout(ctx context.Context, path, url string, opts *git.
104104
return nil, err
105105
}
106106
defer cc.Free()
107-
return commit(cc, "refs/tags/"+c.Tag), nil
107+
return buildCommit(cc, "refs/tags/"+c.Tag), nil
108108
}
109109

110110
type CheckoutCommit struct {
@@ -130,7 +130,7 @@ func (c *CheckoutCommit) Checkout(ctx context.Context, path, url string, opts *g
130130
if err != nil {
131131
return nil, fmt.Errorf("git checkout error: %w", err)
132132
}
133-
return commit(cc, ""), nil
133+
return buildCommit(cc, ""), nil
134134
}
135135

136136
type CheckoutSemVer struct {
@@ -228,7 +228,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, opts *g
228228
return nil, err
229229
}
230230
defer cc.Free()
231-
return commit(cc, "refs/tags/"+t), nil
231+
return buildCommit(cc, "refs/tags/"+t), nil
232232
}
233233

234234
// checkoutDetachedDwim attempts to perform a detached HEAD checkout by first DWIMing the short name
@@ -285,20 +285,20 @@ func headCommit(repo *git2go.Repository) (*git2go.Commit, error) {
285285
return c, nil
286286
}
287287

288-
func commit(c *git2go.Commit, ref string) *git.Commit {
288+
func buildCommit(c *git2go.Commit, ref string) *git.Commit {
289289
sig, msg, _ := c.ExtractSignature()
290290
return &git.Commit{
291291
Hash: []byte(c.Id().String()),
292292
Reference: ref,
293-
Author: signature(c.Author()),
294-
Committer: signature(c.Committer()),
293+
Author: buildSignature(c.Author()),
294+
Committer: buildSignature(c.Committer()),
295295
Signature: sig,
296296
Encoded: []byte(msg),
297297
Message: c.Message(),
298298
}
299299
}
300300

301-
func signature(s *git2go.Signature) git.Signature {
301+
func buildSignature(s *git2go.Signature) git.Signature {
302302
return git.Signature{
303303
Name: s.Name,
304304
Email: s.Email,

pkg/git/libgit2/transport_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ orKqTuAPzXK7imQk6+OycYABbqCtC/9qmwRd8wwn7sF97DtYfK8WuNHtFalCAwyi
132132
Kom08eUK8skxAzfDDijZPh10VtJ66uBoiDPdT+uCBehcBIcmSTrKjFGX
133133
-----END CERTIFICATE-----`
134134

135-
knownHosts string = `github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==`
135+
knownHostsFixture string = `github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==`
136136
)
137137

138138
func Test_x509Callback(t *testing.T) {
@@ -210,31 +210,31 @@ func Test_knownHostsCallback(t *testing.T) {
210210
{
211211
name: "Match",
212212
host: "github.com",
213-
knownHosts: []byte(knownHosts),
213+
knownHosts: []byte(knownHostsFixture),
214214
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA1 | git2go.HostkeyMD5, HashSHA1: sha1Fingerprint("v2toJdKXfFEaR1u++4iq1UqSrHM")},
215215
expectedHost: "github.com",
216216
want: git2go.ErrorCodeOK,
217217
},
218218
{
219219
name: "Match with port",
220220
host: "github.com",
221-
knownHosts: []byte(knownHosts),
221+
knownHosts: []byte(knownHostsFixture),
222222
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA1 | git2go.HostkeyMD5, HashSHA1: sha1Fingerprint("v2toJdKXfFEaR1u++4iq1UqSrHM")},
223223
expectedHost: "github.com:22",
224224
want: git2go.ErrorCodeOK,
225225
},
226226
{
227227
name: "Hostname mismatch",
228228
host: "github.com",
229-
knownHosts: []byte(knownHosts),
229+
knownHosts: []byte(knownHostsFixture),
230230
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA1 | git2go.HostkeyMD5, HashSHA1: sha1Fingerprint("v2toJdKXfFEaR1u++4iq1UqSrHM")},
231231
expectedHost: "example.com",
232232
want: git2go.ErrorCodeUser,
233233
},
234234
{
235235
name: "Hostkey mismatch",
236236
host: "github.com",
237-
knownHosts: []byte(knownHosts),
237+
knownHosts: []byte(knownHostsFixture),
238238
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeyMD5, HashMD5: md5Fingerprint("\xb6\x03\x0e\x39\x97\x9e\xd0\xe7\x24\xce\xa3\x77\x3e\x01\x42\x09")},
239239
expectedHost: "github.com",
240240
want: git2go.ErrorCodeCertificate,
@@ -269,7 +269,7 @@ func Test_parseKnownHosts(t *testing.T) {
269269
t.Run(tt.name, func(t *testing.T) {
270270
g := NewWithT(t)
271271

272-
knownKeys, err := parseKnownHosts(knownHosts)
272+
knownKeys, err := parseKnownHosts(knownHostsFixture)
273273
if err != nil {
274274
t.Error(err)
275275
return

pkg/git/strategy/strategy_test.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ func TestCheckoutStrategyForImplementation_Auth(t *testing.T) {
3737
gitImpls := []git.Implementation{gogit.Implementation, libgit2.Implementation}
3838

3939
type testCase struct {
40-
name string
41-
transport git.TransportType
42-
getRepoURL func(g *WithT, srv *gittestserver.GitServer, repoPath string) string
43-
getAuthOpts func(g *WithT, u *url.URL, user string, pswd string, ca []byte) *git.AuthOptions
44-
wantFunc func(g *WithT, cs git.CheckoutStrategy, dir string, repoURL string, authOpts *git.AuthOptions)
40+
name string
41+
transport git.TransportType
42+
repoURLFunc func(g *WithT, srv *gittestserver.GitServer, repoPath string) string
43+
authOptsFunc func(g *WithT, u *url.URL, user string, pswd string, ca []byte) *git.AuthOptions
44+
wantFunc func(g *WithT, cs git.CheckoutStrategy, dir string, repoURL string, authOpts *git.AuthOptions)
4545
}
4646

4747
cases := []testCase{
4848
{
49-
name: "http cloning",
49+
name: "HTTP clone",
5050
transport: git.HTTP,
51-
getRepoURL: func(g *WithT, srv *gittestserver.GitServer, repoPath string) string {
51+
repoURLFunc: func(g *WithT, srv *gittestserver.GitServer, repoPath string) string {
5252
return srv.HTTPAddressWithCredentials() + "/" + repoPath
5353
},
54-
getAuthOpts: func(g *WithT, u *url.URL, user string, pswd string, ca []byte) *git.AuthOptions {
54+
authOptsFunc: func(g *WithT, u *url.URL, user string, pswd string, ca []byte) *git.AuthOptions {
5555
return &git.AuthOptions{
5656
Transport: git.HTTP,
5757
Username: user,
@@ -64,12 +64,12 @@ func TestCheckoutStrategyForImplementation_Auth(t *testing.T) {
6464
},
6565
},
6666
{
67-
name: "https cloning",
67+
name: "HTTPS clone",
6868
transport: git.HTTPS,
69-
getRepoURL: func(g *WithT, srv *gittestserver.GitServer, repoPath string) string {
69+
repoURLFunc: func(g *WithT, srv *gittestserver.GitServer, repoPath string) string {
7070
return srv.HTTPAddress() + "/" + repoPath
7171
},
72-
getAuthOpts: func(g *WithT, u *url.URL, user, pswd string, ca []byte) *git.AuthOptions {
72+
authOptsFunc: func(g *WithT, u *url.URL, user, pswd string, ca []byte) *git.AuthOptions {
7373
return &git.AuthOptions{
7474
Transport: git.HTTPS,
7575
Username: user,
@@ -83,12 +83,12 @@ func TestCheckoutStrategyForImplementation_Auth(t *testing.T) {
8383
},
8484
},
8585
{
86-
name: "ssh cloning",
86+
name: "SSH clone",
8787
transport: git.SSH,
88-
getRepoURL: func(g *WithT, srv *gittestserver.GitServer, repoPath string) string {
88+
repoURLFunc: func(g *WithT, srv *gittestserver.GitServer, repoPath string) string {
8989
return getSSHRepoURL(srv.SSHAddress(), repoPath)
9090
},
91-
getAuthOpts: func(g *WithT, u *url.URL, user, pswd string, ca []byte) *git.AuthOptions {
91+
authOptsFunc: func(g *WithT, u *url.URL, user, pswd string, ca []byte) *git.AuthOptions {
9292
knownhosts, err := ssh.ScanHostKey(u.Host, 5*time.Second)
9393
g.Expect(err).ToNot(HaveOccurred())
9494

@@ -163,10 +163,10 @@ func TestCheckoutStrategyForImplementation_Auth(t *testing.T) {
163163
err = gitServer.InitRepo("testdata/repo1", branch, repoPath)
164164
g.Expect(err).ToNot(HaveOccurred())
165165

166-
repoURL := tt.getRepoURL(g, gitServer, repoPath)
166+
repoURL := tt.repoURLFunc(g, gitServer, repoPath)
167167
u, err := url.Parse(repoURL)
168168
g.Expect(err).ToNot(HaveOccurred())
169-
authOpts := tt.getAuthOpts(g, u, username, password, exampleCA)
169+
authOpts := tt.authOptsFunc(g, u, username, password, exampleCA)
170170

171171
// Get the checkout strategy.
172172
checkoutOpts := git.CheckoutOptions{

0 commit comments

Comments
 (0)