Skip to content

Commit e6b6af7

Browse files
authored
Merge pull request #685 from knutgoetz/chore/gogit/delete-gogiterror-function
Delete obsolete goGitError function
2 parents 02723c3 + cbc2172 commit e6b6af7

File tree

3 files changed

+9
-66
lines changed

3 files changed

+9
-66
lines changed

git/gogit/client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,11 @@ func (g *Client) Push(ctx context.Context, cfg repository.PushConfig) error {
418418
ProxyOptions: g.proxy,
419419
Options: cfg.Options,
420420
})
421-
return goGitError(err)
421+
if err != nil {
422+
return fmt.Errorf("failed to push to remote: %w", err)
423+
}
424+
425+
return nil
422426
}
423427

424428
// SwitchBranch switches the current branch to the given branch name.

git/gogit/clone.go

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (g *Client) cloneBranch(ctx context.Context, url, branch string, opts repos
106106
}
107107
}
108108
if err != nil {
109-
return nil, fmt.Errorf("unable to clone '%s': %w", url, goGitError(err))
109+
return nil, fmt.Errorf("unable to clone '%s': %w", url, err)
110110
}
111111
}
112112

@@ -179,7 +179,7 @@ func (g *Client) cloneTag(ctx context.Context, url, tag string, opts repository.
179179
URL: url,
180180
}
181181
}
182-
return nil, fmt.Errorf("unable to clone '%s': %w", url, goGitError(err))
182+
return nil, fmt.Errorf("unable to clone '%s': %w", url, err)
183183
}
184184

185185
head, err := repo.Head()
@@ -243,7 +243,7 @@ func (g *Client) cloneCommit(ctx context.Context, url, commit string, opts repos
243243
URL: url,
244244
}
245245
}
246-
return nil, fmt.Errorf("unable to clone '%s': %w", url, goGitError(err))
246+
return nil, fmt.Errorf("unable to clone '%s': %w", url, err)
247247
}
248248

249249
w, err := repo.Worktree()
@@ -305,7 +305,7 @@ func (g *Client) cloneSemVer(ctx context.Context, url, semverTag string, opts re
305305
URL: url,
306306
}
307307
}
308-
return nil, fmt.Errorf("unable to clone '%s': %w", url, goGitError(err))
308+
return nil, fmt.Errorf("unable to clone '%s': %w", url, err)
309309
}
310310

311311
repoTags, err := repo.Tags()
@@ -609,23 +609,3 @@ func buildCommitWithRef(c *object.Commit, t *object.Tag, ref plumbing.ReferenceN
609609
func isRemoteBranchNotFoundErr(err error, ref string) bool {
610610
return strings.Contains(err.Error(), fmt.Sprintf("couldn't find remote ref '%s'", ref))
611611
}
612-
613-
// goGitError translates an error from the go-git library, or returns
614-
// `nil` if the argument is `nil`.
615-
func goGitError(err error) error {
616-
if err == nil {
617-
return nil
618-
}
619-
switch strings.TrimSpace(err.Error()) {
620-
case "unknown error: remote:":
621-
// this unhelpful error arises because go-git takes the first
622-
// line of the output on stderr, and for some git providers
623-
// (GitLab, at least) the output has a blank line at the
624-
// start. The rest of stderr is thrown away, so we can't get
625-
// the actual error; but at least we know what was being
626-
// attempted, and the likely cause.
627-
return fmt.Errorf("push rejected; check git secret has write access")
628-
default:
629-
return err
630-
}
631-
}

git/gogit/clone_test.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,47 +1516,6 @@ func TestClone_CredentialsOverHttp(t *testing.T) {
15161516
}
15171517
}
15181518

1519-
func TestGoGitErrorReplace(t *testing.T) {
1520-
// this is what go-git uses as the error message is if the remote
1521-
// sends a blank first line
1522-
unknownMessage := `unknown error: remote: `
1523-
err := errors.New(unknownMessage)
1524-
err = goGitError(err)
1525-
reformattedMessage := err.Error()
1526-
if reformattedMessage == unknownMessage {
1527-
t.Errorf("expected rewritten error, got %q", reformattedMessage)
1528-
}
1529-
}
1530-
1531-
func TestGoGitErrorUnchanged(t *testing.T) {
1532-
// this is (roughly) what GitHub sends if the deploy key doesn't
1533-
// have write access; go-git passes this on verbatim
1534-
regularMessage := `remote: ERROR: deploy key does not have write access`
1535-
expectedReformat := regularMessage
1536-
err := errors.New(regularMessage)
1537-
err = goGitError(err)
1538-
reformattedMessage := err.Error()
1539-
// test that it's been rewritten, without checking the exact content
1540-
if len(reformattedMessage) > len(expectedReformat) {
1541-
t.Errorf("expected %q, got %q", expectedReformat, reformattedMessage)
1542-
}
1543-
}
1544-
1545-
func Fuzz_GoGitError(f *testing.F) {
1546-
f.Add("")
1547-
f.Add("unknown error: remote: ")
1548-
f.Add("some other error")
1549-
1550-
f.Fuzz(func(t *testing.T, msg string) {
1551-
var err error
1552-
if msg != "" {
1553-
err = errors.New(msg)
1554-
}
1555-
1556-
_ = goGitError(err)
1557-
})
1558-
}
1559-
15601519
func initRepo(tmpDir string) (*extgogit.Repository, string, error) {
15611520
sto := filesystem.NewStorage(osfs.New(tmpDir, osfs.WithBoundOS()), cache.NewObjectLRUDefault())
15621521
repo, err := extgogit.Init(sto, memfs.New())

0 commit comments

Comments
 (0)