Skip to content

Commit 3e3247d

Browse files
committed
Add test for PATH
1 parent 2fa0e2d commit 3e3247d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

agent/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
363363
// If using backslashes, it's unable to find the executable.
364364
executablePath = strings.ReplaceAll(executablePath, "\\", "/")
365365
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, executablePath))
366-
cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%s%s`, os.Getenv("PATH"), os.PathListSeparator, executablePath))
366+
cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%b%s`, os.Getenv("PATH"), os.PathListSeparator, executablePath))
367367
// These prevent the user from having to specify _anything_ to successfully commit.
368368
// Both author and committer must be set!
369369
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_AUTHOR_EMAIL=%s`, metadata.OwnerEmail))

agent/agent_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ func TestAgent(t *testing.T) {
6868
require.True(t, strings.HasSuffix(strings.TrimSpace(string(output)), "gitssh --"))
6969
})
7070

71+
t.Run("PATHHasCoder", func(t *testing.T) {
72+
t.Parallel()
73+
session := setupSSHSession(t, agent.Metadata{})
74+
command := "sh -c 'echo $PATH'"
75+
if runtime.GOOS == "windows" {
76+
command = "cmd.exe /c echo %PATH%"
77+
}
78+
output, err := session.Output(command)
79+
require.NoError(t, err)
80+
ex, err := os.Executable()
81+
require.NoError(t, err)
82+
require.True(t, strings.HasSuffix(strings.TrimSpace(string(output)), ex), string(output))
83+
})
84+
7185
t.Run("SessionTTY", func(t *testing.T) {
7286
t.Parallel()
7387
if runtime.GOOS == "windows" {

0 commit comments

Comments
 (0)