-
Notifications
You must be signed in to change notification settings - Fork 430
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
Only perform checks on staged hunks #123
Comments
This does not solve the problem actually, but at least code that is not yet staged would not be checked, as it is not part of the staged version of the given file. |
@Miljar |
I have updated to v0.8.0 but I receive errors when I try to test this: Reapplying unstaged changes from stash.
The stashed changes could not be applied. Please run `git stash pop` manually!More info: exception 'Gitonomy\Git\Exception\ProcessException' with message 'Error while running git command:
'git' '--git-dir' '/path/to/my/project/.git' '--work-tree' '/path/to/my/project' 'stash' 'pop' '--quiet' In my source code, I then get git markers for merge conflicts: <<<<<<< Updated upstream
=======
}
public function tralala()
{
>>>>>>> Stashed changes This is how I tested:
|
We didn't really test For example: # create the file:
echo "<?php" > test.php
git add test.php
echo 'echo "stage me";' >> test.php
echo 'echo "unstage me";' >> test.php
# Run patch add:
git add -p test.php
# edit the hunk and delete the unstage me line
# You can check what is staged and what is not:
git status
git diff --cached
git diff
# Create stash:
git stash save --keep-index
git diff --cached
git stash pop Result:
As you can see, this will always result in an error in GIT. |
Why mess with my workspace? When stashing, the checks will still happen on new unstaged files, since these are not stashed. # this is the magic:
# retrieve all files in staging area that are added, modified or renamed
# but no deletions etc
FILES=$(git diff-index --name-only --cached --diff-filter=ACMR $against -- ) Then loop over those files and check those files against the checkers. |
No, only the staged files are being validated. This could also be fixed with the stash --all flag, but isn't necesarry at the moment. A copy is another option, but there is much more that can go wrong inside of GrumPHP. |
Did some additional research last night and found the following discussion: So basically the patched stash can only be applied again when the staged changes are committed. |
@veewee I have thought about it, and I don't think that the current solution is good enough. At the very least, there should be an option to turn it off, because I don't like it when tools mess with my workspace by stash popping & pushing. If something goes wrong, who knows what I have to do to restore the situation. You worry that in big projects the copying of the files will be slow. I can only see that as a problem when you try to commit a lot of big blobs. Like a folder with a database dump or a folder with images. I have not really tested this situation so I cannot confirm nor deny this. However, you could make this smart by allowing to add a global ignore pattern for GrumPHP where you could add |
@Miljar About the copy: we will certainly have to look into that one. My biggest concern is how GrumPHP will handle these files / tasks when they run in a separate folder. So mostly about: autoloading, relative paths, location of the tools, location of the vendor libraries, .... But then again: this needs to be investigated first. |
It's a tough one :) |
We changed the default value of |
I have been using GrumPHP for a while now, and one of the things that bothers me is that checks are performed on the entire file that is staged, rather than on the changes in that file.
Practical example: PHPCS reporting errors in parts of the code which are not touched in that commit.
An improvement would be to do the checks on the staged version of a file, and not on the working directory version. I have an example PHPCS pre-commit hook below, where this magic is demonstrated. Could this be incorporated in GrumPHP?
The text was updated successfully, but these errors were encountered: