checkstyle / patch-filters

Suppression Filter for Checkstyle that is based on patch file
GNU Lesser General Public License v2.1
4 stars 6 forks source link

Patch File doesn't include Unstaged Changes #363

Open rnveach opened 1 year ago

rnveach commented 1 year ago

Not an issue with patch filter itself, but we need documentation on the best way to set up this repo for our users. There is nothing in our readme for this.

Identified when testing https://github.com/checkstyle/patch-filters/issues/352 , I made changes to the repo but did not commit them. They did not appear in show.patch which wasn't expected.

I test my changes before committing them all the time to ensure I am not committing something bad and losing my original work. I think we should find some way to include unstaged changes as well with the top commit.

Repo's patch file creation: https://github.com/checkstyle/eclipse-cs/blob/master/pom.xml#L125-L131

romani commented 1 year ago

https://stackoverflow.com/questions/30023405/how-to-compare-the-working-copy-staging-copy-and-committed-copy-of-a-file-using/30023448#30023448

git diff HEAD~1

Please recheck that it works, if so, let's update our configs

romani commented 1 year ago

Approach above does not work.

Explanation on why it is not working: https://www.reddit.com/r/git/comments/a8oju0/basic_question_does_git_diff_only_show_the/ https://stackoverflow.com/a/857696

Workaround is to use git add --intent-to-add . so in this case git diff HEAD~0 show new file. But it is sligh effect to user activity, there might be some files user did not plan to add to git at all. Good is that such adding to staging is not full staging, so 'git commit' will not take it.

We suggest to use it and user can decide to use it or not.

romani commented 1 year ago

@rdiachenko , do you know any git commands trick to have new files patch files?

rdiachenko commented 1 year ago

@rdiachenko , do you know any git commands trick to have new files patch files?

No such a trick. Another option would be to append show.patch with new unstaged files as an additional step before filter execution: git ls-files -o --exclude-standard -x show.patch | xargs -I {} git diff /dev/null {} >> show.patch

It is equivalent to git add . ; git diff --cached --diff-filter=A >> show.patch ; git restore --staged .

romani commented 1 year ago

is there way to put this bash magic to pom.xml and use it ? in real project (eclipse-cs)

rnveach commented 1 year ago

This would be better if it was also possible to use this on Windows and not just Linux. I am not sure if Windows recognizes /dev/null.