Home > Net >  Find wrapped strings in a pre-push git hook
Find wrapped strings in a pre-push git hook

Time:04-08

I am trying to go through the changes being made in a git push and find any instance of a wrapped string like so: ___('something to be translated') so that I can make some subsequent API calls with that information. But for some reason I am unable to get any sort of useful output when I try to use a git diff --cached call. I already have my regex pattern figured out to do the search. Any suggestions on this would be great.

My code looks something like this:

FILES_PATTERN="/___[^)] \)/gm"
git diff --cached --name-only | \
    grep -E $FILES_PATTERN | \
    GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n  echo 'COMMIT contains strings that need to be uploaded to Lokalise.' && exit 1

CodePudding user response:

Try this. I think your bash script is the main issue. It's not formatted properly. This will also make it so the output will only be the modified lines in addition to the ___() matches.

pattern="___\([^)] \)"
echo $(git diff $remote_sha $local_sha | grep -E $pattern | grep '^[ -]')

Hope this works.

  • Related