Skip to content

Make hook work properly on initial commit #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion git_pylint_commit_hook/commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,42 @@
import re
import sys
import subprocess
import collections
import ConfigParser


ExecutionResult = collections.namedtuple(
'ExecutionResult',
'status, stdout, stderr'
)


def _execute(cmd):
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = process.communicate()
status = process.poll()
return ExecutionResult(status, stdout, stderr)


def _current_commit():
if _execute('git rev-parse --verify HEAD'.split()).status:
return '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
else:
return 'HEAD'


def _get_list_of_committed_files():
""" Returns a list of files about to be commited. """
files = []
# pylint: disable=E1103
diff_index_cmd = 'git diff-index --cached %s' % _current_commit()
output = subprocess.check_output(
'git diff-index --cached HEAD'.split())
diff_index_cmd.split()
)
for result in output.split('\n'):
if result != '':
result = result.split()
Expand Down