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

"git add" with several pathspecS and one doesn't match

From
GBGoffredo Baroncelli <kreijack@gmail.com>
Date
Feb 14, 2018, 18:31 UTC
Message-ID
<d5e4138e-d5d6-3a84-a222-8d0170a52ccb@gmail.com>
Hi All,
I am facing this issue: I am ADDing some file with several pathspec, and one of these fails. The results is that no file is added at all.
Simple test case:
$ git init .
$ touch 123.txt
$ git add "*.txt" "*.doc"
fatal: pathspec '*.doc' did not match any files
$ git status
[...]
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	123.txt
[...]
Results: no file is added
Expected results: the files which match any pathspec should be added
Looking at the code, git works properly:
from builtins/add.c, near line 500
[...]
		for (i = 0; i < pathspec.nr; i++) {
			const char *path = pathspec.items[i].match;
			if (pathspec.items[i].magic & PATHSPEC_EXCLUDE)
				continue;
			if (!seen[i] && path[0] &&
			    ((pathspec.items[i].magic &
			      (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
			     !file_exists(path))) {
				if (ignore_missing) {
					int dtype = DT_UNKNOWN;
					if (is_excluded(&dir, &the_index, path, &dtype))
						dir_add_ignored(&dir, &the_index,
								path, pathspec.items[i].len);
				} else
					die(_("pathspec '%s' did not match any files"),
					    pathspec.items[i].original);
			}
		}
It seems that if any pathspec doesn't match, all add action fails. Which is the rationale of this choice ? I would expect that an error message would be printed, but the matched files would be added.

My use case is the following: I use "git" as backup system, and I do something like: $ git add paths/*.doc $ git add paths/*.pdf $ git commit -m "bla bla"

I know that git is not the best method for that, however we have a lot of files which are moved between different directories, and git seems to handle this job quite nicely. Unfortunately the filesystem is quite slow and quite huge, so I would prefer to do a single "git add", in order to avoid to traverse all the filesystem more times. But this would not work because if one pathspce fails, it prevents all other pathspecs to success.

Please put me in CC because I am not subscribed.

BR G.Baroncelli

-- 
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
Next: Junio C Hamano
Message 1 of 2 in “"git add" with several pathspecS and one doesn't match”
  1. Goffredo BaroncelliFeb 14, 2018
  2. Junio C HamanoFeb 14, 2018

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.