Skip to content

Commit

Permalink
Merge branch 'jc/spht'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed Dec 9, 2007
2 parents 05e74f4 + cf1b786 commit 4eb39e9
Show file tree
Hide file tree
Showing 12 changed files with 641 additions and 111 deletions.
18 changes: 16 additions & 2 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,20 @@ core.pager::
The command that git will use to paginate output. Can be overridden
with the `GIT_PAGER` environment variable.

core.whitespace::
A comma separated list of common whitespace problems to
notice. `git diff` will use `color.diff.whitespace` to
highlight them, and `git apply --whitespace=error` will
consider them as errors:
+
* `trailing-space` treats trailing whitespaces at the end of the line
as an error (enabled by default).
* `space-before-tab` treats a space character that appears immediately
before a tab character in the initial indent part of the line as an
error (enabled by default).
* `indent-with-non-tab` treats a line that is indented with 8 or more
space characters that can be replaced with tab characters.

alias.*::
Command aliases for the gitlink:git[1] command wrapper - e.g.
after defining "alias.last = cat-file commit HEAD", the invocation
Expand Down Expand Up @@ -387,8 +401,8 @@ color.diff.<slot>::
which part of the patch to use the specified color, and is one
of `plain` (context text), `meta` (metainformation), `frag`
(hunk header), `old` (removed lines), `new` (added lines),
`commit` (commit headers), or `whitespace` (highlighting dubious
whitespace). The values of these variables may be specified as
`commit` (commit headers), or `whitespace` (highlighting
whitespace errors). The values of these variables may be specified as
in color.branch.<slot>.

color.interactive::
Expand Down
35 changes: 21 additions & 14 deletions Documentation/git-apply.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SYNOPSIS
[--apply] [--no-add] [--build-fake-ancestor <file>] [-R | --reverse]
[--allow-binary-replacement | --binary] [--reject] [-z]
[-pNUM] [-CNUM] [--inaccurate-eof] [--cached]
[--whitespace=<nowarn|warn|error|error-all|strip>]
[--whitespace=<nowarn|warn|fix|error|error-all>]
[--exclude=PATH] [--verbose] [<patch>...]

DESCRIPTION
Expand Down Expand Up @@ -135,25 +135,32 @@ discouraged.
be useful when importing patchsets, where you want to exclude certain
files or directories.

--whitespace=<option>::
When applying a patch, detect a new or modified line
that ends with trailing whitespaces (this includes a
line that solely consists of whitespaces). By default,
the command outputs warning messages and applies the
patch.
When gitlink:git-apply[1] is used for statistics and not applying a
patch, it defaults to `nowarn`.
You can use different `<option>` to control this
behavior:
--whitespace=<action>::
When applying a patch, detect a new or modified line that has
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 initial indent of the line are
considered whitespace errors.
+
By default, the command outputs warning messages but applies the patch.
When gitlink:git-apply[1] is used for statistics and not applying a
patch, it defaults to `nowarn`.
+
You can use different `<action>` to control this
behavior:
+
* `nowarn` turns off the trailing whitespace warning.
* `warn` outputs warnings for a few such errors, but applies the
patch (default).
patch as-is (default).
* `fix` outputs warnings for a few such errors, and applies the
patch after fixing them (`strip` is a synonym --- the tool
used to consider only trailing whitespaces as errors, and the
fix involved 'stripping' them, but modern gits do more).
* `error` outputs warnings for a few such errors, and refuses
to apply the patch.
* `error-all` is similar to `error` but shows all errors.
* `strip` outputs warnings for a few such errors, strips out the
trailing whitespaces and applies the patch.

--inaccurate-eof::
Under certain circumstances, some versions of diff do not correctly
Expand Down
31 changes: 31 additions & 0 deletions Documentation/gitattributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,37 @@ When left unspecified, the driver itself is used for both
internal merge and the final merge.


Checking whitespace errors
~~~~~~~~~~~~~~~~~~~~~~~~~~

`whitespace`
^^^^^^^^^^^^

The `core.whitespace` configuration variable allows you to define what
`diff` and `apply` should consider whitespace errors for all paths in
the project (See gitlink:git-config[1]). This attribute gives you finer
control per path.

Set::

Notice all types of potential whitespace errors known to git.

Unset::

Do not notice anything as error.

Unspecified::

Use the value of `core.whitespace` configuration variable to
decide what to notice as error.

String::

Specify a comma separate list of common whitespace problems to
notice in the same format as `core.whitespace` configuration
variable.


EXAMPLE
-------

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ LIB_OBJS = \
alloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS) \
color.o wt-status.o archive-zip.o archive-tar.o shallow.o utf8.o \
convert.o attr.o decorate.o progress.o mailmap.o symlinks.o remote.o \
transport.o bundle.o walker.o parse-options.o
transport.o bundle.o walker.o parse-options.o ws.o

BUILTIN_OBJS = \
builtin-add.o \
Expand Down
Loading

0 comments on commit 4eb39e9

Please sign in to comment.