aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-01-15 23:14:06 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-01-15 23:14:06 +0300
commitbfba2ae7228456fad8aeb35710d00773f91fd195 (patch)
treeb2cd5b15af8b56566ecb4136992dd3f7bda5ed5b
parentadd repo_line_endings_are_normalized (diff)
downloadlinux-home-bfba2ae7228456fad8aeb35710d00773f91fd195.tar.gz
linux-home-bfba2ae7228456fad8aeb35710d00773f91fd195.zip
add branch_eol_normalized
* repo_line_endings_are_normalized -> repo_eol_normalized * repo_eol_normalized checks every branch.
Diffstat (limited to '')
-rw-r--r--%HOME%/.bash_utils/git.sh49
1 files changed, 36 insertions, 13 deletions
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() (