1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

Write git clone progress only if terminal is a TTY (#670)

This commit is contained in:
Markus Wolf 2021-05-06 15:55:23 +02:00 committed by GitHub
parent 707067856b
commit 133e8a4475

View file

@ -17,6 +17,7 @@ import (
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/transport/http" "github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-ini/ini" "github.com/go-ini/ini"
"github.com/mattn/go-isatty"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -238,6 +239,7 @@ func CloneIfRequired(ctx context.Context, refName plumbing.ReferenceName, input
r, err := git.PlainOpen(input.Dir) r, err := git.PlainOpen(input.Dir)
if err != nil { if err != nil {
var progressWriter io.Writer var progressWriter io.Writer
if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
if entry, ok := logger.(*log.Entry); ok { if entry, ok := logger.(*log.Entry); ok {
progressWriter = entry.WriterLevel(log.DebugLevel) progressWriter = entry.WriterLevel(log.DebugLevel)
} else if lgr, ok := logger.(*log.Logger); ok { } else if lgr, ok := logger.(*log.Logger); ok {
@ -246,21 +248,16 @@ func CloneIfRequired(ctx context.Context, refName plumbing.ReferenceName, input
log.Errorf("Unable to get writer from logger (type=%T)", logger) log.Errorf("Unable to get writer from logger (type=%T)", logger)
progressWriter = os.Stdout progressWriter = os.Stdout
} }
}
var cloneOptions git.CloneOptions cloneOptions := git.CloneOptions{
if input.Token != "" {
cloneOptions = git.CloneOptions{
URL: input.URL, URL: input.URL,
Progress: progressWriter, Progress: progressWriter,
Auth: &http.BasicAuth{ }
if input.Token != "" {
cloneOptions.Auth = &http.BasicAuth{
Username: "token", Username: "token",
Password: input.Token, Password: input.Token,
},
}
} else {
cloneOptions = git.CloneOptions{
URL: input.URL,
Progress: progressWriter,
} }
} }