Is there any way to not to run "post commit hook" or skip "post commit hook statement" when a specific file is committed?
Asked
Active
Viewed 172 times
2 Answers
1
This worked for me:
"C:\Program Files\VisualSVN Server\bin\svnlook" changed C:\Repositories\sbm2| findstr version.json && EXIT /B
#here my main part of post-commit-hook will begin
Thanks @uzsolt

tripleee
- 175,061
- 34
- 275
- 318

Raj Sharma
- 91
- 1
- 10
0
You can use a test in your post-commit
script. The svnlook changed repository_directory
will show which files changed - can use grep
or similar.
For example:
#!/bin/sh
/usr/bin/svnlook changed /svn/repo | grep -w ' yourfile$' && exit 0
# here begin the main part of your (original) hook

uzsolt
- 5,832
- 2
- 20
- 32
-
"C:\Program Files\VisualSVN Server\bin\svnlook" changed C:\Repositories\sbm2 | findstr version.json ----------------------How to stop execution, it is still executing – Raj Sharma Jul 13 '18 at 14:03
-
Ah, Windows. Did you try add `&& exit 0` as I describe in example? https://ss64.com/nt/syntax-conditional.html – uzsolt Jul 13 '18 at 14:10
-
This could fail if there are files whose name is a superstring of *yourfile.* Perhaps better use `grep -Fx` with the full path to the file. – tripleee Jul 13 '18 at 14:11
-
@tripleee please check `-w` in `grep` options. But in this case it's irrelevant because the OP uses Windows. – uzsolt Jul 13 '18 at 14:18
-
No, it's not. `grep -w yourfile` matches `not-yourfile.too`, on Windows just as on every other platform. – tripleee Jul 13 '18 at 14:31
-
On FreeBSD doesn't: `echo 'not_yourfile.too' | grep -w yourfile` prints nothing (and returns error code 1). The OP uses Windows without Cygwin, and replaces `grep` to `findstr` (see his first comment). – uzsolt Jul 13 '18 at 14:34
-
1Sorry, switched the underscore to a minus before I saw your reply. The point remains; `-w` reduces the chance of false positives, but by no means eliminates it. Projects with files with similar names are more common than you seem to think. – tripleee Jul 13 '18 at 14:37
-
You've right. But the `-x` doesn't work because `svnlook changed` has a plus letter (see http://svnbook.red-bean.com/en/1.7/svn.ref.svnlook.c.changed.html). Would better `grep " yourfile$"`. – uzsolt Jul 13 '18 at 14:45
-
@RajSharma check the documentation: https://ss64.com/nt/findstr.html - I think you should use `||` instead of `&&` because `findstr` returns `false` if found the pattern and returns `true` if not found. – uzsolt Jul 13 '18 at 17:46
-
"C:\Program Files\VisualSVN Server\bin\svnlook" changed C:\Repositories\sbm2| findstr version.json && EXIT /B #thanks @uzsolt – Raj Sharma Jul 14 '18 at 07:18