Differences between revisions 5 and 15 (spanning 10 versions)
Revision 5 as of 2010-11-26 23:21:54
Size: 1595
Comment: Added issue tracker link
Revision 15 as of 2010-12-06 22:09:36
Size: 2894
Comment: Give credit where credit is due :)
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
This extension installs a commit hook to prevent tabs and trailing whitespaces locally. It also provides a command to check the working directory files and optionally to fix problems found. This extension provides two hooks and a command to prevent committing tabs and trailing whitespaces.
The
hooks must be explicitly enabled in the hgrc/mercurial.ini file.
Line 10: Line 11:
'''This extension is/is not distributed with Mercurial.''' '''This extension is not distributed with Mercurial.'''
Line 12: Line 13:
''Author: MarcusLindblom '' ''Author: MarcusLindblom '' (Additional help: JesseGlick)
Line 16: Line 17:
 * If you like it, drop a note here: https://www.ohloh.net/p/ml-hgext
Line 19: Line 21:
=== Configuration === By avoiding commits with tab characters or trailing whitespace on lines, there is less noise in the diffs and the actual code changes are clearer.

The extensions adds a command {{{checkfiles}}} which reports issues in the working directory. Using --fixup will instead fix these files by replacing tabs with spaces and

There is also two hooks:
 * {{{check_hook}}} - checks and blocks commits with issues, useable in {{{pretxncommit}}} or {{{pretxnchangegroup}}}
 * {{{fixup_hook}}} - automatically fixes issues in files on commit, useable in {{{pre-commit}}}

== Configuration ==
Line 24: Line 34:
checkfiles = /path/to/checkfiles.py checkfiles = /path/to/checkfiles.py # enable command

[hooks]
pretxnchangegroup.checkfiles = python:/path/to/checkfiles.py:check_hook # enables hook to check incoming changeset
pretxncommit.checkfiles = python:/path/to/checkfiles.py:check_hook # enables hook to stop bad commits
precommit.checkfiles = python:/path/to/checkfiles.py:fixup_hook # enables hook to fix files before creating commit
Line 27: Line 42:
# default is any text file
Line 28: Line 44:
# default are these (common autogenerated files)
ignored_exts = .sln .suo .vcproj .csproj .ui
Line 30: Line 48:
# to examine only modified lines from check_hook (no effect on fixup_hook or command), use:
# check_diffs = True
Line 32: Line 52:
=== Usage === == Usage ==
Line 43: Line 63:
    If problems are found, the command returns 1, otherwise 0.     If problems are found, the command returns 1, otherwise 0.      If --fixup is given, the return value is always 0 (unless an error occurs).
Line 47: Line 68:
 -f --fixup fix files by replacing tabs and removing trailing whitespace
 -t --tabsize set the tab length (default: 8 or checkfiles.tab_size)
 -f --fixup       fix files by replacing tabs and removing trailing whitespace
 -t --tabsize VALUE set the tab length (default: 4)
Line 54: Line 75:
CategoryExtension CategoryExtensionsByOthers CategoryExtensionsByOthers

CheckFilesExtension

This extension provides two hooks and a command to prevent committing tabs and trailing whitespaces. The hooks must be explicitly enabled in the hgrc/mercurial.ini file.

1. Status

This extension is not distributed with Mercurial.

Author: MarcusLindblom (Additional help: JesseGlick)

2. Overview

By avoiding commits with tab characters or trailing whitespace on lines, there is less noise in the diffs and the actual code changes are clearer.

The extensions adds a command checkfiles which reports issues in the working directory. Using --fixup will instead fix these files by replacing tabs with spaces and

There is also two hooks:

  • check_hook - checks and blocks commits with issues, useable in pretxncommit or pretxnchangegroup

  • fixup_hook - automatically fixes issues in files on commit, useable in pre-commit

3. Configuration

Configure your .hgrc to enable the extension by adding following lines:

[extensions]
checkfiles = /path/to/checkfiles.py # enable command

[hooks]
pretxnchangegroup.checkfiles = python:/path/to/checkfiles.py:check_hook # enables hook to check incoming changeset
pretxncommit.checkfiles = python:/path/to/checkfiles.py:check_hook # enables hook to stop bad commits
precommit.checkfiles = python:/path/to/checkfiles.py:fixup_hook # enables hook to fix files before creating commit

[checkfiles]
# default is any text file
checked_exts = .c .h .cpp .xml .cs .html .js .css .txt .py .nsi .java .aspx .asp .bat .cmd .glsl
# default are these (common autogenerated files)
ignored_exts = .sln .suo .vcproj .csproj .ui
ignored_files = foo/contains_tabs.txt bar/contains_trailing_ws.txt
tab_size = 4
# to examine only modified lines from check_hook (no effect on fixup_hook or command), use:
# check_diffs = True

4. Usage

hg checkfiles [options]

checks changed files in the working directory for tabs or trailing whitespace

    - --verbose shows the location of offending characters in each line
    - --quiet hides filenames and only reports summary information
    - --debug shows settings and details about each file considered for checking

    If problems are found, the command returns 1, otherwise 0. 
    If --fixup is given, the return value is always 0 (unless an error occurs).

options:

 -f --fixup          fix files by replacing tabs and removing trailing whitespace
 -t --tabsize VALUE  set the tab length (default: 4)

use "hg -v help checkfiles" to show global options


CategoryExtensionsByOthers

CheckFilesExtension (last edited 2012-02-15 19:25:33 by ks3095497)