Skip to content

Commit

Permalink
Fixed error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Carlson committed Mar 21, 2023
1 parent 61237e5 commit 28863bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions pkg/git/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,36 @@ func (f Fetcher) Fetch(dir, gitURL, gitRevision, metadataDir string) error {
Auth: auth,
})
if err != nil && err != transport.ErrAuthenticationRequired {
return errors.Wrapf(err, "unable to fetch references for git repository: %s", gitURL)
return errors.Wrapf(err, "unable to fetch references for repository")
} else if err == transport.ErrAuthenticationRequired {
return errors.Wrapf(err, "invalid credentials for git repository: %s", gitURL)
return errors.Wrapf(err, "invalid credentials for repository")
}

worktree, err := repository.Worktree()
if err != nil {
return errors.Wrapf(err, "getting worktree for git repository: %s", gitURL)
return errors.Wrapf(err, "getting worktree for repository")
}

hash, err := repository.ResolveRevision(plumbing.Revision(gitRevision))
if err != nil {
return errors.Wrapf(err, "resolving revision `%s` for git repository: %s", gitRevision, gitURL)
return errors.Wrapf(err, "resolving revision")
}

err = worktree.Checkout(&gogit.CheckoutOptions{Hash: *hash})
if err != nil {
return errors.Wrapf(err, "checking out revision `%s` for git repository: %s", gitRevision, gitURL)
return errors.Wrapf(err, "checking out revision")
}

// copy tmpDir to dir
err = os.RemoveAll(dir)
if err != nil {
return errors.Wrapf(err, "removing directory '%s' for git repository: %s", dir, gitURL)
return errors.Wrapf(err, "removing directory")
}

// recursive copy of tmpDir to dir
err = copyDir(dir, tmpDir)
if err != nil {
return errors.Wrapf(err, "copying directory '%s' to '%s' for git repository: %s", tmpDir, dir, gitURL)
return errors.Wrapf(err, "copying directory")
}

// Write the git revision to the metadata directory
Expand Down
4 changes: 2 additions & 2 deletions pkg/git/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func testGitCheckout(t *testing.T, when spec.G, it spec.S) {

it("returns error on non-existent ref", func() {
err := fetcher.Fetch(testDir, "https://github.com/git-fixtures/basic", "doesnotexist", metadataDir)
require.EqualError(t, err, "resolving revision `doesnotexist` for git repository: https://github.com/git-fixtures/basic: reference not found")
require.EqualError(t, err, "resolving revision: reference not found")
})

it("returns invalid credentials to fetch error on authentication required", func() {
err := fetcher.Fetch(testDir, "git@bitbucket.com:org/repo", "main", metadataDir)
require.ErrorContains(t, err, "unable to fetch references for git repository")
require.ErrorContains(t, err, "unable to fetch references for repository")
})

it("uses the http proxy env vars", func() {
Expand Down

0 comments on commit 28863bf

Please sign in to comment.