Closed mildblimp closed 3 years ago
Can you provide your full search and replace config and some example text that should be acting on? This does work for me.
➜ cat .pre-commit-search-and-replace.yaml
- search: A Fail String
- search: A Replacement String
replacement: A Good String
➜ pre-commit try-repo . search-and-replace --verbose
[WARNING] Creating temporary repo with uncommitted changes...
===============================================================================
Using config:
===============================================================================
repos:
- repo: /var/folders/9g/zxvd77gd76xb24djffcrp31r0000gn/T/tmp5gajpexa/shadow-repo
rev: 76a24e1082c426887431119e45072e651986be52
hooks:
- id: search-and-replace
===============================================================================
[INFO] Initializing environment for /var/folders/9g/zxvd77gd76xb24djffcrp31r0000gn/T/tmp5gajpexa/shadow-repo.
Search and replace strings...............................................Failed
- hook id: search-and-replace
- duration: 0.23s
- exit code: 1
- files were modified by this hook
==== Found 1 occurrences of "A Fail String" in test/fail.txt:
test/fail.txt, line 2, col 1:
A Fail String
^
==== Found 1 occurrences of "A Replacement String" in test/replace.txt:
test/replace.txt, line 1, col 1:
A Replacement String
^
Fixed test/replace.txt
Oh, I see. The non-replacement is still exiting 0 when alone.
I just did some testing and I think that that's the issue indeed.
Fixed up by https://github.com/mattlqx/pre-commit-search-and-replace/commit/417c99dafb534d7517d9abc17f0293de3c915a72
➜ pre-commit try-repo . search-and-replace --verbose
[WARNING] Creating temporary repo with uncommitted changes...
===============================================================================
Using config:
===============================================================================
repos:
- repo: /var/folders/9g/zxvd77gd76xb24djffcrp31r0000gn/T/tmpqdpg4lz1/shadow-repo
rev: 0da8174b0938bf83d166825667cbe577cb8ac13c
hooks:
- id: search-and-replace
===============================================================================
[INFO] Initializing environment for /var/folders/9g/zxvd77gd76xb24djffcrp31r0000gn/T/tmpqdpg4lz1/shadow-repo.
Search and replace strings...............................................Failed
- hook id: search-and-replace
- duration: 0.15s
- exit code: 1
==== Found 1 occurrences of "A Fail String" in test/fail.txt:
test/fail.txt, line 2, col 1:
A Fail String
^
Thanks for the report!
According to the documentation, adding
- search: JustFailIfThisStringIsFound
should make the commit fail. However, the commit only seems to fail if I add a-replacement
tag.