git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* suppress fatal pathspec errors from "git add"?
@ 2009-12-31 21:24 aaron smith
  2010-01-03  7:40 ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: aaron smith @ 2009-12-31 21:24 UTC (permalink / raw)
  To: git

I'm looking through the add documentation, I don't see a way to
suppress fatal pathspec errors? For example, if I'm adding 5 files,
but one of them is mis-spelled, can I have git just supress the errors
and add the other four?
thanks much!

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

* Re: suppress fatal pathspec errors from "git add"?
  2009-12-31 21:24 suppress fatal pathspec errors from "git add"? aaron smith
@ 2010-01-03  7:40 ` Jeff King
  2010-01-03  8:00   ` aaron smith
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jeff King @ 2010-01-03  7:40 UTC (permalink / raw)
  To: aaron smith; +Cc: git

On Thu, Dec 31, 2009 at 01:24:59PM -0800, aaron smith wrote:

> I'm looking through the add documentation, I don't see a way to
> suppress fatal pathspec errors? For example, if I'm adding 5 files,
> but one of them is mis-spelled, can I have git just supress the errors
> and add the other four?

Hmm. I would have thought "git add --ignore-errors" would do what you
want, but it only ignores errors in reading the file. If we can't stat
it, we will always die. IMHO that is an oversight in how
"--ignore-errors" works (why should this one particular error be treated
as fatal, when others are not?).

However, I have to wonder what your workflow is to really want this. If
you do:

  $ ls
  foo bar baz
  $ git add foo bar bz
  fatal: pathspec 'bz' did not match any files

Then presumably your next command would be:

  $ git add foo bar baz

Using ignore-errors (if it worked), you would probably do:

  $ git add baz

Less typing, I suppose, but presumably you are using a shell that
lets you just go back and edit the previous command line. I could see it
if your workflow were something like "in a script, add these N files if
they exist, but it is not an error if they don't". But I still don't
think you would want to ignore all errors; you would want to do
something like:

  $ git add $(for i in foo bar baz; do test -e $i && echo $i; done)

instead. Am I missing something?

-Peff

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

* Re: suppress fatal pathspec errors from "git add"?
  2010-01-03  7:40 ` Jeff King
@ 2010-01-03  8:00   ` aaron smith
  2010-01-03  8:12   ` Junio C Hamano
  2010-01-03  9:44   ` Jakub Narebski
  2 siblings, 0 replies; 6+ messages in thread
From: aaron smith @ 2010-01-03  8:00 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Hey Jeff, thanks for the reply.

Yeah you hit it right on the head, it would be useful to suppress the
errors if you're running a script to add the files. I can certainly
use that snippet u provided - thanks. It would even be useful in git
if you could suppress the errors, or maybe have a switch to list out
the files that failed, but add the ones that pass.. like "git add
--ignore-errors --list-failures" something like that. Anyway, thanks
for the input.



On Sat, Jan 2, 2010 at 11:40 PM, Jeff King <peff@peff.net> wrote:
> On Thu, Dec 31, 2009 at 01:24:59PM -0800, aaron smith wrote:
>
>> I'm looking through the add documentation, I don't see a way to
>> suppress fatal pathspec errors? For example, if I'm adding 5 files,
>> but one of them is mis-spelled, can I have git just supress the errors
>> and add the other four?
>
> Hmm. I would have thought "git add --ignore-errors" would do what you
> want, but it only ignores errors in reading the file. If we can't stat
> it, we will always die. IMHO that is an oversight in how
> "--ignore-errors" works (why should this one particular error be treated
> as fatal, when others are not?).
>
> However, I have to wonder what your workflow is to really want this. If
> you do:
>
>  $ ls
>  foo bar baz
>  $ git add foo bar bz
>  fatal: pathspec 'bz' did not match any files
>
> Then presumably your next command would be:
>
>  $ git add foo bar baz
>
> Using ignore-errors (if it worked), you would probably do:
>
>  $ git add baz
>
> Less typing, I suppose, but presumably you are using a shell that
> lets you just go back and edit the previous command line. I could see it
> if your workflow were something like "in a script, add these N files if
> they exist, but it is not an error if they don't". But I still don't
> think you would want to ignore all errors; you would want to do
> something like:
>
>  $ git add $(for i in foo bar baz; do test -e $i && echo $i; done)
>
> instead. Am I missing something?
>
> -Peff
>

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

* Re: suppress fatal pathspec errors from "git add"?
  2010-01-03  7:40 ` Jeff King
  2010-01-03  8:00   ` aaron smith
@ 2010-01-03  8:12   ` Junio C Hamano
  2010-01-03  8:28     ` Jeff King
  2010-01-03  9:44   ` Jakub Narebski
  2 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2010-01-03  8:12 UTC (permalink / raw)
  To: Jeff King; +Cc: aaron smith, git

Jeff King <peff@peff.net> writes:

> ... I could see it
> if your workflow were something like "in a script, add these N files if
> they exist, but it is not an error if they don't". But I still don't
> think you would want to ignore all errors; you would want to do
> something like:
>
>   $ git add $(for i in foo bar baz; do test -e $i && echo $i; done)
>
> instead. Am I missing something?

If your primary activity that happens in the work tree were:

	while :
        do
        	file=$(date +"random-%H%M%S")
                >"$file"
                rm -f "$file"
	done

and your add were done in

	while sleep 3600
        do
		git add $(for i in *; do test -e $i && echo $i; done)
                git commit -m "hourly snapshot"
	done

totally asynchronously without coordinating with what the primary activity
is doing, your "test -e && echo" can race with a concurrent "rm".

Even though I think it is an insane use pattern that we shouldn't bother
to bend too much backwards to support it, --ignore-errors were added
primarily for a similar use case (i.e. by the time we try to read it, it
is either gone or it cannot be read by the user who runs "git add"), so in
that sense it _might_ make sense to ignore all errors with the option.  If
we choose to go in that direction, it would also make tons of sense to
update the documentation of the option to caution more strongly that its
use is a sign of insanity and is discouraged at the same time.

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

* Re: suppress fatal pathspec errors from "git add"?
  2010-01-03  8:12   ` Junio C Hamano
@ 2010-01-03  8:28     ` Jeff King
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2010-01-03  8:28 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: aaron smith, git

On Sun, Jan 03, 2010 at 12:12:19AM -0800, Junio C Hamano wrote:

> If your primary activity that happens in the work tree were:
> 
> 	while :
>         do
>         	file=$(date +"random-%H%M%S")
>                 >"$file"
>                 rm -f "$file"
> 	done
> 
> and your add were done in
> 
> 	while sleep 3600
>         do
> 		git add $(for i in *; do test -e $i && echo $i; done)
>                 git commit -m "hourly snapshot"
> 	done
> 
> totally asynchronously without coordinating with what the primary activity
> is doing, your "test -e && echo" can race with a concurrent "rm".

Of course. But in such a situation, you are almost certainly better off
doing "git add -A". The external loop is really only useful if you want
to add a subset of the files that may or may not exist for some reason.
Which is getting pretty specific and crazy.

I haven't checked to see whether "add -A" has a race in discovering
files versus actually adding them (I suppose there has to be one...even
if we open() immediately and use fstat() and friends for everything
else, there still must be a race between getting the name from readdir()
and calling open()).

And I can see that as a potentially useful workflow: you are doing
regular snapshots of a set of files which are being changed by an
outside force. You care about errors, but not files disappearing between
readdir() and stat(). The "find" command has an "--ignore-readdir-race"
option, which is what you would want.

But that is not "--ignore-errors should also ignore missing files". It
is "I want to ignore missing files but not other errors".

> Even though I think it is an insane use pattern that we shouldn't bother
> to bend too much backwards to support it, --ignore-errors were added
> primarily for a similar use case (i.e. by the time we try to read it, it
> is either gone or it cannot be read by the user who runs "git add"), so in
> that sense it _might_ make sense to ignore all errors with the option.  If
> we choose to go in that direction, it would also make tons of sense to
> update the documentation of the option to caution more strongly that its
> use is a sign of insanity and is discouraged at the same time.

I tracked down the original thread and it looks like the motivation was
to handle repositories with a mixed set of readable and inaccessible
(due to permissions) files:

 http://article.gmane.org/gmane.comp.version-control.git/75676

So I think it's not _totally_ insane there. You would do "git add
--ignore-errors ." instead of having to manually write the shell loop of
accessible items (though personally, I think I would just write the
shell loop in that situation).

That's just my two cents on the matter. I'm not personally planning on
writing patches for either case.

-Peff

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

* Re: suppress fatal pathspec errors from "git add"?
  2010-01-03  7:40 ` Jeff King
  2010-01-03  8:00   ` aaron smith
  2010-01-03  8:12   ` Junio C Hamano
@ 2010-01-03  9:44   ` Jakub Narebski
  2 siblings, 0 replies; 6+ messages in thread
From: Jakub Narebski @ 2010-01-03  9:44 UTC (permalink / raw)
  To: Jeff King; +Cc: aaron smith, git

Jeff King <peff@peff.net> writes:

> On Thu, Dec 31, 2009 at 01:24:59PM -0800, aaron smith wrote:
> 
> > I'm looking through the add documentation, I don't see a way to
> > suppress fatal pathspec errors? For example, if I'm adding 5 files,
> > but one of them is mis-spelled, can I have git just supress the errors
> > and add the other four?
> 
> Hmm. I would have thought "git add --ignore-errors" would do what you
> want, but it only ignores errors in reading the file. If we can't stat
> it, we will always die. IMHO that is an oversight in how
> "--ignore-errors" works (why should this one particular error be treated
> as fatal, when others are not?).

I have thought that this is task for --ignore-missing / --missing-ok
option, but this option(s) does not apply to git-add / git-rm; the former
is from git-write-index, the latter form from git-write-tree.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

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

end of thread, other threads:[~2010-01-03  9:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-31 21:24 suppress fatal pathspec errors from "git add"? aaron smith
2010-01-03  7:40 ` Jeff King
2010-01-03  8:00   ` aaron smith
2010-01-03  8:12   ` Junio C Hamano
2010-01-03  8:28     ` Jeff King
2010-01-03  9:44   ` Jakub Narebski

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 NNTP newsgroup(s).