Skip to content

Commit 1dd6835

Browse files
authored
chore: refactor gitrepo.go (#2272)
- Replace `==` to `errors.Is()` when comparing errors.
1 parent 083b15a commit 1dd6835

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

internal/gitrepo/gitrepo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func (r *LocalRepository) GetCommitsForPathsSinceCommit(paths []string, sinceCom
288288
if len(paths) == 0 {
289289
return nil, errors.New("no paths to check for commits")
290290
}
291-
commits := []*Commit{}
291+
var commits []*Commit
292292
finalHash := plumbing.NewHash(sinceCommit)
293293
logOptions := git.LogOptions{Order: git.LogOrderCommitterTime}
294294
logIterator, err := r.repo.Log(&logOptions)
@@ -343,10 +343,10 @@ func (r *LocalRepository) GetCommitsForPathsSinceCommit(paths []string, sinceCom
343343

344344
return nil
345345
})
346-
if err != nil && err != ErrStopIterating {
346+
if err != nil && !errors.Is(err, ErrStopIterating) {
347347
return nil, err
348348
}
349-
if sinceCommit != "" && err != ErrStopIterating {
349+
if sinceCommit != "" && !errors.Is(err, ErrStopIterating) {
350350
return nil, fmt.Errorf("did not find commit %s when iterating", sinceCommit)
351351
}
352352
return commits, nil
@@ -360,7 +360,7 @@ func getHashForPathOrEmpty(commit *object.Commit, path string) (string, error) {
360360
return "", err
361361
}
362362
treeEntry, err := tree.FindEntry(path)
363-
if err == object.ErrEntryNotFound || err == object.ErrDirectoryNotFound {
363+
if errors.Is(err, object.ErrEntryNotFound) || errors.Is(err, object.ErrDirectoryNotFound) {
364364
return "", nil
365365
}
366366
if err != nil {

internal/librarian/commit_version_analyzer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func TestGetConventionalCommitsSinceLastRelease(t *testing.T) {
152152
wantErrPhrase string
153153
}{
154154
{
155-
name: "get commits for foo",
155+
name: "get_commits_for_foo",
156156
repo: repoWithCommits,
157157
library: &config.LibraryState{
158158
ID: "foo",

0 commit comments

Comments
 (0)