git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git --literal-pathspecs add -u says "fatal: pathspec ':/' did not match any files"

From
Victor Leschuk <vleschuk@gmail.com>
Date
Oct 24, 2015, 07:13 UTC
Message-ID
<562B2FB2.4080604@gmail.com>
In-Reply-To
<CAM-tV--Q=DjTwLk8sZVm7-xMQsGwKmyjy4XiT08QpQ5-dffL0w@mail.gmail.com>
Hello Noam,

The problem is that in the absence of explicit argument we set the list of files to special path ":/" which means repo root:

     if ((0 < addremove_explicit || take_worktree_changes) && !argc) {
         static const char *whole[2] = { ":/", NULL };
         argc = 1;
         argv = whole;
     }
And after that we treat it as regular file
             if (!seen[i] && path[0] &&
                 ((pathspec.items[i].magic &
                   (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
                  !file_exists(path))) {          /* <======== 
file_exists() here just checks lstat() result */
Maybe it'll make sense to modify file_exists() to treat ":/" specially. 
Something like that:
diff --git a/dir.c b/dir.c
index 109ceea..6cae3b9 100644
--- a/dir.c
+++ b/dir.c
@@ -2103,6 +2103,10 @@ int read_directory(struct dir_struct *dir, const 
char *path, int len, const stru
  int file_exists(const char *f)
  {
         struct stat sb;
+       if (!strcmp(f, ":/")) {
+               /* ":/" - root dir, always exists */
+               return 1;
+       }
         return lstat(f, &sb) == 0;
  }

--
Victor

On 10/24/2015 02:39 AM, Noam Postavsky wrote:
> ~/tmp/tmprepo$ git init
> Initialized empty Git repository in /home/npostavs/tmp/tmprepo/.git/
> ~/tmp/tmprepo$ git --literal-pathspecs add -u
> fatal: pathspec ':/' did not match any files
> ~/tmp/tmprepo$ git --version
> git version 2.6.1
>
> It was reported[1] that 2.0.2 and several following versions also fail
> with the same error; I found that version 1.9.5 succeeds.
>
> Adding a "." argument:
>
>     git --literal-pathspecs add -u .
>
> succeeds in all versions.
>
> [1]: https://github.com/magit/magit/issues/2354#issuecomment-150665961
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous: Noam PostavskyNext: Noam Postavsky
Message 2 of 4 in “git --literal-pathspecs add -u says "fatal: pathspec ':/' did not match any files"”
  1. Noam PostavskyOct 23, 2015
  2. Victor LeschukOct 24, 2015
  3. Noam PostavskyOct 24, 2015
  4. Re* git --literal-pathspecs add -u says "fatal: pathspec ':/' did not match any files"Junio C Hamano, Oct 24, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.