summaryrefslogtreecommitdiff
path: root/pre-commit.d
diff options
context:
space:
mode:
Diffstat (limited to 'pre-commit.d')
-rwxr-xr-xpre-commit.d/30store-metadata12
1 files changed, 9 insertions, 3 deletions
diff --git a/pre-commit.d/30store-metadata b/pre-commit.d/30store-metadata
index 2e35e6c..aeec374 100755
--- a/pre-commit.d/30store-metadata
+++ b/pre-commit.d/30store-metadata
@@ -32,10 +32,16 @@ filter_ignore() {
statf() {
while read statfile; do
- echo "$(stat --format="$1" "$statfile") '$statfile'"
+ printf "$(stat --format="$1" "$statfile") "
+ echo "$statfile" | shellquote
done
}
+shellquote() {
+ # Single quotes text, escaping existing single quotes.
+ sed -e "s/'/'\"'\"'/" -e "s/^/'/" -e "s/$/'/"
+}
+
generate_metadata() {
# This function generates the script commands to fix any files
# that aren't owner=root, group=root, or mode=0644 or 0755.
@@ -60,7 +66,7 @@ generate_metadata() {
# These version control systems do not track directories,
# so empty directories must be stored specially.
find $NOVCS -type d -empty -print |
- sort | sed -e "s/^/mkdir -p '/" -e "s/\$/'/"
+ sort | shellquote | sed -e "s/^/mkdir -p /"
fi
if [ "$VCS" = darcs ]; then
@@ -68,7 +74,7 @@ generate_metadata() {
# so they must be stored specially.
find $NOVCS -type l -print | sort | filter_ignore | while read link; do
dest=$( readlink "$link" )
- printf "ln -sf '%s' '%s'\n" "$dest" "$link"
+ printf "ln -sf '%s' '%s'\n" "$(echo "$dest" | shellquote)" "$(echo "$link" | shellquote)"
done
fi