Skip to content

git add cannot add file with path . #12948

Closed

Description

@eggcaker

Describe the bug

cannot use git add . to add file to git

$ git add .
fatal: empty string is not a valid pathspec. please use . instead if you meant to match all paths

How to reproduce

  1. add some new file to a git repo
  2. run git add . to add file

Expected behavior

should add file with git add . not git add ./file1`

Screenshots

No response

Configuration

key value
version 0.93.1
major 0
minor 93
patch 1
branch main
commit_hash bf07806
build_os macos-aarch64
build_target aarch64-apple-darwin
rust_version rustc 1.77.2 (25ef9e3d8 2024-04-09)
rust_channel 1.77.2-aarch64-apple-darwin
cargo_version cargo 1.77.2 (e52e36006 2024-03-26)
build_time 2024-05-24 06:35:19 +08:00
build_rust_channel release
allocator mimalloc
features default, sqlite, system-clipboard, trash, which
installed_plugins formats, polars, query, regex

Additional context

commit: 75689ec works

Activity

  1. added
    status:needs-triage
    on May 24, 2024
  2. yizhepku commented on May 24, 2024

    @yizhepku
    Contributor

    This is caused by PR #12921, which changed how arguments to external commands are expanded.

    Here's how the bug works. Nushell will perform glob-expansion on any bare strings, and since . is considered a bare string, it is expanded into an absolute path (e.g. /tmp/.). Since working with absolute paths is tedious (^ls * would print a bunch of absolute paths), we also use Path::strip_prefix() against the current directory to shorten the path when possible. However, Path::strip_prefix() has this weird behavior where if you shorten /tmp/. against /tmp, you get an empty path instead of ., which causes this bug.

    Technically speaking, the behavior of Path::strip_prefix() is correct because the standard library considers /tmp/. and /tmp equal. I think adding a special case for this should suffice?

  3. added
    category:bug
    A:external-commands
    A:glob
    and removed
    status:needs-triage
    on May 25, 2024
  4. added this to the v0.94.0 milestone on May 25, 2024
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

    A:external-commandsA:globcategory:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions