Skip to content

Conversation

@marcocondrache
Copy link
Contributor

Closes #39469
Closes #39438
Closes #39458

I'm not able to test it, i would appreciate if somebody could do it. I think this bug was present also for SSH remote projects

Release Notes:

  • Fixed an issue where zed bin was not found in remote servers for askpass
…utable itself

Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 3, 2025
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
@notruri
Copy link

notruri commented Oct 3, 2025

lgtm

Zed: v0.208.0 (Zed Dev ed651ea3a0a9d2d7f298d7ea2d62ebc639e8711d) (Taylor's Version)
OS: Windows 10.0.26100
Architecture: x86_64

zed cli helper now works within WSL

Copy link
Collaborator

@maxbrunsfeld maxbrunsfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcocondrache Thanks so much for tracking this down. Nice work.

I would love to solve this in a way that doesn't rely on checking the filename of the current exe.

Here's one way to fix it that I think is cleaner. Let me know if this makes sense to you:

  • We should put back the --askpass argument in the main editor on linux and macOS.
  • There should be a static variable in ask_pass.rs called ASKPASS_PROGRAM (a PathBuf) - the path to the program that should be invoked for askpass. By default, ASKPASS_PROGRAM should be initialized to the current_exe(). On mac and Linux, and in the remote server, it should just be left that way.
  • The askpass module should have a public setter function called set_askpass_program that can override the ASKPASS_PROGRAM. We should only call that function on Windows, in zed::main (passing in the path to the CLI).
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
@marcocondrache
Copy link
Contributor Author

@maxbrunsfeld, thanks for the feedback! That makes perfect sense, and it's a cleaner approach. I will make the changes immediately

Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
@marcocondrache
Copy link
Contributor Author

@maxbrunsfeld I’ve updated the PR with the changes. I moved the logic for turning a path into a shell-safe string into the PathExt trait, since it felt generic enough to live there but if you think it makes more sense somewhere else, I’m happy to move it.

I’m also not too sure about the get_zed_cli_path function since it's called for set_askpass_program. Maybe it’d be simpler to inline that directly in zed::main, but I’ll let you guide what feels best here.

For testing, I can only try things out on macOS. I’ll give it a spin there, but unfortunately I won’t be much help on Linux or Windows 😞

}
}

pub fn set_askpass_program(path: std::path::PathBuf) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: conventionally in Zed we use a fn init() function for initialization of globals related to a given module. That function also resides closer to the top of a file.

Suggested change
pub fn set_askpass_program(path: std::path::PathBuf) {
pub fn init(path: std::path::PathBuf) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think calling it init might be misleading in this case, since it only runs on Windows. Making it run unconditionally could also introduce security concerns - on Unix platforms, current_exe should be called right before use to avoid potential privilege escalation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, we can leave it as is then.


pub fn set_askpass_program(path: std::path::PathBuf) {
if ASKPASS_PROGRAM.set(path).is_err() {
panic!("askpass program has already been set");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could prolly be a debug_panic. We don't want to bring the whole app down, because - while multiple distinct values for ASKPASS_PROGRAM don't make sense - panicking turns a benign bug into a hard crash, even if you don't end up using any remoting functionalities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's super right. I missed the debug_panic macro

Comment on lines 157 to 160

/// Try to make a shell-safe representation of the path.
///
/// For Unix, the path is escaped to be safe for POSIX shells
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a doc comment on the trait method itself, not on it's implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the methods of this trait have the doc comment on the implementations. Should i move all of them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that'd be best.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the doc comments to the trait definition

.to_string())
}

/// Returns a shell escaped path for the zed cli executable, this function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: is this doc comment outdated? The returned path is no longer shell-escaped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, i've missed that

// As of writing, this can only be fail if the path contains a null byte, which shouldn't be possible
// but shlex has annotated the error as #[non_exhaustive] so we can't make it a compile error if other
// errors are introduced in the future :(
Ok(shlex::try_quote(path_str)?.to_string())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Ok(shlex::try_quote(path_str)?.to_string())
Ok(shlex::try_quote(path_str)?.into())

I'm not sure if that'll compile from the get-go, but to_string can be slower than String::from. Not that it matters though, so feel free to disregard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good catch. The method returns Cow, so into() could indeed be faster. I've made the change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, in that case you can even go the extra mile and use into_owned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. Done

Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Copy link
Contributor

@osiewicz osiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Will give it a go with other platforms before merging.

@maxbrunsfeld
Copy link
Collaborator

Thanks so much for the follow ups @marcocondrache

Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
@marcocondrache
Copy link
Contributor Author

@maxbrunsfeld @osiewicz thank you for the support!

@osiewicz
Copy link
Contributor

osiewicz commented Oct 6, 2025

I've tested this on Windows -> Linux and Mac -> Linux SSH scenarios. In both cases it fixed git usage.

@osiewicz osiewicz dismissed maxbrunsfeld’s stale review October 6, 2025 22:49

The author has applied Max's feedback + I've manually tested the code.

@osiewicz osiewicz merged commit 4de13e0 into zed-industries:main Oct 6, 2025
23 checks passed
@osiewicz
Copy link
Contributor

osiewicz commented Oct 8, 2025

/cherry-pick v0.207.x

osiewicz pushed a commit that referenced this pull request Oct 8, 2025
Closes #39469
Closes #39438
Closes #39458

I'm not able to test it, i would appreciate if somebody could do it. I
think this bug was present also for SSH remote projects

Release Notes:

- Fixed an issue where zed bin was not found in remote servers for
askpass

---------

Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Oct 11, 2025
…s#39475)

Closes zed-industries#39469
Closes zed-industries#39438
Closes zed-industries#39458

I'm not able to test it, i would appreciate if somebody could do it. I
think this bug was present also for SSH remote projects

Release Notes:

- Fixed an issue where zed bin was not found in remote servers for
askpass

---------

Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

4 participants