From 9ee44b92c7f2ed652dd5f357e610cb175a03b8c1 Mon Sep 17 00:00:00 2001 From: Dennis Traub Date: Thu, 22 Feb 2024 20:53:36 +0100 Subject: [PATCH] Add shebang line to top of pre-commit hook so it can be used on Windows (#6156) --- .git-hooks/pre-commit | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit index ff769934fd4..93414574c92 100755 --- a/.git-hooks/pre-commit +++ b/.git-hooks/pre-commit @@ -1,31 +1,31 @@ +#!/bin/sh -tag=[PRE-COMMIT] +tag="[PRE-COMMIT]" -function log { +log() { echo "$tag $1" } # If any of the local directories contain staged changes, try # and run pre-commit.sh. -for dir in $(ls -A) ; do - # Get a list of file names for changed files. - staged=$(git diff --cached --name-only -- "$dir") +for dir in * ; do + if [ -d "$dir" ]; then + # Get a list of file names for changed files. + staged=$(git diff --cached --name-only -- "$dir") + if [ -n "$staged" ] ; then + log "The following files have staged changes in $dir:" + log "$staged" + if [ -x "${dir}/hook_scripts/pre-commit.sh" ] ; then + + # Enter directory. + (cd "$dir" || exit - if [ -n "$staged" ] ; then - log "The following files have staged changes in $dir:\n$staged" - if [ -x "${dir}/hook_scripts/pre-commit.sh" ] ; then - - # Enter directory. - cd $dir - - log "Working from $(pwd)..." - if ! "./hook_scripts/pre-commit.sh" ; then - log "$dir's pre-commit hook failed." - exit 1 + log "Working from $(pwd)..." + if ! "./hook_scripts/pre-commit.sh" ; then + log "$dir's pre-commit hook failed." + exit 1 + fi) fi - - # Exit directory. - cd .. fi fi done \ No newline at end of file