From bfba2ae7228456fad8aeb35710d00773f91fd195 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 15 Jan 2017 23:14:06 +0300 Subject: add branch_eol_normalized * repo_line_endings_are_normalized -> repo_eol_normalized * repo_eol_normalized checks every branch. --- %HOME%/.bash_utils/git.sh | 49 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to '%HOME%') diff --git a/%HOME%/.bash_utils/git.sh b/%HOME%/.bash_utils/git.sh index 552ed87..9204847 100644 --- a/%HOME%/.bash_utils/git.sh +++ b/%HOME%/.bash_utils/git.sh @@ -22,28 +22,51 @@ is_repo_clean() ( alias repo_clean_all='git clean -fdx' alias repo_clean_ignored='git clean -fdX' -repo_line_endings_are_normalized() ( +branch_eol_normalized() ( set -o errexit -o nounset -o pipefail - local -r prefix='i/' - if is_repo_clean; then repo_clean_ignored + else + echo "${FUNCNAME[0]}: repository isn't clean" >&2 + return 1 + fi + + local line + while IFS= read -d '' -r line; do local eolinfo - while IFS= read -d '' -r eolinfo; do - if [ "${eolinfo#$prefix}" == "$eolinfo" ]; then - echo "${FUNCNAME[0]}: malformatted eolinfo: $eolinfo" >&2 - return 1 - fi - eolinfo="${eolinfo#$prefix}" - if [ "$eolinfo" == crlf ] || [ "$eolinfo" == mixed ]; then - echo "${FUNCNAME[0]}: detected invalid line endings" >&2 - fi - done < <( git ls-files -z --eol | cut -z -d ' ' -f 1 ) + if ! eolinfo="$( expr "$line" : 'i/\([^ ]*\)' )"; then + echo "${FUNCNAME[0]}: couldn't extract eolinfo from: $line" >&2 + return 1 + fi + + local path + if ! path="$( expr "$line" : $'.*\t\\(.*\\)' )"; then + echo "${FUNCNAME[0]}: couldn't extract file path from: $line" >&2 + return 1 + fi + + if [ "$eolinfo" == crlf ] || [ "$eolinfo" == mixed ]; then + echo "${FUNCNAME[0]}: detected inconsistent line endings in file: $path" >&2 + fi + done < <( git ls-files -z --eol ) +) + +repo_eol_normalized() ( + set -o errexit -o nounset -o pipefail + + if is_repo_clean; then + repo_clean_ignored else echo "${FUNCNAME[0]}: repository isn't clean" >&2 return 1 fi + + local branch + while IFS= read -r branch; do + git checkout --quiet "$branch" + branch_eol_normalized "$branch" + done < <( list_repo_branches ) ) tighten_repo_security() ( -- cgit v1.2.3