Skip to content

Commit c1d1e1d

Browse files
f0sselkylecarbs
authored andcommitted
Add coder executable to PATH (#1771)
1 parent 4b6afe1 commit c1d1e1d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

agent/agent.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,11 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
359359
if err != nil {
360360
return nil, xerrors.Errorf("getting os executable: %w", err)
361361
}
362+
cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%c%s`, os.Getenv("PATH"), filepath.ListSeparator, executablePath))
362363
// Git on Windows resolves with UNIX-style paths.
363364
// If using backslashes, it's unable to find the executable.
364-
executablePath = strings.ReplaceAll(executablePath, "\\", "/")
365-
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, executablePath))
365+
unixExecutablePath := strings.ReplaceAll(executablePath, "\\", "/")
366+
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, unixExecutablePath))
366367
// These prevent the user from having to specify _anything_ to successfully commit.
367368
// Both author and committer must be set!
368369
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_AUTHOR_EMAIL=%s`, metadata.OwnerEmail))

agent/agent_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ 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+
t.Log(ex)
82+
require.NoError(t, err)
83+
require.True(t, strings.Contains(strings.TrimSpace(string(output)), ex), string(output), ex)
84+
})
85+
7186
t.Run("SessionTTY", func(t *testing.T) {
7287
t.Parallel()
7388
if runtime.GOOS == "windows" {

0 commit comments

Comments
 (0)