[PATCH 02/10] Run the pre-commit hook on content staged for commit
David Shea
dshea at redhat.com
Thu Sep 26 13:03:35 UTC 2013
On 09/25/2013 05:50 PM, Brian C. Lane wrote:
> On Wed, Sep 25, 2013 at 02:21:46PM -0400, David Shea wrote:
>> Changed the pylint Module output so that it's more clear what file is
>> being checked. Added an option to runpylint.sh to manually set the
>> filename to display.
>> ---
>> scripts/githooks/pre-commit | 47 ++++++++++++++++++++++++++++++++-------------
>> tests/pylint/runpylint.sh | 16 ++++++++++++++-
>> 2 files changed, 49 insertions(+), 14 deletions(-)
>>
>> @@ -37,24 +38,44 @@ except CalledProcessError:
>> pylint_files = []
>> # Lines look like: :100755 100755 2cf57974e13a2aae778e28f942a4d44bf6567409 6fe1b6caf32d565b2cdb6d1aee250aaddc6d3a04 M tests/pylint/runpylint.sh
>> for gf in git_files.splitlines():
>> - path = gf.split()[-1]
>> - if is_python(path):
>> - pylint_files.append(path)
>> + fields = gf.split()
>> +
>> + # If the file is being removed, ignore it
>> + if fields[4] == 'D':
>> + continue
>> + elif is_python(fields[-1]):
>> + pylint_files.append(fields[-1])
> Good idea.
>
>> +# Make a list of tuples of (filename, tempfile) where the tempfile
>> +# contains the file as staged for commit.
>> +pylint_commits = []
>> +for pylint_file in pylint_files:
>> + commit = tempfile.NamedTemporaryFile()
>> + try:
>> + commit.write(check_output(["git", "show", (":%s" % pylint_file)]))
>> + except CalledProcessError:
>> + sys.exit(1)
>> + commit.flush()
>> + pylint_commits.append((pylint_file, commit))
> I'm not sure I like this. Seems like overkill, and it's going to slow
> the check down on larger commits.
Is there at least a cheap way to check if the staged data doesn't match
the filesystem data so we can warn about that?
More information about the anaconda-patches
mailing list