diff --git a/go.mod b/go.mod index d8c8ec0f..3d684b5d 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/joho/godotenv v1.3.0 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect + github.com/mattn/go-isatty v0.0.12 github.com/mitchellh/go-homedir v1.1.0 github.com/moby/buildkit v0.8.1 github.com/moby/sys/mount v0.2.0 // indirect diff --git a/pkg/common/git.go b/pkg/common/git.go index db98f81f..a066856b 100644 --- a/pkg/common/git.go +++ b/pkg/common/git.go @@ -17,6 +17,7 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/transport/http" "github.com/go-ini/ini" + "github.com/mattn/go-isatty" log "github.com/sirupsen/logrus" ) @@ -238,29 +239,25 @@ func CloneIfRequired(ctx context.Context, refName plumbing.ReferenceName, input r, err := git.PlainOpen(input.Dir) if err != nil { var progressWriter io.Writer - if entry, ok := logger.(*log.Entry); ok { - progressWriter = entry.WriterLevel(log.DebugLevel) - } else if lgr, ok := logger.(*log.Logger); ok { - progressWriter = lgr.WriterLevel(log.DebugLevel) - } else { - log.Errorf("Unable to get writer from logger (type=%T)", logger) - progressWriter = os.Stdout + if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) { + if entry, ok := logger.(*log.Entry); ok { + progressWriter = entry.WriterLevel(log.DebugLevel) + } else if lgr, ok := logger.(*log.Logger); ok { + progressWriter = lgr.WriterLevel(log.DebugLevel) + } else { + log.Errorf("Unable to get writer from logger (type=%T)", logger) + progressWriter = os.Stdout + } } - var cloneOptions git.CloneOptions + cloneOptions := git.CloneOptions{ + URL: input.URL, + Progress: progressWriter, + } if input.Token != "" { - cloneOptions = git.CloneOptions{ - URL: input.URL, - Progress: progressWriter, - Auth: &http.BasicAuth{ - Username: "token", - Password: input.Token, - }, - } - } else { - cloneOptions = git.CloneOptions{ - URL: input.URL, - Progress: progressWriter, + cloneOptions.Auth = &http.BasicAuth{ + Username: "token", + Password: input.Token, } }