Skip to content

Commit

Permalink
Enable _ka-commit-lint option from bin
Browse files Browse the repository at this point in the history
Summary:
To enable calling ka-lint from commit-msg githook, instead of directly
linking to the githook.py entry point.

For an example of how I'm thinking of using this, see the sample
commit-msg hook from the WIP ka-clone project:
https://github.com/Khan/ka-clone/blob/wip/templates/commit-lint

Test Plan:
- manually pass sample commit msg files to bin/_ka-commit-lint
- manually pass sample commit msg files to githook.py

Reviewers: marcos, alpert, csilvers

Reviewed By: csilvers

Subscribers: ethan, benkomalo

Differential Revision: https://phabricator.khanacademy.org/D18179
  • Loading branch information
Matthew Rothenberg committed May 22, 2015
1 parent f1b4aff commit 17bfb1f
Show file tree
Hide file tree
Showing 8 changed files with 643 additions and 784 deletions.
13 changes: 2 additions & 11 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ It uses existing linting tools (pep8, pyflakes, jshint, etc), but has been
modified to suit Khan Academy's slightly different style guides.

This repository also contains a wrapper scripts that can be used as a
pre-commit hook for Git or Mercurial.
pre-commit hook for Git.

Installation
============
Expand All @@ -31,20 +31,11 @@ for more options.

Automatic
---------
You can automatically invoke lints on modified or added files in
Mercurial. Add to .hgrc to use:

[hooks]
pretxncommit.lint = /path/to/khan-linter/hghook.py

For git hooks, dotfiles probably already took care of it for you.

You can update the blacklist file in this repository to control what
files should not be linted at all. Alternately, you can create a
blacklist of your own, and use the --blacklist_file flag to runlint.py
(you'll have to modify hghook.py or githook.py to pass in the name of the
blacklist file as well).

To suppress the lint check, set the environment variable FORCE_COMMIT
to 1 prior to calling `hg commit` (there doesn't seem to be a way to
pass args to a pretxncommit script otherwise).
to 1 prior to calling `git commit`.
1 change: 1 addition & 0 deletions bin/_ka-commit-lint
8 changes: 4 additions & 4 deletions githook.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def _normalized_commit_message(text):
return ''.join(lines).strip()


def main():
def main(commit_message_file):
"""Run a git pre-commit lint-check."""
# If we're a merge, don't try to do a lint-check.
git_root = subprocess.check_output(['git', 'rev-parse', '--git-dir'])

commit_message = open(sys.argv[1]).read()
# read the commit message contents from the file specified
commit_message = open(commit_message_file).read()
# Get rid of the comment lines, and leading and trailing whitespace.
commit_message = _normalized_commit_message(commit_message)

Expand Down Expand Up @@ -112,4 +112,4 @@ def main():
if __name__ == '__main__':
suppress_lint = os.getenv('FORCE_COMMIT', '')
if suppress_lint.lower() not in ('1', 'true'):
sys.exit(main())
sys.exit(main(sys.argv[1]))
73 changes: 0 additions & 73 deletions hgeditor.sh

This file was deleted.

68 changes: 0 additions & 68 deletions hghook.py

This file was deleted.

Loading

0 comments on commit 17bfb1f

Please sign in to comment.