2

Inside gitignore/Global/macOS.gitignore, there are two \r\r as shown in the below screenshot:

Lines 6 - 11 of macOS.gitignore

I use pre-commit==v4.0.1 with its mixed-line-ending and trailing-whitespace hooks. Both get triggered on this line.

How can I locally disable those hooks within my .gitignore file?

My current solution I employ is exclude: .gitignore within my .pre-commit-config.yaml for both hooks. However, I don't like this, as it ignores the entire .gitignore file for these hooks, when I really just want to locally disable those two hooks around lines 6 - 8 of the .gitignore.

Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119

2 Answers2

3

there is no such option for what you want

the pre-commit framework operates on files so your best bet is to leverage exclude:

    -   id: trailing-whitespace
        exclude: ^\.gitignore$

or more realistically, just remove the Icon\r line since it's very unlikely to be hit (only appearing when you customize the icon for a folder on macos). another option is to use Icon? instead -- it's slightly less precise but you're probably fairly unlikely to match something else with it


disclaimer: I created pre-commit and pre-commit-hooks

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
0

Another approach would be to avoid configuring anything in pre-commit.com settings, and make sure the .gitignore is checked out with \n only in the first place.

For that, try and add in a .gitattributes, in the same folder as your .gitignore:

*.gitignore eol=lf
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • that breaks the `Icon\r\r\n` rule on clone / checkout since it converts the `\r\n` to `\n` – anthony sottile Dec 24 '21 at 00:25
  • @AnthonySottile Yes, that is the idea, to allow the other pre-commit hooks to not be tripped by those rules. – VonC Dec 24 '21 at 00:26
  • the `Icon\r\r\n` is intentional, to avoid checking in `Icon\r` files created by macos when you customize the icon of a directory – anthony sottile Dec 24 '21 at 00:30
  • @AnthonySottile OK. I suspect that is a workaround that will need to be revisited, as it has unintentional side effect with other pre-commit hooks. – VonC Dec 24 '21 at 00:33