Skip to content

Commit

Permalink
allow suppressing the git clone output by setting the quiet option (#335
Browse files Browse the repository at this point in the history
)
  • Loading branch information
a-zen authored Nov 29, 2021
1 parent 33cff1e commit 254e928
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions artifact/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Option struct {
DisabledHooks []hook.Type
SkipFiles []string
SkipDirs []string
Quiet bool
}

func (o *Option) Sort() {
Expand Down
11 changes: 9 additions & 2 deletions artifact/remote/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ func NewArtifact(rawurl string, c cache.ArtifactCache, artifactOpt artifact.Opti
return nil, cleanup, err
}

_, err = git.PlainClone(tmpDir, false, &git.CloneOptions{
cloneOptions := git.CloneOptions{
URL: u.String(),
Auth: gitAuth(),
Progress: os.Stdout,
Depth: 1,
})
}

// suppress clone output if quiet
if artifactOpt.Quiet {
cloneOptions.Progress = nil
}

_, err = git.PlainClone(tmpDir, false, &cloneOptions)
if err != nil {
return nil, cleanup, xerrors.Errorf("git error: %w", err)
}
Expand Down
14 changes: 13 additions & 1 deletion artifact/remote/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestNewArtifact(t *testing.T) {
type args struct {
rawurl string
c cache.ArtifactCache
quiet bool
}
tests := []struct {
name string
Expand All @@ -49,13 +50,23 @@ func TestNewArtifact(t *testing.T) {
args: args{
rawurl: ts.URL + "/test.git",
c: nil,
quiet: false,
},
},
{
name: "happy quiet",
args: args{
rawurl: ts.URL + "/test.git",
c: nil,
quiet: true,
},
},
{
name: "sad path",
args: args{
rawurl: ts.URL + "/unknown.git",
c: nil,
quiet: false,
},
wantErr: true,
},
Expand All @@ -64,14 +75,15 @@ func TestNewArtifact(t *testing.T) {
args: args{
rawurl: "ht tp://foo.com",
c: nil,
quiet: false,
},
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, cleanup, err := NewArtifact(tt.args.rawurl, tt.args.c, artifact.Option{}, config.ScannerOption{})
_, cleanup, err := NewArtifact(tt.args.rawurl, tt.args.c, artifact.Option{Quiet: tt.args.quiet}, config.ScannerOption{})
assert.Equal(t, tt.wantErr, err != nil)
defer cleanup()
})
Expand Down

0 comments on commit 254e928

Please sign in to comment.