tripleo-quickstart/ci-scripts/pre-commit.d/validate-yaml-in-commit
Gael Chamoulaud 77e537f868 Add blank newline at the end of file
This patch adds blank newline for each [yaml|sh] files if they
don't end with one. This will allows us getting linters happy and avoid us
having git adding "\ No newline at end of file" in diffs when pushing
a new patch.

In other way, you can configure Git to properly handle line endings in
typing:

$ git config --global core.autocrlf input

Change-Id: I8a113541b3eae6a36ed32995822dedbbd2d9666e
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
2017-03-27 10:40:32 +02:00

20 lines
569 B
Bash
Executable File

#!/bin/sh
SCRIPTS="$PWD/ci-scripts"
tmpdir=$(mktemp -d commitXXXXXX)
trap "rm -rf $tmpdir" EXIT
# This checks out the index into a temporary directory, which is
# necessary if you want to validate the files that are actually
# part of the commit (because when performing an interactive add,
# for example, files in a commit may not actually match the content
# of files in the working directory).
git checkout-index --prefix=$tmpdir/ -af
git diff --cached --name-only --diff-filter=ACM | grep '.yml' | (
cd $tmpdir
xargs --no-run-if-empty $SCRIPTS/validate-yaml
)