aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%/.bash_utils
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-01-15 21:16:42 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-01-15 21:16:42 +0300
commit3d754069fda42cbd858fe6d1c7181fdc41592a81 (patch)
treebbeff0272867d5304fcc677ebffbc5268ca5cff4 /%HOME%/.bash_utils
parentremove .curlrc (diff)
downloadlinux-home-3d754069fda42cbd858fe6d1c7181fdc41592a81.tar.gz
linux-home-3d754069fda42cbd858fe6d1c7181fdc41592a81.zip
add repo_line_endings_are_normalized
Diffstat (limited to '%HOME%/.bash_utils')
-rw-r--r--%HOME%/.bash_utils/git.sh36
1 files changed, 36 insertions, 0 deletions
diff --git a/%HOME%/.bash_utils/git.sh b/%HOME%/.bash_utils/git.sh
index 775e224..552ed87 100644
--- a/%HOME%/.bash_utils/git.sh
+++ b/%HOME%/.bash_utils/git.sh
@@ -10,6 +10,42 @@ source "$HOME/.bash_utils/text.sh"
alias list_repo_files='git ls-tree -r --name-only HEAD'
alias list_repo_dirs='git ls-tree -r --name-only HEAD -d'
+list_repo_branches() {
+ git for-each-ref --format='%(refname:short)' refs/heads/
+}
+
+is_repo_clean() (
+ set -o errexit -o nounset -o pipefail
+ test -z "$( git status --porcelain )"
+)
+
+alias repo_clean_all='git clean -fdx'
+alias repo_clean_ignored='git clean -fdX'
+
+repo_line_endings_are_normalized() (
+ set -o errexit -o nounset -o pipefail
+
+ local -r prefix='i/'
+
+ if is_repo_clean; then
+ repo_clean_ignored
+ 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 )
+ else
+ echo "${FUNCNAME[0]}: repository isn't clean" >&2
+ return 1
+ fi
+)
+
tighten_repo_security() (
set -o errexit -o nounset -o pipefail