fix(ssh): pass GIT_PROTOCOL from ssh session down to binary

Ayman Bagabas created

Fixes: 4daebdd422a6 (sec: do not append session envs to git run (#544))

Change summary

pkg/ssh/cmd/git.go | 11 +++++++++++
1 file changed, 11 insertions(+)

Detailed changes

pkg/ssh/cmd/git.go 🔗

@@ -3,6 +3,7 @@ package cmd
 import (
 	"errors"
 	"path/filepath"
+	"strings"
 	"time"
 
 	"github.com/charmbracelet/log"
@@ -204,6 +205,16 @@ func gitRunE(cmd *cobra.Command, args []string) error {
 
 	envs = append(envs, cfg.Environ()...)
 
+	// Add GIT_PROTOCOL from session.
+	if sess := sshutils.SessionFromContext(ctx); sess != nil {
+		for _, env := range sess.Environ() {
+			if strings.HasPrefix(env, "GIT_PROTOCOL=") {
+				envs = append(envs, env)
+				break
+			}
+		}
+	}
+
 	repoPath := filepath.Join(reposDir, repoDir)
 	service := git.Service(cmd.Name())
 	stdin := cmd.InOrStdin()