robmadole / jig-plugins

A bundle of common Jig plugins
BSD 2-Clause "Simplified" License
9 stars 4 forks source link

jig-plugins validate files on disk, not staged changes #3

Open amorriso opened 11 years ago

amorriso commented 11 years ago

Hey Rob

FYI, all the pre-commit scripts only verify files on disk. These should be changed to verify files that are actually staged.

I forked your repo and made the necessary changes to all the Python pre-commits. I did this in is a very crude way (in that i had to add code to each pre-commit):

import subprocess

Stash any changes to the working tree that are not going to be committed subprocess.call(['git', 'stash', 'save', '--keep-index', '-q'], stdout=subprocess.PIPE)

... execute pre-commit stuff

Unstash changes to the working tree that we had stashed subprocess.call(['git', 'reset', '--hard'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) subprocess.call(['git', 'stash', 'pop', '--quiet', '--index'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

robmadole commented 11 years ago

Oh very interesting! I think this should be part of Jig and the plugins themselves should be able to benefit from it so it's not necessary to repeat this work in each one.

I'm thinking that it would be useful to even warn the user that they have unstaged changes. I find myself even exploiting this oddity that you fixed while I work on PEP8 errors for example. The distinction needs to be explicit and the plugins need to check the code that is actually staged.

This is a great idea. Thanks for bringing it up and I'll make a ticket in Jig to get this fixed up in the main tool.

robmadole commented 11 years ago

Work will take place in https://github.com/robmadole/jig/issues/3

amorriso commented 11 years ago

Excellent. Jig's a pretty handy tool by the way, good work.