From 5a01f4854c1e812f9dfcc3b31b49650ae5e11974 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Tue, 21 Mar 2017 18:32:21 +0000 Subject: [PATCH] chore: setup .gitattributes to perform correct line-ending conversions (#1192) This allows `npm run lint` to pass regardless of the `core.autocrlf` setting in git --- .gitattributes | 30 ++++++++++ Makefile | 1 + appveyor.yml | 3 - ...re-all-file-extensions-in-gitattributes.sh | 56 +++++++++++++++++++ 4 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 .gitattributes create mode 100755 scripts/ci/ensure-all-file-extensions-in-gitattributes.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..6a82d403 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,30 @@ +# Javascript files must retain LF line-endings (to keep eslint happy) +*.js text eol=lf +# CSS and SCSS files must retain LF line-endings (to keep ensure-staged-sass.sh happy) +*.css text eol=lf +*.scss text eol=lf + +# Text files +dictionary text +Dockerfile* text +.editorconfig text +etcher text +.git* text +*.html text +*.json text +LICENSE text +Makefile text +*.md text +*.sh text +*.svg text +*.yml text + +# Binary files (no line-ending conversions) +*.bz2 binary +*.gz binary +*.icns binary +*.ico binary +*.img binary +*.png binary +*.xz binary +*.zip binary diff --git a/Makefile b/Makefile index 3eba9b44..41b754ef 100644 --- a/Makefile +++ b/Makefile @@ -428,6 +428,7 @@ sanity-checks: ./scripts/ci/ensure-staged-sass.sh ./scripts/ci/ensure-npm-dependencies-compatibility.sh ./scripts/ci/ensure-npm-shrinkwrap-versions.sh + ./scripts/ci/ensure-all-file-extensions-in-gitattributes.sh clean: rm -rf $(BUILD_DIRECTORY) diff --git a/appveyor.yml b/appveyor.yml index c5c89844..556647d2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,6 @@ # appveyor file # http://www.appveyor.com/docs/appveyor-yml -init: - - git config --global core.autocrlf input - image: Visual Studio 2015 cache: diff --git a/scripts/ci/ensure-all-file-extensions-in-gitattributes.sh b/scripts/ci/ensure-all-file-extensions-in-gitattributes.sh new file mode 100755 index 00000000..3be3036d --- /dev/null +++ b/scripts/ci/ensure-all-file-extensions-in-gitattributes.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +### +# Copyright 2017 resin.io +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +### + +set -u +set -e + +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +"$HERE/../build/check-dependency.sh" git + +# Read list of wildcards from .gitattributes +wildcards=() +while IFS='' read -r line || [[ -n "$line" ]]; do + if [[ -n "$line" ]]; then + if [[ ! "$line" =~ "^#" ]]; then + filetype=$(echo "$line" | cut -d ' ' -f 2) + if [[ "$filetype" == "text" ]] || [[ "$filetype" == "binary" ]]; then + wildcards+=("$(echo "$line" | cut -d ' ' -f 1)") + fi + fi + fi +done < .gitattributes + +# Verify those wildcards against all files stored in the repo +git ls-tree -r HEAD | while IFS='' read line; do + if [[ "$(echo $line | cut -d ' ' -f 2)" == "blob" ]]; then + # the cut delimiter in the line below is actually a tab character, not a space + filename=$(basename $(echo "$line" | cut -d ' ' -f 2)) + found_match=0 + for wildcard in "${wildcards[@]}"; do + if [[ "$filename" = $wildcard ]]; then + found_match=1 + break + fi + done + if [[ $found_match -eq 0 ]]; then + echo "No wildcards match $filename" + exit 1 + fi + fi +done