Skip to content

Commit 4eb39e9

Browse files
committed
Merge branch 'jc/spht'
* jc/spht: Use gitattributes to define per-path whitespace rule core.whitespace: documentation updates. builtin-apply: teach whitespace_rules builtin-apply: rename "whitespace" variables and fix styles core.whitespace: add test for diff whitespace error highlighting git-diff: complain about >=8 consecutive spaces in initial indent War on whitespace: first, a bit of retreat. Conflicts: cache.h config.c diff.c
2 parents 05e74f4 + cf1b786 commit 4eb39e9

File tree

12 files changed

+641
-111
lines changed

12 files changed

+641
-111
lines changed

Documentation/config.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@ core.pager::
295295
The command that git will use to paginate output. Can be overridden
296296
with the `GIT_PAGER` environment variable.
297297

298+
core.whitespace::
299+
A comma separated list of common whitespace problems to
300+
notice. `git diff` will use `color.diff.whitespace` to
301+
highlight them, and `git apply --whitespace=error` will
302+
consider them as errors:
303+
+
304+
* `trailing-space` treats trailing whitespaces at the end of the line
305+
as an error (enabled by default).
306+
* `space-before-tab` treats a space character that appears immediately
307+
before a tab character in the initial indent part of the line as an
308+
error (enabled by default).
309+
* `indent-with-non-tab` treats a line that is indented with 8 or more
310+
space characters that can be replaced with tab characters.
311+
298312
alias.*::
299313
Command aliases for the gitlink:git[1] command wrapper - e.g.
300314
after defining "alias.last = cat-file commit HEAD", the invocation
@@ -387,8 +401,8 @@ color.diff.<slot>::
387401
which part of the patch to use the specified color, and is one
388402
of `plain` (context text), `meta` (metainformation), `frag`
389403
(hunk header), `old` (removed lines), `new` (added lines),
390-
`commit` (commit headers), or `whitespace` (highlighting dubious
391-
whitespace). The values of these variables may be specified as
404+
`commit` (commit headers), or `whitespace` (highlighting
405+
whitespace errors). The values of these variables may be specified as
392406
in color.branch.<slot>.
393407

394408
color.interactive::

Documentation/git-apply.txt

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313
[--apply] [--no-add] [--build-fake-ancestor <file>] [-R | --reverse]
1414
[--allow-binary-replacement | --binary] [--reject] [-z]
1515
[-pNUM] [-CNUM] [--inaccurate-eof] [--cached]
16-
[--whitespace=<nowarn|warn|error|error-all|strip>]
16+
[--whitespace=<nowarn|warn|fix|error|error-all>]
1717
[--exclude=PATH] [--verbose] [<patch>...]
1818

1919
DESCRIPTION
@@ -135,25 +135,32 @@ discouraged.
135135
be useful when importing patchsets, where you want to exclude certain
136136
files or directories.
137137

138-
--whitespace=<option>::
139-
When applying a patch, detect a new or modified line
140-
that ends with trailing whitespaces (this includes a
141-
line that solely consists of whitespaces). By default,
142-
the command outputs warning messages and applies the
143-
patch.
144-
When gitlink:git-apply[1] is used for statistics and not applying a
145-
patch, it defaults to `nowarn`.
146-
You can use different `<option>` to control this
147-
behavior:
138+
--whitespace=<action>::
139+
When applying a patch, detect a new or modified line that has
140+
whitespace errors. What are considered whitespace errors is
141+
controlled by `core.whitespace` configuration. By default,
142+
trailing whitespaces (including lines that solely consist of
143+
whitespaces) and a space character that is immediately followed
144+
by a tab character inside the initial indent of the line are
145+
considered whitespace errors.
146+
+
147+
By default, the command outputs warning messages but applies the patch.
148+
When gitlink:git-apply[1] is used for statistics and not applying a
149+
patch, it defaults to `nowarn`.
150+
+
151+
You can use different `<action>` to control this
152+
behavior:
148153
+
149154
* `nowarn` turns off the trailing whitespace warning.
150155
* `warn` outputs warnings for a few such errors, but applies the
151-
patch (default).
156+
patch as-is (default).
157+
* `fix` outputs warnings for a few such errors, and applies the
158+
patch after fixing them (`strip` is a synonym --- the tool
159+
used to consider only trailing whitespaces as errors, and the
160+
fix involved 'stripping' them, but modern gits do more).
152161
* `error` outputs warnings for a few such errors, and refuses
153162
to apply the patch.
154163
* `error-all` is similar to `error` but shows all errors.
155-
* `strip` outputs warnings for a few such errors, strips out the
156-
trailing whitespaces and applies the patch.
157164

158165
--inaccurate-eof::
159166
Under certain circumstances, some versions of diff do not correctly

Documentation/gitattributes.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,37 @@ When left unspecified, the driver itself is used for both
361361
internal merge and the final merge.
362362

363363

364+
Checking whitespace errors
365+
~~~~~~~~~~~~~~~~~~~~~~~~~~
366+
367+
`whitespace`
368+
^^^^^^^^^^^^
369+
370+
The `core.whitespace` configuration variable allows you to define what
371+
`diff` and `apply` should consider whitespace errors for all paths in
372+
the project (See gitlink:git-config[1]). This attribute gives you finer
373+
control per path.
374+
375+
Set::
376+
377+
Notice all types of potential whitespace errors known to git.
378+
379+
Unset::
380+
381+
Do not notice anything as error.
382+
383+
Unspecified::
384+
385+
Use the value of `core.whitespace` configuration variable to
386+
decide what to notice as error.
387+
388+
String::
389+
390+
Specify a comma separate list of common whitespace problems to
391+
notice in the same format as `core.whitespace` configuration
392+
variable.
393+
394+
364395
EXAMPLE
365396
-------
366397

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ LIB_OBJS = \
313313
alloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS) \
314314
color.o wt-status.o archive-zip.o archive-tar.o shallow.o utf8.o \
315315
convert.o attr.o decorate.o progress.o mailmap.o symlinks.o remote.o \
316-
transport.o bundle.o walker.o parse-options.o
316+
transport.o bundle.o walker.o parse-options.o ws.o
317317

318318
BUILTIN_OBJS = \
319319
builtin-add.o \

0 commit comments

Comments
 (0)