git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* "git add" with several pathspecS and one doesn't match
@ 2018-02-14 18:31 Goffredo Baroncelli
  2018-02-14 19:29 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Goffredo Baroncelli @ 2018-02-14 18:31 UTC (permalink / raw)
  To: git, Goffredo Baroncelli

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: "git add" with several pathspecS and one doesn't match
  2018-02-14 18:31 "git add" with several pathspecS and one doesn't match Goffredo Baroncelli
@ 2018-02-14 19:29 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2018-02-14 19:29 UTC (permalink / raw)
  To: Goffredo Baroncelli; +Cc: git

Goffredo Baroncelli <kreijack@gmail.com> writes:

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

This is a good example of a pretty conscious design decision to keep
operations atomic/a-o-n when appropriate.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-14 19:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-14 18:31 "git add" with several pathspecS and one doesn't match Goffredo Baroncelli
2018-02-14 19:29 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).