From e83490a90e1bff03fe52d2e83be0799d430444c9 Mon Sep 17 00:00:00 2001 From: m-adler Date: Tue, 8 Jan 2019 07:30:20 +0100 Subject: [PATCH] Escape spaces within file names in pre-commit hook script (#5721) --- docs/precommit.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/precommit.md b/docs/precommit.md index 53eafe6a0..7b0ba8d8b 100644 --- a/docs/precommit.md +++ b/docs/precommit.md @@ -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 ```