Browse Source

capture git fetch output when debug output is enabled

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 8 months ago
parent
commit
ee33143026
1 changed files with 18 additions and 1 deletions
  1. 18 1
      pkg/remote/git.go

+ 18 - 1
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"] == "" {