Escape spaces within file names in pre-commit hook script (#5721)

master
m-adler 2019-01-08 07:30:20 +01:00 committed by Lily Scott
parent 30979ed104
commit e83490a90e
1 changed files with 5 additions and 5 deletions

View File

@ -103,14 +103,14 @@ Alternately you can save this script as `.git/hooks/pre-commit` and give it exec
```bash
#!/bin/sh
jsfiles=$(git diff --cached --name-only --diff-filter=ACM "*.js" "*.jsx" | tr '\n' ' ')
[ -z "$jsfiles" ] && exit 0
FILES=$(git diff --cached --name-only --diff-filter=ACM "*.js" "*.jsx" | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0
# Prettify all staged .js files
echo "$jsfiles" | xargs ./node_modules/.bin/prettier --write
# Prettify all selected files
echo "$FILES" | xargs ./node_modules/.bin/prettier --write
# Add back the modified/prettified files to staging
echo "$jsfiles" | xargs git add
echo "$FILES" | xargs git add
exit 0
```