git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Shouldn't git be able to apply diffs that it created with --ignore-whitespace?
@ 2018-10-18 20:12 Mahmoud Al-Qudsi
  2018-10-20  2:36 ` brian m. carlson
  0 siblings, 1 reply; 2+ messages in thread
From: Mahmoud Al-Qudsi @ 2018-10-18 20:12 UTC (permalink / raw)
  To: git

Hello again all,

I think I've previously broached this subject before, but I think I perhaps
wasn't clear enough about what I was trying to do or why I feel that git is at
fault here.

(I'm running git 2.19.1)

Starting with a fully-committed, not-dirty codebase, I open(ed) a poorly
formatted, mixed-whitespace file (that I absolutely did not author!) under
version control and make some very localized changes. My editor, being very
smart and helpful, fixes up the line ending on save, and I exit.

At this point, my source file contains a) deliberate changes I want, and b)
whitespace changes I wish I could commit but that should not be a part of my
patch.

Shouldn't the following workflow be supported:

~> git diff -w > foo.diff
~> git reset --hard
~> git apply [--ignore-whitespace] < foo.diff

Because that throws an error in this case:

> error: patch failed: includes/helpers/class.phpmailer.php:1182
> error: includes/helpers/class.phpmailer.php: patch does not apply

I feel like this did work, once upon a time. Perhaps prior to the same that
broke `git add -p` when whitespace was mangled on editor exit/save (2b8ea7f3c7)?

To help debug this, I'm attaching the output of the following taken after I've
made my changes to the file and wish to generate a clean diff, the former of
which applies just fine after `git reset --hard`, while the latter does not:

~> git diff > with_whitespace.diff
~> git diff -w > without_whitespace.diff

(I can also privately share the original file off-list if needed.)

I don't believe the list allows binary attachments and because we're dealing
with line-ending mangling I definitely do not want to include them inline, so
I've uploaded them here:

* http://share.neosmart.net/View/Index/nGujqm.diff
* http://share.neosmart.net/View/Index/f4dkVF.diff

(You can download them as-is by clicking the floppy icon in the top-right)

With thanks,

Mahmoud Al-Qudsi
NeoSmart Technologies

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

* Re: Shouldn't git be able to apply diffs that it created with --ignore-whitespace?
  2018-10-18 20:12 Shouldn't git be able to apply diffs that it created with --ignore-whitespace? Mahmoud Al-Qudsi
@ 2018-10-20  2:36 ` brian m. carlson
  0 siblings, 0 replies; 2+ messages in thread
From: brian m. carlson @ 2018-10-20  2:36 UTC (permalink / raw)
  To: Mahmoud Al-Qudsi; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1986 bytes --]

On Thu, Oct 18, 2018 at 03:12:09PM -0500, Mahmoud Al-Qudsi wrote:
> Hello again all,
> 
> I think I've previously broached this subject before, but I think I perhaps
> wasn't clear enough about what I was trying to do or why I feel that git is at
> fault here.
> 
> (I'm running git 2.19.1)
> 
> Starting with a fully-committed, not-dirty codebase, I open(ed) a poorly
> formatted, mixed-whitespace file (that I absolutely did not author!) under
> version control and make some very localized changes. My editor, being very
> smart and helpful, fixes up the line ending on save, and I exit.
> 
> At this point, my source file contains a) deliberate changes I want, and b)
> whitespace changes I wish I could commit but that should not be a part of my
> patch.
> 
> Shouldn't the following workflow be supported:
> 
> ~> git diff -w > foo.diff
> ~> git reset --hard
> ~> git apply [--ignore-whitespace] < foo.diff

In general, git diff -w doesn't produce a patch that can be applied.
That's because it ignores all whitespace changes in a particular way.
The diff output is rendered as if the whitespace in the lines were
written as it is in the postimage (the changed file), not the preimage
(the original file).

This is useful because usually if you're, say, indenting a block of
code, you want to see the output properly indented with the new lines of
code (say, the loop or conditional) you wrote around it.  And since this
feature is designed for visual inspection, it makes sense to do it this
way.  However, it essentially means that your changes can't, in general,
be applied.

There are, of course, situations in which this might have worked in the
past, and it may indeed work for some situations still, but it won't in
the general case.  git apply --ignore-whitespace only modifies context
lines, so it doesn't affect the actual content lines in the diff.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

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

end of thread, other threads:[~2018-10-20  2:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-18 20:12 Shouldn't git be able to apply diffs that it created with --ignore-whitespace? Mahmoud Al-Qudsi
2018-10-20  2:36 ` brian m. carlson

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