From 904de577261e7024373e7a42fd763184764238f9 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 10 Oct 2023 13:15:59 -0400 Subject: Don't swallow namespace-parsing errors Previously, if there was a problem with the inputs and bild failed to determine the namespace, 'fromPath' would return 'Nothing' and then 'catMaybes' would drop the error-causing input altogether. In the one time that I had a bad input, this made debugging incredibly difficult. It's always a bad idea to swallow errors silently, so instead lets just kill the program if we have bad inputs. --- Biz/Ide/hooks/commit-msg | 2 -- Biz/Ide/hooks/commit-msg.bash | 2 ++ Biz/Ide/hooks/post-checkout | 15 ----------- Biz/Ide/hooks/post-checkout.bash | 15 +++++++++++ Biz/Ide/hooks/post-merge | 2 -- Biz/Ide/hooks/post-merge.bash | 2 ++ Biz/Ide/hooks/pre-commit | 21 --------------- Biz/Ide/hooks/pre-commit.bash | 21 +++++++++++++++ Biz/Ide/hooks/pre-push | 58 ---------------------------------------- Biz/Ide/hooks/pre-push.bash | 58 ++++++++++++++++++++++++++++++++++++++++ 10 files changed, 98 insertions(+), 98 deletions(-) delete mode 100755 Biz/Ide/hooks/commit-msg create mode 100755 Biz/Ide/hooks/commit-msg.bash delete mode 100755 Biz/Ide/hooks/post-checkout create mode 100755 Biz/Ide/hooks/post-checkout.bash delete mode 100755 Biz/Ide/hooks/post-merge create mode 100755 Biz/Ide/hooks/post-merge.bash delete mode 100755 Biz/Ide/hooks/pre-commit create mode 100755 Biz/Ide/hooks/pre-commit.bash delete mode 100755 Biz/Ide/hooks/pre-push create mode 100755 Biz/Ide/hooks/pre-push.bash (limited to 'Biz/Ide/hooks') diff --git a/Biz/Ide/hooks/commit-msg b/Biz/Ide/hooks/commit-msg deleted file mode 100755 index 64e400d..0000000 --- a/Biz/Ide/hooks/commit-msg +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -gitlint --ignore-stdin --staged --msg-filename "$1" run-hook diff --git a/Biz/Ide/hooks/commit-msg.bash b/Biz/Ide/hooks/commit-msg.bash new file mode 100755 index 0000000..64e400d --- /dev/null +++ b/Biz/Ide/hooks/commit-msg.bash @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +gitlint --ignore-stdin --staged --msg-filename "$1" run-hook diff --git a/Biz/Ide/hooks/post-checkout b/Biz/Ide/hooks/post-checkout deleted file mode 100755 index 73488b0..0000000 --- a/Biz/Ide/hooks/post-checkout +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -set -e -mktags=${CODEROOT:?}/Biz/Ide/mktags -old=$1 -new=$2 -# filter out only the changed haskell files -changed=($(git diff --diff-filter=d --name-only $old $new -- '*.hs')) -if [[ ! -r tags ]] || [[ ! -r TAGS ]] -then - $mktags "$CODEROOT"/**/* -elif [[ ${#changed[@]} -gt 0 ]] -then - $mktags $changed -fi -direnv reload diff --git a/Biz/Ide/hooks/post-checkout.bash b/Biz/Ide/hooks/post-checkout.bash new file mode 100755 index 0000000..73488b0 --- /dev/null +++ b/Biz/Ide/hooks/post-checkout.bash @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -e +mktags=${CODEROOT:?}/Biz/Ide/mktags +old=$1 +new=$2 +# filter out only the changed haskell files +changed=($(git diff --diff-filter=d --name-only $old $new -- '*.hs')) +if [[ ! -r tags ]] || [[ ! -r TAGS ]] +then + $mktags "$CODEROOT"/**/* +elif [[ ${#changed[@]} -gt 0 ]] +then + $mktags $changed +fi +direnv reload diff --git a/Biz/Ide/hooks/post-merge b/Biz/Ide/hooks/post-merge deleted file mode 100755 index c21211f..0000000 --- a/Biz/Ide/hooks/post-merge +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -exec ${CODEROOT:?}/Biz/Ide/hooks/post-checkout 'HEAD@{1}' HEAD diff --git a/Biz/Ide/hooks/post-merge.bash b/Biz/Ide/hooks/post-merge.bash new file mode 100755 index 0000000..c21211f --- /dev/null +++ b/Biz/Ide/hooks/post-merge.bash @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +exec ${CODEROOT:?}/Biz/Ide/hooks/post-checkout 'HEAD@{1}' HEAD diff --git a/Biz/Ide/hooks/pre-commit b/Biz/Ide/hooks/pre-commit deleted file mode 100755 index 2b4575c..0000000 --- a/Biz/Ide/hooks/pre-commit +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# -# - prevent frozen code from being checked in -# - guard against lint errors -## - set -e - changed=($(git diff-index --cached --name-only HEAD)) - for ns in ${changed[@]} - do - version=$(${CODEROOT:?}/Biz/Ide/version $ns) - if (( $version == -1 )); then - echo "info: version: $ns: deleted" - elif (( $version < 1 )); then - echo "fail: version: $ns: $version" - exit 1 - else - echo "info: version: $ns: $version" - fi - done - lint "${changed[@]}" -## diff --git a/Biz/Ide/hooks/pre-commit.bash b/Biz/Ide/hooks/pre-commit.bash new file mode 100755 index 0000000..2b4575c --- /dev/null +++ b/Biz/Ide/hooks/pre-commit.bash @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# +# - prevent frozen code from being checked in +# - guard against lint errors +## + set -e + changed=($(git diff-index --cached --name-only HEAD)) + for ns in ${changed[@]} + do + version=$(${CODEROOT:?}/Biz/Ide/version $ns) + if (( $version == -1 )); then + echo "info: version: $ns: deleted" + elif (( $version < 1 )); then + echo "fail: version: $ns: $version" + exit 1 + else + echo "info: version: $ns: $version" + fi + done + lint "${changed[@]}" +## diff --git a/Biz/Ide/hooks/pre-push b/Biz/Ide/hooks/pre-push deleted file mode 100755 index 0c313cb..0000000 --- a/Biz/Ide/hooks/pre-push +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash -# -# a simple ci that saves its results in a git note, formatted according to -# RFC-2822, more or less. -# -## - set -uo pipefail - [[ -n $(git status -s) ]] && { echo fail: dirty worktree; exit 1; } -## - at=$(date -R) - user=$(git config --get user.name) - mail=$(git config --get user.email) -## - while read local_ref local_sha remote_ref remote_sha - do - if [[ $local_ref =~ notes ]]; then - exit 0 - fi - commit=$(git notes --ref=ci show $local_ref || true) - if [[ -n "$commit" ]] - then - lint_ok=$() - if grep -q "Lint-is: good" <<< $commit - then - exit 0 - fi - if grep -q "Test-is: good" <<< $commit - then - exit 0 - fi - fi - ## - if lint "${CODEROOT:?}"/**/* - then - lint_result="good" - else - lint_result="fail" - exit 1 - fi - ## - if bild --test "${CODEROOT:?}"/**/* - then - test_result="good" - else - test_result="fail" - exit 1 - fi - ## - read -r -d '' note < -Test-at: $at -EOF - ## - git notes --ref=ci append -m "$note" - done -## diff --git a/Biz/Ide/hooks/pre-push.bash b/Biz/Ide/hooks/pre-push.bash new file mode 100755 index 0000000..0c313cb --- /dev/null +++ b/Biz/Ide/hooks/pre-push.bash @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# +# a simple ci that saves its results in a git note, formatted according to +# RFC-2822, more or less. +# +## + set -uo pipefail + [[ -n $(git status -s) ]] && { echo fail: dirty worktree; exit 1; } +## + at=$(date -R) + user=$(git config --get user.name) + mail=$(git config --get user.email) +## + while read local_ref local_sha remote_ref remote_sha + do + if [[ $local_ref =~ notes ]]; then + exit 0 + fi + commit=$(git notes --ref=ci show $local_ref || true) + if [[ -n "$commit" ]] + then + lint_ok=$() + if grep -q "Lint-is: good" <<< $commit + then + exit 0 + fi + if grep -q "Test-is: good" <<< $commit + then + exit 0 + fi + fi + ## + if lint "${CODEROOT:?}"/**/* + then + lint_result="good" + else + lint_result="fail" + exit 1 + fi + ## + if bild --test "${CODEROOT:?}"/**/* + then + test_result="good" + else + test_result="fail" + exit 1 + fi + ## + read -r -d '' note < +Test-at: $at +EOF + ## + git notes --ref=ci append -m "$note" + done +## -- cgit v1.2.3