pre-commit / pre-commit-hooks

Some out-of-the-box hooks for pre-commit
MIT License
5.2k stars 694 forks source link

`file-contents-sorter` breaks .gitignore order #1086

Closed ddeepwell closed 3 weeks ago

ddeepwell commented 3 weeks ago

The file-contents-sorter uses the default python sorter which places items with a leading exclamation mark before the equivalent file. When this is used on the .gitignore file, it breaks the functionality to include files of a specific name after a more generic name was ignored.

For example, the following .gitignore file will ignore test1-example

!test*-example
test*

but this next will not ignore test1-example

test*
!test*-example

Using the file sorter pre-commit hook as is breaks the management of ignored files.

Can an option be added to place leading exclamation mark lines to the end of the file? This could be further generalized to allow any matching regex to be placed at the end of the file.

asottile commented 3 weeks ago

then... simply don't use it on .gitignore ? it's not designed for that