From f63cfb4462b57d483fce3d0ac9ab9dce4fcc525f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 13 Sep 2023 15:48:34 +0200 Subject: [PATCH] replace pre-commit hook with hook in pre-create --- devShell.nix | 3 ++- pkgs/tea-create-pr/script.sh | 2 ++ scripts/pre-commit | 52 ------------------------------------ 3 files changed, 4 insertions(+), 53 deletions(-) delete mode 100755 scripts/pre-commit diff --git a/devShell.nix b/devShell.nix index 8a91831d6..62daa71c5 100644 --- a/devShell.nix +++ b/devShell.nix @@ -14,7 +14,8 @@ config.treefmt.build.wrapper ]; shellHook = '' - ln -sf ../../scripts/pre-commit "$(git rev-parse --show-toplevel)/.git/hooks/pre-commit" + # no longer used + rm "$(git rev-parse --show-toplevel)/.git/hooks/pre-commit" ''; }; }; diff --git a/pkgs/tea-create-pr/script.sh b/pkgs/tea-create-pr/script.sh index 385d7147f..e85d5ea4c 100644 --- a/pkgs/tea-create-pr/script.sh +++ b/pkgs/tea-create-pr/script.sh @@ -9,6 +9,8 @@ currentBranch="$(git rev-parse --abbrev-ref HEAD)" user="$(tea login list -o simple | cut -d" " -f4)" tempRemoteBranch="$user-$currentBranch" +nix fmt -- --fail-on-change + git log --reverse --pretty="format:%s%n%n%b%n%n" "$remoteName/$targetBranch..HEAD" > "$TMPDIR"/commit-msg $EDITOR "$TMPDIR"/commit-msg diff --git a/scripts/pre-commit b/scripts/pre-commit deleted file mode 100755 index 1590d565e..000000000 --- a/scripts/pre-commit +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash -# -# Run treefmt on every commit and abort if some files have changed. -# -# To install, copy this file to .git/hooks/pre-commit and make sure it's -# executable. -# -set -euo pipefail - -# Redirect stdout to stderr -exec 1>&2 - -# Get list of files that will be committed -mapfile -t commit_files < <(git diff --name-only --cached) - -log() { - echo "treefmt pre-commit: $*" -} - -# If the commit has no files, skip everything as there is nothing to format -if [[ -z ${commit_files+x} ]] || [[ ${#commit_files} = 0 ]]; then - log "no files to format" - exit 0 -fi - -# Will be called at the end -restore_stash() { - # Store exit status - local ret=$? - # Don't fail on error from now on - set +e - # Put bash the staged files - git stash pop -q - - if [[ $ret -gt 0 ]]; then - log "aborting commit, detected unformatted files" - fi - exit "$ret" -} - -# Stash index and work dir, keeping only the to-be-committed changes in -# the working directory. -git stash push --quiet --keep-index --message "treefmt pre-commit" - -# Install the callback to restore the stash on script exit -trap restore_stash EXIT - -# Run treefmt on the files in the index and record the result. -nix fmt -- "${commit_files[@]}" - -# Check if there is a diff -git diff --name-only --exit-code