From f23ea48c913d6f907f499e0315c4658632d20d29 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 31 Jul 2024 15:55:56 -0400 Subject: [PATCH] fix(ssh): pass GIT_PROTOCOL from ssh session down to binary Fixes: 4daebdd422a6 (sec: do not append session envs to git run (#544)) --- pkg/ssh/cmd/git.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/ssh/cmd/git.go b/pkg/ssh/cmd/git.go index d8584e45..7265c9a7 100644 --- a/pkg/ssh/cmd/git.go +++ b/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()