capture git fetch output when debug output is enabled

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2025-04-08 11:36:06 +02:00 committed by Nicolas De loof
parent cb0b5f6e27
commit ee33143026

View File

@ -17,6 +17,8 @@
package remote
import (
"bufio"
"bytes"
"context"
"fmt"
"os"
@ -31,6 +33,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/pkg/api"
"github.com/moby/buildkit/util/gitutil"
"github.com/sirupsen/logrus"
)
const GIT_REMOTE_ENABLED = "COMPOSE_EXPERIMENTAL_GIT_REMOTE"
@ -169,7 +172,8 @@ func (g gitRemoteLoader) checkout(ctx context.Context, path string, ref *gitutil
cmd = exec.CommandContext(ctx, "git", "fetch", "--depth=1", "origin", ref.Commit)
cmd.Env = g.gitCommandEnv()
cmd.Dir = path
err = cmd.Run()
err = g.run(cmd)
if err != nil {
return err
}
@ -183,6 +187,19 @@ func (g gitRemoteLoader) checkout(ctx context.Context, path string, ref *gitutil
return nil
}
func (g gitRemoteLoader) run(cmd *exec.Cmd) error {
if logrus.IsLevelEnabled(logrus.DebugLevel) {
output, err := cmd.CombinedOutput()
scanner := bufio.NewScanner(bytes.NewBuffer(output))
for scanner.Scan() {
line := scanner.Text()
logrus.Debug(line)
}
return err
}
return cmd.Run()
}
func (g gitRemoteLoader) gitCommandEnv() []string {
env := types.NewMapping(os.Environ())
if env["GIT_TERMINAL_PROMPT"] == "" {