Martin Kumecký
Martin Kumecký

Reputation: 175

Visual studio 2019 git pre-commit hook is ignoring perl command

I created pre-commit hook for my project. It works fine if I commit changes through command line or Git Extensions GUI. But if I commit my changes through Visual studio, for some reason perl command gets somehow ignored, does nothing and output file is the same.

I am trying to delete some lines in .json file if it matches my regex expression. Here is script I am using in pre-commit hook.

for file in $(git diff --cached --name-only)
do
    if [[ $file == "path/to/my/file"* ]]; then
        file="./${file}"
        perl -i -pne 'BEGIN {undef $/} s/^\s*"id":.*?\r?\n//img' $file
        perl -i -pne 'BEGIN {undef $/} s/,(\s*})/$1/isg' $file
        git add $file
    fi
done

Upvotes: 1

Views: 1468

Answers (1)

Martin Kumecký
Martin Kumecký

Reputation: 175

It seems that Visual studio has its own implementation of Git, which doesn't have perl command, so it gets ignored. There are 2 possible solutions:

Upvotes: 2

Related Questions