threads / discuss / 41851

Warning about conflict markers - undocumented 'diff --check' feature & suggestion

Subject: Warning about conflict markers - undocumented 'diff --check' feature & suggestion

## tl;dr

6 messages between Mar 28, 2016 and Mar 29, 2016.

replies: 5people: 2as markdown or json

Ori Avtalion· Mar 28, 2016, 22:44 UTC · lore
A bug report and a suggestion:

`git diff --check` has been warning about conflict markers since 2008: https://marc.info/?l=git&m=122398500726634&w=2

This is an undocumented feature. The current documentation for the flag only mentions "whitespace errors".

This check will also be useful in `git add`, to prevent accidental staging of conflict markers. Perhaps it could be included, if not by default, then at least with a configuration setting.

Thoughts? Is this perhaps an existing feature that I'm missing? :)
-Ori
Junio C Hamano· Mar 28, 2016, 23:01 UTC · re: Ori Avtalion · lore

Re: Warning about conflict markers - undocumented 'diff --check' feature & suggestion

Ori Avtalion <ori@avtalion.name> writes:
Show 7 quoted lines
> A bug report and a suggestion:
>
> `git diff --check` has been warning about conflict markers since 2008:
> https://marc.info/?l=git&m=122398500726634&w=2
>
> This is an undocumented feature. The current documentation for the
> flag only mentions "whitespace errors".

Thanks for digging (even though I do not think the message you quoted has much to do with this).

04954043 (diff --check: detect leftover conflict markers, 2008-06-26) was the change that added this check to the "check whitespace breakage" codepath, which forgot to update the documentation.

And when 4f830390 (Documentation: git diff --check respects core.whitespace, 2011-06-22) rewrote the paragraph, it again didn't remember to update it to match the reality.

Care to try a patch?
Ori Avtalion· Mar 29, 2016, 11:19 UTC · re: Junio C Hamano · lore

Re: Warning about conflict markers - undocumented 'diff --check' feature & suggestion

On Tue, Mar 29, 2016 at 2:01 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Ori Avtalion <ori@avtalion.name> writes:
>
> Thanks for digging (even though I do not think the message you
> quoted has much to do with this).

Oops, you are correct! I had several tabs open digging through the archives and picked the wrong one :)

> Care to try a patch?

Yes. Will submit one soon. If my change introduces a few words that exceed asciidoc's ~72-char line width, should I reformat the entire paragraph? (thus making it had to identify what changed exactly)

Any thoughts on adding similar functionality to "git add"?
Junio C Hamano· Mar 29, 2016, 18:23 UTC · re: Ori Avtalion · lore

Re: Warning about conflict markers - undocumented 'diff --check' feature & suggestion

Ori Avtalion <ori@avtalion.name> writes:
> If my change introduces a few words that exceed asciidoc's ~72-char line width,
> should I reformat the entire paragraph? (thus making it had to identify what
> changed exactly)
You should try to minimize the damage, but shouldn't go overboard ;-)
> Any thoughts on adding similar functionality to "git add"?
I am not sure what "similar functionality" you are imagining.

"git add" does not show any changes, it just does what it was told to do. If the user is unsure, s/he should make it the habit to check what s/he is doing with "git diff".

Ori Avtalion· Mar 29, 2016, 18:27 UTC · re: Junio C Hamano · lore

Re: Warning about conflict markers - undocumented 'diff --check' feature & suggestion

On Tue, Mar 29, 2016 at 9:23 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
> Ori Avtalion <ori@avtalion.name> writes:
> I am not sure what "similar functionality" you are imagining.
>
> "git add" does not show any changes, it just does what it was told
> to do.  If the user is unsure, s/he should make it the habit to
> check what s/he is doing with "git diff".

I was thinking of an off-by-default setting where git-add outright refuses to stage changes that do not pass "diff --check". I understand if that's a big deviation from the spirit of the tool, and perhaps not a good idea.

Ori Avtalion· Mar 29, 2016, 18:59 UTC · re: Junio C Hamano · lore

[PATCH] Documentation: git diff --check detects conflict markers

Signed-off-by: Ori Avtalion <ori@avtalion.name>
---
 Documentation/diff-options.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 306b7e3..32f48ed 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -286,8 +286,8 @@ endif::git-format-patch[]
 
 ifndef::git-format-patch[]
 --check::
-	Warn if changes introduce whitespace errors.  What are
-	considered whitespace errors is controlled by `core.whitespace`
+	Warn if changes introduce conflict markers or whitespace errors.
+	What are considered whitespace errors is controlled by `core.whitespace`
 	configuration.  By default, trailing whitespaces (including
 	lines that solely consist of whitespaces) and a space character
 	that is immediately followed by a tab character inside the
-- 
2.5.0

← back to recent threads