From 553ae43ee34f7c9f52ed01d8363b88b4eabc52a7 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 8 Apr 2025 11:36:06 +0200 Subject: [PATCH] capture git fetch output when debug output is enabled Signed-off-by: Nicolas De Loof --- pkg/remote/git.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/remote/git.go b/pkg/remote/git.go index 4668d907555..ca170daf528 100644 --- a/pkg/remote/git.go +++ b/pkg/remote/git.go @@ -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"] == "" {