From de7536536e557b2225064971cec3da2f5aebad41 Mon Sep 17 00:00:00 2001 From: Kunall Banerjee Date: Tue, 19 May 2026 04:48:04 -0400 Subject: [PATCH] dev_container: Start containers from the project directory The initializeCommand lifecycle hook already runs with cwd set to the project directory, but the subsequent docker run / podman run inherited Zed's own working directory. Relative paths in runArgs such as --env-file .devcontainer/.env therefore failed to resolve. Set current_dir on the spawned command so relative runArgs paths line up with where lifecycle scripts already run, matching the behavior of the upstream devcontainer CLI. Add a get_current_dir accessor on util::command::Command so the regression test can verify the working directory is set. --- crates/dev_container/src/devcontainer_manifest.rs | 7 +++++++ crates/util/src/command.rs | 4 ++++ crates/util/src/command/darwin.rs | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/crates/dev_container/src/devcontainer_manifest.rs b/crates/dev_container/src/devcontainer_manifest.rs index fe1dbe7b9a8..d88264dde6d 100644 --- a/crates/dev_container/src/devcontainer_manifest.rs +++ b/crates/dev_container/src/devcontainer_manifest.rs @@ -1841,6 +1841,7 @@ RUN sed -i -E 's/((^|\s)PATH=)([^\$]*)$/\1\${PATH:-\3}/g' /etc/profile || true let docker_cli = self.docker_client.docker_cli(); let mut command = Command::new(&docker_cli); + command.current_dir(&self.local_project_directory); command.arg("run"); @@ -3100,6 +3101,12 @@ mod test { let docker_run_command = docker_run_command.expect("ok"); assert_eq!(docker_run_command.get_program(), "docker"); + assert_eq!( + docker_run_command.get_current_dir(), + Some(Path::new(TEST_PROJECT_PATH)), + "docker run must execute with cwd set to the project directory so \ + relative paths in `runArgs` (e.g. `--env-file .devcontainer/.env`) resolve correctly" + ); let expected_config_file_label = PathBuf::from(TEST_PROJECT_PATH) .join(".devcontainer") .join("devcontainer.json"); diff --git a/crates/util/src/command.rs b/crates/util/src/command.rs index a131d3c15b9..265e1c47747 100644 --- a/crates/util/src/command.rs +++ b/crates/util/src/command.rs @@ -72,6 +72,10 @@ impl Command { self.0.get_args() } + pub fn get_current_dir(&self) -> Option<&Path> { + self.0.get_current_dir() + } + pub fn env(&mut self, key: impl AsRef, val: impl AsRef) -> &mut Self { self.0.env(key, val); self diff --git a/crates/util/src/command/darwin.rs b/crates/util/src/command/darwin.rs index a3d7561f4e3..5ead023c8eb 100644 --- a/crates/util/src/command/darwin.rs +++ b/crates/util/src/command/darwin.rs @@ -225,6 +225,10 @@ impl Command { pub fn get_program(&self) -> &OsStr { self.program.as_os_str() } + + pub fn get_current_dir(&self) -> Option<&Path> { + self.current_dir.as_deref() + } } #[derive(Debug)]