git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git add to ignore whitespaces, some day?
@ 2015-02-27  0:09 Marc-André Lureau
  2015-03-04 10:05 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: Marc-André Lureau @ 2015-02-27  0:09 UTC (permalink / raw)
  To: git

Hey,

It would be nice if git-add could be told to ignore whitespace
changes, wouldn't it?

According to SO, I am not the one to think so:
http://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes

A change to add--interactive would be as simple as adding the diff -b
or -w option like:
my @diff = run_cmd_pipe("git", @diff_cmd, "-w", "--", $path);

But I wonder if this should be configured in a diff.ignorews or passed
as an argument to git add. Opinions?

-- 
Marc-André Lureau

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

* Re: git add to ignore whitespaces, some day?
  2015-02-27  0:09 git add to ignore whitespaces, some day? Marc-André Lureau
@ 2015-03-04 10:05 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2015-03-04 10:05 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: git

On Fri, Feb 27, 2015 at 01:09:30AM +0100, Marc-André Lureau wrote:

> It would be nice if git-add could be told to ignore whitespace
> changes, wouldn't it?
> 
> According to SO, I am not the one to think so:
> http://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes
> 
> A change to add--interactive would be as simple as adding the diff -b
> or -w option like:
> my @diff = run_cmd_pipe("git", @diff_cmd, "-w", "--", $path);

What would it mean to stage such a hunk? For example, consider this
situation:

    git init

    echo 'foo();' >file
    git add file

    {
      echo 'if (something) {'
      echo '    foo();'
      echo '}'
    } >file

A regular diff shows:

    diff --git a/file b/file
    index a280f9a..ce0eeda 100644
    --- a/file
    +++ b/file
    @@ -1 +1,3 @@
    -foo();
    +if (something) {
    +    foo();
    +}

but "diff -w" would show:

    diff --git a/file b/file
    index a280f9a..ce0eeda 100644
    --- a/file
    +++ b/file
    @@ -1 +1,3 @@
    +if (something) {
         foo();
    +}

If we try to apply that hunk to what is in the index, it will not work.
The context line does not exist in the index file. Even if you could
convince git-apply to massage it into place, it still does not update
the whitespace in the 'foo();' line. IOW, we did not stage the full hunk
at all; running "git add -p" again would show that we still have the
whitespace change to stage.

So if you were to pursue this, it would have to have two copies of each
hunk: the one to apply, and the "display" copy that we show the user. We
do this already for colorization. However, I think we rely there on the
fact that the two versions of the diff match up, line for line. Whereas
here, you would not even necessarily have the same number of hunks
between the regular and "-b" versions.

-Peff

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

end of thread, other threads:[~2015-03-04 10:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-27  0:09 git add to ignore whitespaces, some day? Marc-André Lureau
2015-03-04 10:05 ` Jeff King

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