Differences between revisions 17 and 20 (spanning 3 versions)
Revision 17 as of 2010-12-21 00:28:28
Size: 3129
Comment:
Revision 20 as of 2012-02-15 19:25:33
Size: 3277
Editor: ks3095497
Comment: Download location is a repository.
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
This extension provides two hooks and two commands to detect, report, prevent and remove tabs and trailing whitespaces. This extension provides two hooks and two commands to detect, report and prevent trailing whitespace and/or unify usage of tabs/spaces. (Default behaviour prefers spaces.)
Line 16: Line 16:
 * Download site: https://bitbucket.org/marcusl/ml-hgext/src/tip/checkfiles.py  * Repository: https://bitbucket.org/marcusl/ml-hgext
Line 45: Line 45:
Line 49: Line 50:
Line 51: Line 53:

# to replace spaces with tabs (instead of the default: tabs -> spaces), set use_spaces = False
use_spaces = True

CheckFilesExtension

This extension provides two hooks and two commands to detect, report and prevent trailing whitespace and/or unify usage of tabs/spaces. (Default behaviour prefers spaces.)

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 & VsevolodParfenov)

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

# to replace spaces with tabs (instead of the default: tabs -> spaces), set use_spaces = False
use_spaces = 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. 

options:

 -t --tabsize VALUE  set the tab length (default: 4)
    --all            consider all tracked files, not just modified

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

hg fixwhitespace [options]

replaces tabs with spaces and removes trailing whitespace

options:

 -t --tabsize VALUE  set the tab length (default: 4)
    --all            consider all tracked files, not just modified

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


CategoryExtensionsByOthers

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