You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
..branchname in git log ..branchname is expanded by nushell #5131
Double dots (..) in arguments to external commands appear to be expanded by nushell:
❯ git log ..staging
fatal: ambiguous argument '[REDACTED ABSOLUTE PATH]/..staging': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Also quoting ..staging (git log "..staging" or git log '..staging') does not help: The error returned by git is exactly the same. Escaping the dots (..staging -> \.\.staging) makes nushell no longer expand them, but also passes them literally to git, which then cannot find the path. This is the same when quoting the argument ('..staging' -> '\.\.staging', "..staging" -> "\.\.staging").
How to reproduce
Try to run git log ..staging
Observe an error printed by git
Expected behavior
I would expect nushell to not expand arguments that are not valid paths. In fact as a bash and fish user, it comes unexpected that it expands regular paths at all, i.e. paths that do not contain * or ~. At the very least I would expect there to be an obvious way to prevent this expansion and pass an argument literally, as I wrote it, to the command.
--- good/crates/nu-command/src/system/run_external.rs+++ bad/crates/nu-command/src/system/run_external.rs@@ -260,15 +261,21 @@
/// Spawn a command without shelling out to an external shell
fn spawn_simple_command(&self) -> std::process::Command {
let mut process = std::process::Command::new(&self.name.item);
for arg in &self.args {
let arg = trim_enclosing_quotes(arg);
- let arg = nu_path::expand_path(arg).to_string_lossy().to_string();+ let arg = if arg.starts_with('~') || arg.starts_with("..") {+ nu_path::expand_path_with(arg, cwd)+ .to_string_lossy()+ .to_string()+ } else {+ arg+ };
let arg = arg.replace("\\", "\\\\");
process.arg(&arg);
}
process
}
That looks like the engine-q PR. It changed a bunch of things, so we'd probably be better off trying to code before it landed and looking for parser differences that need to get ported into the new parser
@jntrnr it looks like it's just that it switched from expand_path to expand_path_with, and the check wasn't correct - it needs to check for arg.starts_with("~/") or something like that.
Activity
strega-nil commentedon Apr 11, 2022
I did a bisection; it looks like:
are the bad commits.
To me, it looks like the bad change was:
sophiajt commentedon Apr 11, 2022
That looks like the engine-q PR. It changed a bunch of things, so we'd probably be better off trying to code before it landed and looking for parser differences that need to get ported into the new parser
strega-nil commentedon Apr 11, 2022
@jntrnr it looks like it's just that it switched from
expand_pathtoexpand_path_with, and the check wasn't correct - it needs to check forarg.starts_with("~/")or something like that.fix nushell#5131
fix nushell#5131
fix nushell#5131
don't join paths to cwd ever in calls to external functions (#5180)