Skip to content

..branchname in git log ..branchname is expanded by nushell #5131

Closed

Description

@devurandom

Describe the bug

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

  1. Try to run git log ..staging
  2. 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.

Screenshots

No response

Configuration

key value
version 0.60.0
build_os linux-x86_64
rust_version rustc 1.59.0 (gentoo)
cargo_version cargo 1.59.0
pkg_version 0.60.0
build_time 2022-03-25 19:35:23 +01:00
build_rust_channel release
features dataframe, default, trash, which, zip
installed_plugins

Additional context

See-also: #4205

Activity

  1. added
    category:bug
    on Apr 8, 2022
  2. strega-nil commented on Apr 11, 2022

    @strega-nil
    Contributor

    I did a bisection; it looks like:

    41dbc641ccdd34ed05076b389d0d181b66baabbf
    b4c72e85e12f7a80ccc3d30164d53533f53ce901
    

    are the bad commits.

    To me, it looks like the bad change was:

    --- 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
         }
  3. sophiajt commented on Apr 11, 2022

    @sophiajt
    Contributor

    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

  4. strega-nil commented on Apr 11, 2022

    @strega-nil
    Contributor

    @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.

  5. added 3 commits that reference this issue on Apr 11, 2022
    5f945f0
    76872f9
    c581607
  6. added this to the v0.61.0 milestone on Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions