Skip to content

Commit eccff0f

Browse files
committed
feat: reverted code that did not need changing
1 parent 871d7a7 commit eccff0f

4 files changed

Lines changed: 24 additions & 17 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ __pycache__
2525

2626
# binaries
2727
/mach-composer
28+
**/.mach-composer
2829
/local
29-
/result
30+
/result

internal/gitutils/diff.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gitutils
22

33
import (
4+
"context"
45
"fmt"
56
"strings"
67

@@ -28,8 +29,8 @@ func pathFilter(paths []string) func(path string) bool {
2829

2930
// commitsBetween returns the commits between revisions first and last. It should equal the functionality of
3031
// `git log base..head`. See https://github.com/go-git/go-git/issues/69
31-
func commitsBetween(repository *git.Repository, first, last *plumbing.Revision, paths []string) ([]*object.Commit, error) {
32-
log.Debug().Msgf("Getting commits between %s and %s (paths = %s)", first, last, paths)
32+
func commitsBetween(ctx context.Context, repository *git.Repository, first, last *plumbing.Revision, paths []string) ([]*object.Commit, error) {
33+
log.Ctx(ctx).Debug().Msgf("Getting commits between %s and %s (paths = %s)", first, last, paths)
3334
if first != nil {
3435
_, err := repository.ResolveRevision(*first)
3536
if err != nil {
@@ -43,7 +44,7 @@ func commitsBetween(repository *git.Repository, first, last *plumbing.Revision,
4344
var firstCommit *object.Commit
4445
if first != nil {
4546
if val, err := repository.ResolveRevision(*first); err != nil {
46-
log.Warn().Err(err).Msgf("failed to resolve %s in repository", first.String())
47+
log.Ctx(ctx).Warn().Err(err).Msgf("failed to resolve %s in repository", first.String())
4748
return []*object.Commit{}, nil
4849
} else {
4950
firstHash = val
@@ -85,7 +86,7 @@ func commitsBetween(repository *git.Repository, first, last *plumbing.Revision,
8586
}
8687
if firstCommit != nil && firstCommit.Committer.When.After(c.Committer.When) {
8788
found = false
88-
log.Info().Msgf("Did not find commit %s in path but next older commit %s in paths %s", first, c.Hash, paths)
89+
log.Ctx(ctx).Info().Msgf("Did not find commit %s in path but next older commit %s in paths %s", first, c.Hash, paths)
8990
return storer.ErrStop
9091
}
9192

@@ -96,7 +97,7 @@ func commitsBetween(repository *git.Repository, first, last *plumbing.Revision,
9697
return nil, err
9798
}
9899
if !found {
99-
log.Info().Msgf("found commit %s in %s but failed to find changes in paths %s", first, last, paths)
100+
log.Ctx(ctx).Info().Msgf("found commit %s in %s but failed to find changes in paths %s", first, last, paths)
100101
}
101102

102103
return result, nil

internal/gitutils/diff_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gitutils
22

33
import (
4+
"context"
45
"github.com/go-git/go-git/v5/plumbing"
56
"github.com/stretchr/testify/assert"
67
"github.com/stretchr/testify/require"
@@ -27,12 +28,13 @@ func TestCommitsBetweenResolveFirstError(t *testing.T) {
2728
secondHash, err := tr.commit("Second commit")
2829
require.NoError(t, err)
2930

31+
ctx := context.Background()
3032
targetRev := plumbing.Revision(secondHash.String())
3133

3234
badRev := plumbing.Revision("test")
3335

3436
// Check results
35-
_, err = commitsBetween(tr.repository(), &badRev, &targetRev, []string{})
37+
_, err = commitsBetween(ctx, tr.repository(), &badRev, &targetRev, []string{})
3638
require.Error(t, err)
3739
}
3840

@@ -53,14 +55,16 @@ func TestCommitsBetween(t *testing.T) {
5355
secondHash, err := tr.commit("Second commit")
5456
require.NoError(t, err)
5557

58+
ctx := context.Background()
59+
5660
targetRev := plumbing.Revision(secondHash.String())
5761
baseRev := plumbing.Revision(firstHash.String())
5862

59-
commits, err := commitsBetween(tr.repository(), nil, &targetRev, []string{})
63+
commits, err := commitsBetween(ctx, tr.repository(), nil, &targetRev, []string{})
6064
require.NoError(t, err)
6165
assert.Equal(t, 2, len(commits))
6266

63-
commits, err = commitsBetween(tr.repository(), &baseRev, &targetRev, []string{})
67+
commits, err = commitsBetween(ctx, tr.repository(), &baseRev, &targetRev, []string{})
6468
require.NoError(t, err)
6569
assert.Equal(t, 1, len(commits))
6670
}
@@ -96,14 +100,15 @@ func TestCommitsBetweenFilterPath(t *testing.T) {
96100
thirdHash, err := tr.commit("third commit")
97101
require.NoError(t, err)
98102

103+
ctx := context.Background()
99104
targetRev := plumbing.Revision(thirdHash.String())
100105

101106
// Check results
102-
commits, err := commitsBetween(tr.repository(), nil, &targetRev, []string{})
107+
commits, err := commitsBetween(ctx, tr.repository(), nil, &targetRev, []string{})
103108
require.NoError(t, err)
104109
assert.Equal(t, 3, len(commits))
105110

106-
commits, err = commitsBetween(tr.repository(), nil, &targetRev, []string{"wanted/"})
111+
commits, err = commitsBetween(ctx, tr.repository(), nil, &targetRev, []string{"wanted/"})
107112
require.NoError(t, err)
108113
assert.Equal(t, 1, len(commits))
109114
}

internal/gitutils/git.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ func commitExists(ctx context.Context, gitPath, baseRevision, targetRevision str
201201
return nil
202202
}
203203

204-
func determineRevision(repository *git.Repository, revision string) *plumbing.Revision {
204+
func determineRevision(ctx context.Context, repository *git.Repository, revision string) *plumbing.Revision {
205205
tagRef, err := repository.Tag(revision)
206206
if err == nil {
207-
log.Debug().Msgf("Found tag %s. Using revision %s to determine updates", tagRef.Name().Short(),
207+
log.Ctx(ctx).Debug().Msgf("Found tag %s. Using revision %s to determine updates", tagRef.Name().Short(),
208208
tagRef.Hash().String())
209209
return asRevision(tagRef.Hash().String())
210210
}
@@ -225,14 +225,14 @@ func GetRecentCommits(ctx context.Context, basePath string, baseRevision, target
225225
return nil, fmt.Errorf("failed to open repository: %w", err)
226226
}
227227

228-
baseRev := determineRevision(repository, baseRevision)
228+
baseRev := determineRevision(ctx, repository, baseRevision)
229229
targetRev := asRevision(targetRevision)
230230

231231
if err = commitExists(ctx, gitPath, baseRevision, targetRevision); err != nil {
232232
return nil, err
233233
}
234234

235-
commits, err := commitsBetween(repository, baseRev, targetRev, filterPaths)
235+
commits, err := commitsBetween(ctx, repository, baseRev, targetRev, filterPaths)
236236
if err != nil {
237237
return nil, err
238238
}
@@ -333,11 +333,11 @@ func fetchGitRepository(ctx context.Context, source *GitSource, dest string) {
333333
_, err := os.Stat(dest)
334334
if os.IsNotExist(err) {
335335
output, _ := runGit(ctx, ".", "clone", "--bare", source.Repository, dest)
336-
log.Debug().
336+
log.Ctx(ctx).Debug().
337337
Msgf("downloaded new repository %s at destination %s: %s", source.Name, dest, string(output))
338338
} else {
339339
output, _ := runGit(ctx, dest, "fetch", "-f", "origin", "*:*")
340-
log.Debug().
340+
log.Ctx(ctx).Debug().
341341
Msgf("updated existing repository %s at destination %s: %s", source.Name, dest, string(output))
342342
}
343343
}

0 commit comments

Comments
 (0)