Commit Graph

19 Commits

Author SHA1 Message Date
Brad King
c3d0b77f8d pre-commit: Add whitespace check "no-lf-at-eol" 2010-12-30 09:11:38 -05:00
Brad King
f560224524 pre-commit: Generalize custom whitespace check
Lookup the whitespace attribute for each modified file and dispatch
custom checks as necessary.  Currently the only custom check is the
approximate tab-in-indent check for Git < 1.7.2.
2010-12-30 09:08:10 -05:00
Brad King
dc31be5bda Chain to script configured by "hooks.chain-<hook>"
Chain the pre-commit, commit-msg, and prepare-commit-msg hooks to
locally configured scripts.  Interpret relative paths with respect to
the working directory where the hooks run (top of work tree).  This
allows project setup scripts to add project-specific checks for each of
these hooks.
2010-11-16 17:40:16 -05:00
Matt McCormick (thewtex)
d5bb076453 pre-commit: Apply uncrustify and KWStyle check for modified files.
uncrustify (uncrustify.sourceforge.net) is applied to changed files prior to
commit.

This feature is off by default.  To enable this behavior, set

  git config hooks.uncrustify true

By default, the behavior of git-mergetool is used to review the changes
uncrustify makes before they are added to the commit.  For more information on
this behavior, see

  git help mergetool

KWStyle is run on the changed C++ files and the commit is aborted if the files
do not pass the test.  A file similar to the original is saved with a '*.kws'
extension so that line numbers referenced in the error message can be examined.

The test is off by default.  To enable this behavoir, set

  git config hooks.KWStyle true

Project specific uncrustify and KWStyle configuration files are set with 'git
config'.  For example,

  git config hooks.uncrustify.conf path/to/uncrustify.conf
  git config hooks.KWStyle.conf path/to/KWStyle.conf
  git config hooks.KWStyle.overwriteRulesConf path/to/overwrite.conf # optional

If the appropriate values have not been set, die() is called.  An
optional KWStyle overwrite rules file can also been configured.

The files on which to run the style checks must also be identified in the
repository's '.gitattributes'.  For example,

  *.h    hooks.style
  *.cpp  hooks.style

Or, to only enable a subset of style hooks,

  *.h    hooks.style=KWStyle
  *.cpp  hooks.style=KWStyle,uncrustify

Change-Id: Ia6b2d4136af3002eb0ec5d36f03c50df928917f4
2010-09-27 14:53:00 -05:00
Brad King
19f86ec15c pre-commit: Allow submodule check to be disabled
If hooks.submodule is 'false' disable all checks.  If an individual
hooks.<module>.update is 'true' then accept any update for that module.
Leave these options out of the hints printed.  Developers that know what
they are doing will be able to find them by reading the hook source.
2010-09-15 09:22:03 -04:00
Brad King
e368fa1290 pre-commit: Approximate Git 1.7.2 tab-in-indent check
Check for leading TABs in files marked with the whitespace=tab-in-indent
attribute instead of hard-coding a list of file extensions.
2010-08-30 10:02:42 -04:00
Brad King
19ee713db1 Add Apache 2.0 LICENSE and copyright NOTICE 2010-08-27 16:43:57 -04:00
Brad King
aad245bee7 Remove out-dated instructions 2010-08-27 16:41:32 -04:00
Brad King
0c6925a7fc pre-commit: Allow .gitattributes to limit file size
Check for a 'hooks.MaxObjectKiB' attribute to set the limit of specific
files or patterns.
2010-08-25 12:03:45 -04:00
Brad King
48e72dd1cd pre-commit: Check submodules staged with other changes
Since Git does not automatically update submodule checkouts when
checking out a new version in the work tree, it is common to have
locally modified submodule references.  Therefore it is easy to stage
such modifications with other changes by accident, especially with
commands like "git add -u" or "git commit -a".  The result is almost
always wrong if the submodule change is not intended.

Prevent such mistakes by requiring an extra step to commit submodule
link updates with other changes.  When this case is detected, print a
message describing the situation and provide cut-and-paste instructions
to proceed.
2010-08-10 17:30:06 -04:00
Gaëtan Lehmann
8653d28606 Reference bash explicitly in shebang lines
On Solaris, where /bin/sh is actually sh, not bash, some expressions
like $() are not supported.  Git's own scripts on this machine are
configured to use "#!/bin/bash".  Change our shebang line to

  #!/usr/bin/env bash

which should work almost everywhere.
2010-08-03 11:07:24 -04:00
Brad King
1387c7efa0 pre-commit: Check file size always
Fix logic to call check_size for all updated index entries, not just
those whose mode changed.
2010-06-07 14:07:38 -04:00
Brad King
a54ae582f7 pre-commit: Check file sizes
Check blob and tree object sizes to prevent large objects from entering
the repository.  The default limit is 1024 KiB, but it can be set with

  git config hooks.MaxObjectKiB $KiB

locally, or disabled by using 0 KiB.
2010-06-07 13:56:33 -04:00
Brad King
92c7517435 pre-commit: Rename looks_executable -> mode_looks_exe
Keep all mode-related check helpers in the "mode_" namespace.
2010-06-07 13:27:19 -04:00
Brad King
7827726e88 pre-commit: Check file modes
Check new files and files whose mode changes to verify that each file
mode matches the content of the file.  The mode of a file must be
executable if and only if the file looks executable (name ends in a
Windows executable extension or content starts with a shebang line).
2010-05-20 11:42:57 -04:00
Brad King
0df83855da pre-commit: Workaround shell syntax limitations
Commit "Reject leading TABs" added use of shell syntax of the form

  $(case "..." in
     a) ... ;;
    esac)

Some shell implementations fail to recognize that the ')' in the case
label is not the end of the '$(' expression.  Work around the problem
by moving the case block into a separate function outside the '$()'
expression.
2010-04-27 13:55:31 -04:00
Brad King
f226aad5a4 pre-commit: Reject leading TABs
Our style guidelines do not permit indentation by TABs.
2010-04-23 15:49:21 -04:00
Brad King
2b3a3cd7a6 pre-commit: Validate user.name and user.email 2010-04-20 11:28:25 -04:00
Brad King
68d1d3b4af Prototype pre-commit and commit-msg hook scripts
These hooks perform some basic commit-time checks to keep history clean.
2010-03-31 17:39:00 -04:00