From 7a816cafb6bafd661ad239ae9c545f928587fcca Mon Sep 17 00:00:00 2001 From: David Knapp Date: Fri, 13 Feb 2026 09:40:30 +0100 Subject: [PATCH 01/28] Stash uncommited changes before running the pre-commit Should prevent the following scenario: pre-commit fails and the dev does some changes Changes are not commited pre-commit runs again, but successfull Non-updated commit gets push, CI fails With this update the pre-commit will fail again, because the un-commited changes are stashed --- scripts/pre-commit | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/pre-commit b/scripts/pre-commit index 0f04e17eba..d5aa14cf75 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -63,6 +63,10 @@ fi # Redirect output to stderr. exec 1>&2 +# Stash any unstaged changes, including untracked files, to ensure that the pre-commit checks are performed on the exact state of the files being committed. +# The --keep-index option allows staged changes to remain intact, while --include-untracked ensures that untracked files are also stashed. +# The --message option provides a description for the stash entry, making it easier to identify later. +git stash push --keep-index --include-untracked --message "pre-commit-stash" nocontinue=0 for file in `git diff --cached --name-only` @@ -114,6 +118,9 @@ do fi done +# Pop the stash to restore the working directory to its original state before the pre-commit checks were performed. +git stash pop + # exit 1 if there was a nonindented file # this will abort the commit exit $nocontinue From 176da54aa0e53dca0f2931408688ace45cda4f74 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Fri, 13 Feb 2026 09:53:22 +0100 Subject: [PATCH 02/28] Print a message if something has been added to the stash --- scripts/pre-commit | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index d5aa14cf75..d52b141652 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -68,6 +68,17 @@ exec 1>&2 # The --message option provides a description for the stash entry, making it easier to identify later. git stash push --keep-index --include-untracked --message "pre-commit-stash" +nostashed=0 +if [ -z "$(git stash list | grep "pre-commit-stash")" ]; then + # If there was no stash created, set nostashed to 1 to indicate that there are no changes to pop later. + nostashed=1 +else + # If a stash was created, print a message to inform the user that unstaged changes have been stashed and will be popped later. + echo "" + printf '\033[0;31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes again if you want to include them in the commit." + echo "" +fi + nocontinue=0 for file in `git diff --cached --name-only` do @@ -118,8 +129,11 @@ do fi done -# Pop the stash to restore the working directory to its original state before the pre-commit checks were performed. -git stash pop +if [ $nostashed -eq 0 ]; then + # If a stash was created, pop it to restore the working directory to its original state before the pre-commit checks were performed. + git stash pop +fi + # exit 1 if there was a nonindented file # this will abort the commit From f7ac57e82a984721d2ce0d9d21d2b7c04a61132b Mon Sep 17 00:00:00 2001 From: David Knapp Date: Fri, 13 Feb 2026 09:56:39 +0100 Subject: [PATCH 03/28] test --- scripts/pre-commit | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index d52b141652..0921c34d19 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -68,16 +68,16 @@ exec 1>&2 # The --message option provides a description for the stash entry, making it easier to identify later. git stash push --keep-index --include-untracked --message "pre-commit-stash" -nostashed=0 -if [ -z "$(git stash list | grep "pre-commit-stash")" ]; then - # If there was no stash created, set nostashed to 1 to indicate that there are no changes to pop later. - nostashed=1 -else - # If a stash was created, print a message to inform the user that unstaged changes have been stashed and will be popped later. - echo "" - printf '\033[0;31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes again if you want to include them in the commit." - echo "" -fi +#nostashed=0 +#if [ -z "$(git stash list | grep "pre-commit-stash")" ]; then +# # If there was no stash created, set nostashed to 1 to indicate that there are no changes to pop later. +# nostashed=1 +#else +# # If a stash was created, print a message to inform the user that unstaged changes have been stashed and will be popped later. +# echo "" +# printf '\033[0;31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes again if you want to include them in the commit." +# echo "" +#fi nocontinue=0 for file in `git diff --cached --name-only` @@ -129,10 +129,10 @@ do fi done -if [ $nostashed -eq 0 ]; then - # If a stash was created, pop it to restore the working directory to its original state before the pre-commit checks were performed. - git stash pop -fi +#if [ $nostashed -eq 0 ]; then +# # If a stash was created, pop it to restore the working directory to its original state before the pre-commit checks were performed. +# git stash pop +#fi # exit 1 if there was a nonindented file From e2e4d149af707f3827fe1485c53094b031eed47e Mon Sep 17 00:00:00 2001 From: David Knapp Date: Fri, 13 Feb 2026 09:58:46 +0100 Subject: [PATCH 04/28] test --- scripts/pre-commit | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 0921c34d19..070369dbfa 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -66,7 +66,7 @@ exec 1>&2 # Stash any unstaged changes, including untracked files, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact, while --include-untracked ensures that untracked files are also stashed. # The --message option provides a description for the stash entry, making it easier to identify later. -git stash push --keep-index --include-untracked --message "pre-commit-stash" +#git stash push --keep-index --include-untracked --message "pre-commit-stash" #nostashed=0 #if [ -z "$(git stash list | grep "pre-commit-stash")" ]; then @@ -74,9 +74,7 @@ git stash push --keep-index --include-untracked --message "pre-commit-stash" # nostashed=1 #else # # If a stash was created, print a message to inform the user that unstaged changes have been stashed and will be popped later. -# echo "" -# printf '\033[0;31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes again if you want to include them in the commit." -# echo "" +# echo "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes if you want to include them in the commit." #fi nocontinue=0 @@ -129,7 +127,7 @@ do fi done -#if [ $nostashed -eq 0 ]; then +#if [ $nostashed -eq 0 ] then # # If a stash was created, pop it to restore the working directory to its original state before the pre-commit checks were performed. # git stash pop #fi From cae84bb97ee461868186664f3902b5179619bff8 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Fri, 13 Feb 2026 10:16:08 +0100 Subject: [PATCH 05/28] check stash-size --- scripts/pre-commit | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 070369dbfa..88612140a5 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -63,19 +63,22 @@ fi # Redirect output to stderr. exec 1>&2 +# Get the size of the stash list before stashing any changes. This is used to determine later if a new stash entry was created for the pre-commit checks. +stash_size_before=$(git stash list | wc -l) + # Stash any unstaged changes, including untracked files, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact, while --include-untracked ensures that untracked files are also stashed. # The --message option provides a description for the stash entry, making it easier to identify later. -#git stash push --keep-index --include-untracked --message "pre-commit-stash" +git stash push --keep-index --include-untracked --message "pre-commit-stash" + +# Get the size of the stash list after stashing changes. +stash_size_after=$(git stash list | wc -l) -#nostashed=0 -#if [ -z "$(git stash list | grep "pre-commit-stash")" ]; then -# # If there was no stash created, set nostashed to 1 to indicate that there are no changes to pop later. -# nostashed=1 -#else -# # If a stash was created, print a message to inform the user that unstaged changes have been stashed and will be popped later. -# echo "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes if you want to include them in the commit." -#fi +stashed=($stash_size_after - $stash_size_before) +# If the stash size has increased, it means a new stash entry was created. +if [ $stashed -gt 0 ]; then + printf '\033[31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes if you want to include them in the commit." +fi nocontinue=0 for file in `git diff --cached --name-only` @@ -127,10 +130,10 @@ do fi done -#if [ $nostashed -eq 0 ] then -# # If a stash was created, pop it to restore the working directory to its original state before the pre-commit checks were performed. -# git stash pop -#fi +if [ $stashed -gt 0 ]; then + # If a stash was created, pop it to restore the working directory to its original state before the pre-commit checks were performed. + git stash pop +fi # exit 1 if there was a nonindented file From 4ee340b1c4e5b301c68d4ded477cb41d1db3e56f Mon Sep 17 00:00:00 2001 From: David Knapp Date: Fri, 13 Feb 2026 10:17:14 +0100 Subject: [PATCH 06/28] Fix stash-size look-up --- scripts/pre-commit | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 88612140a5..b647bae71e 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -65,6 +65,7 @@ exec 1>&2 # Get the size of the stash list before stashing any changes. This is used to determine later if a new stash entry was created for the pre-commit checks. stash_size_before=$(git stash list | wc -l) +echo "Stash size before: $stash_size_before" # Stash any unstaged changes, including untracked files, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact, while --include-untracked ensures that untracked files are also stashed. @@ -73,8 +74,9 @@ git stash push --keep-index --include-untracked --message "pre-commit-stash" # Get the size of the stash list after stashing changes. stash_size_after=$(git stash list | wc -l) +echo "Stash size after: $stash_size_after" -stashed=($stash_size_after - $stash_size_before) +stashed=$(($stash_size_after - $stash_size_before)) # If the stash size has increased, it means a new stash entry was created. if [ $stashed -gt 0 ]; then printf '\033[31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes if you want to include them in the commit." From d0828e59f53d7c2a657e72f641d75d6838204ed9 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Fri, 13 Feb 2026 10:18:11 +0100 Subject: [PATCH 07/28] don't include untracked files --- scripts/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index b647bae71e..3b97ab7def 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -70,7 +70,7 @@ echo "Stash size before: $stash_size_before" # Stash any unstaged changes, including untracked files, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact, while --include-untracked ensures that untracked files are also stashed. # The --message option provides a description for the stash entry, making it easier to identify later. -git stash push --keep-index --include-untracked --message "pre-commit-stash" +git stash push --keep-index --message "pre-commit-stash" # Get the size of the stash list after stashing changes. stash_size_after=$(git stash list | wc -l) From 626a6b351d0d3b5129912d43e7e1430581ca2257 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Fri, 13 Feb 2026 10:19:06 +0100 Subject: [PATCH 08/28] remove debug-output --- scripts/pre-commit | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 3b97ab7def..594f5bc5ff 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -65,7 +65,6 @@ exec 1>&2 # Get the size of the stash list before stashing any changes. This is used to determine later if a new stash entry was created for the pre-commit checks. stash_size_before=$(git stash list | wc -l) -echo "Stash size before: $stash_size_before" # Stash any unstaged changes, including untracked files, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact, while --include-untracked ensures that untracked files are also stashed. @@ -74,7 +73,6 @@ git stash push --keep-index --message "pre-commit-stash" # Get the size of the stash list after stashing changes. stash_size_after=$(git stash list | wc -l) -echo "Stash size after: $stash_size_after" stashed=$(($stash_size_after - $stash_size_before)) # If the stash size has increased, it means a new stash entry was created. From ec7eb7cc97ad27e0de003a3ecae16babf61d8371 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Fri, 13 Feb 2026 10:23:42 +0100 Subject: [PATCH 09/28] Update comment --- scripts/pre-commit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 594f5bc5ff..4cbaffc350 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -66,8 +66,8 @@ exec 1>&2 # Get the size of the stash list before stashing any changes. This is used to determine later if a new stash entry was created for the pre-commit checks. stash_size_before=$(git stash list | wc -l) -# Stash any unstaged changes, including untracked files, to ensure that the pre-commit checks are performed on the exact state of the files being committed. -# The --keep-index option allows staged changes to remain intact, while --include-untracked ensures that untracked files are also stashed. +# Stash any unstaged changes, to ensure that the pre-commit checks are performed on the exact state of the files being committed. +# The --keep-index option allows staged changes to remain intact. # The --message option provides a description for the stash entry, making it easier to identify later. git stash push --keep-index --message "pre-commit-stash" From 767d4bd4d1ca2ffdca44c64b642b8a6d9fd63ccd Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 11:09:23 +0100 Subject: [PATCH 10/28] Also include untracked files to be stashed --- scripts/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 4cbaffc350..81657de030 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -69,7 +69,7 @@ stash_size_before=$(git stash list | wc -l) # Stash any unstaged changes, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact. # The --message option provides a description for the stash entry, making it easier to identify later. -git stash push --keep-index --message "pre-commit-stash" +git stash push --keep-index --include-untracked --message "pre-commit-stash" # Get the size of the stash list after stashing changes. stash_size_after=$(git stash list | wc -l) From b706d0d62a2797529bd2213dcd031d156f9afada Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 11:14:23 +0100 Subject: [PATCH 11/28] test --- scripts/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 81657de030..85b921835a 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -69,7 +69,7 @@ stash_size_before=$(git stash list | wc -l) # Stash any unstaged changes, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact. # The --message option provides a description for the stash entry, making it easier to identify later. -git stash push --keep-index --include-untracked --message "pre-commit-stash" +git stash push --keep-index --include-untracked --message "pre-commit-stash" # Get the size of the stash list after stashing changes. stash_size_after=$(git stash list | wc -l) From 2f9816a0eb633c0478af8ba5d57af397ac5cf366 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 11:23:57 +0100 Subject: [PATCH 12/28] Debug --- scripts/pre-commit | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 85b921835a..2e56b94563 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -69,7 +69,7 @@ stash_size_before=$(git stash list | wc -l) # Stash any unstaged changes, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact. # The --message option provides a description for the stash entry, making it easier to identify later. -git stash push --keep-index --include-untracked --message "pre-commit-stash" +git stash push --keep-index --include-untracked --message "pre-commit-stash" # Get the size of the stash list after stashing changes. stash_size_after=$(git stash list | wc -l) @@ -77,6 +77,7 @@ stash_size_after=$(git stash list | wc -l) stashed=$(($stash_size_after - $stash_size_before)) # If the stash size has increased, it means a new stash entry was created. if [ $stashed -gt 0 ]; then + git stash show --include-untracked -p printf '\033[31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes if you want to include them in the commit." fi From a27ce5dfcb7e40b4d69e6851b4b6b1bece54b8bc Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 11:25:48 +0100 Subject: [PATCH 13/28] debug --- scripts/pre-commit | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/pre-commit b/scripts/pre-commit index 2e56b94563..6acb7cd98b 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -65,6 +65,7 @@ exec 1>&2 # Get the size of the stash list before stashing any changes. This is used to determine later if a new stash entry was created for the pre-commit checks. stash_size_before=$(git stash list | wc -l) +echo "stash size before: $stash_size_before" # Stash any unstaged changes, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact. @@ -73,8 +74,10 @@ git stash push --keep-index --include-untracked --message "pre-commit-stash" # Get the size of the stash list after stashing changes. stash_size_after=$(git stash list | wc -l) +echo "stash size after: $stash_size_after" stashed=$(($stash_size_after - $stash_size_before)) +echo "stashed: $stashed" # If the stash size has increased, it means a new stash entry was created. if [ $stashed -gt 0 ]; then git stash show --include-untracked -p From 274702c2a2c37c887699bdbaa895280a5a3b3bce Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 11:36:58 +0100 Subject: [PATCH 14/28] Debug --- scripts/pre-commit | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 6acb7cd98b..bb9962e2af 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -70,7 +70,7 @@ echo "stash size before: $stash_size_before" # Stash any unstaged changes, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact. # The --message option provides a description for the stash entry, making it easier to identify later. -git stash push --keep-index --include-untracked --message "pre-commit-stash" +git stash push --keep-index --message "pre-commit-stash" # Get the size of the stash list after stashing changes. stash_size_after=$(git stash list | wc -l) @@ -80,6 +80,7 @@ stashed=$(($stash_size_after - $stash_size_before)) echo "stashed: $stashed" # If the stash size has increased, it means a new stash entry was created. if [ $stashed -gt 0 ]; then + echo "A stash entry was created for the pre-commit checks." git stash show --include-untracked -p printf '\033[31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes if you want to include them in the commit." fi From 05306be72c64e3834baa6b406030fa775d02ad85 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 11:38:53 +0100 Subject: [PATCH 15/28] Debug --- scripts/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index bb9962e2af..b986bbb526 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -70,7 +70,7 @@ echo "stash size before: $stash_size_before" # Stash any unstaged changes, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact. # The --message option provides a description for the stash entry, making it easier to identify later. -git stash push --keep-index --message "pre-commit-stash" +git stash push --keep-index --include-untracked --message "pre-commit-stash" # Get the size of the stash list after stashing changes. stash_size_after=$(git stash list | wc -l) From 196872c6c3d2aca55d44b58537ef55099b76a1ba Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 12:08:22 +0100 Subject: [PATCH 16/28] fix including staged stash From 7efb51507ffedd1ce47337ea81a0dd286897cbd2 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 12:09:06 +0100 Subject: [PATCH 17/28] fix staged changes From 8e872dfb0dc0759d4db4af8e58a1b761cf9030e2 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 12:10:09 +0100 Subject: [PATCH 18/28] Debug --- scripts/pre-commit | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index b986bbb526..6955fb2676 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -65,7 +65,6 @@ exec 1>&2 # Get the size of the stash list before stashing any changes. This is used to determine later if a new stash entry was created for the pre-commit checks. stash_size_before=$(git stash list | wc -l) -echo "stash size before: $stash_size_before" # Stash any unstaged changes, to ensure that the pre-commit checks are performed on the exact state of the files being committed. # The --keep-index option allows staged changes to remain intact. @@ -74,14 +73,10 @@ git stash push --keep-index --include-untracked --message "pre-commit-stash" # Get the size of the stash list after stashing changes. stash_size_after=$(git stash list | wc -l) -echo "stash size after: $stash_size_after" stashed=$(($stash_size_after - $stash_size_before)) -echo "stashed: $stashed" # If the stash size has increased, it means a new stash entry was created. if [ $stashed -gt 0 ]; then - echo "A stash entry was created for the pre-commit checks." - git stash show --include-untracked -p printf '\033[31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes if you want to include them in the commit." fi @@ -140,7 +135,6 @@ if [ $stashed -gt 0 ]; then git stash pop fi - # exit 1 if there was a nonindented file # this will abort the commit exit $nocontinue From cbcbeb3ff31f63473657783484a9be1831090368 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 13:05:54 +0100 Subject: [PATCH 19/28] Debug --- scripts/pre-commit | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/pre-commit b/scripts/pre-commit index 6955fb2676..f975f656bf 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -77,6 +77,10 @@ stash_size_after=$(git stash list | wc -l) stashed=$(($stash_size_after - $stash_size_before)) # If the stash size has increased, it means a new stash entry was created. if [ $stashed -gt 0 ]; then + echo "A stash entry was created for the pre-commit checks." + git stash show --include-untracked -p + echo "files: " + git stash show --name-only printf '\033[31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes if you want to include them in the commit." fi From 799f274068f92750b5f28e4315d028c8146a488e Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 13:22:21 +0100 Subject: [PATCH 20/28] debug --- scripts/pre-commit | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index f975f656bf..0d4619101b 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -63,28 +63,20 @@ fi # Redirect output to stderr. exec 1>&2 -# Get the size of the stash list before stashing any changes. This is used to determine later if a new stash entry was created for the pre-commit checks. -stash_size_before=$(git stash list | wc -l) +diff_size=$(git diff | wc -l) -# Stash any unstaged changes, to ensure that the pre-commit checks are performed on the exact state of the files being committed. -# The --keep-index option allows staged changes to remain intact. -# The --message option provides a description for the stash entry, making it easier to identify later. -git stash push --keep-index --include-untracked --message "pre-commit-stash" - -# Get the size of the stash list after stashing changes. -stash_size_after=$(git stash list | wc -l) - -stashed=$(($stash_size_after - $stash_size_before)) +pre_stash_size=$(git stash list | wc -l) +git stash push --keep-index --include-untracked --message "pre-commit-stash" +post_stash_size=$(git stash list | wc -l) +increased_stash_size=$((post_stash_size - pre_stash_size)) # If the stash size has increased, it means a new stash entry was created. -if [ $stashed -gt 0 ]; then - echo "A stash entry was created for the pre-commit checks." - git stash show --include-untracked -p - echo "files: " - git stash show --name-only +if [ $diff_size -gt 0 ]; then printf '\033[31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes if you want to include them in the commit." fi + nocontinue=0 + for file in `git diff --cached --name-only` do # only indent existing files, this is necessary since if we rename or delete @@ -134,8 +126,7 @@ do fi done -if [ $stashed -gt 0 ]; then - # If a stash was created, pop it to restore the working directory to its original state before the pre-commit checks were performed. +if [ $increased_stash_size -gt 0 ]; then git stash pop fi From 79cd5fd9f99ced218515f2a9040352484e06381d Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 13:22:52 +0100 Subject: [PATCH 21/28] remove space --- scripts/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 0d4619101b..f0f5b5ab90 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -66,7 +66,7 @@ exec 1>&2 diff_size=$(git diff | wc -l) pre_stash_size=$(git stash list | wc -l) -git stash push --keep-index --include-untracked --message "pre-commit-stash" +git stash push --keep-index --include-untracked --message "pre-commit-stash" post_stash_size=$(git stash list | wc -l) increased_stash_size=$((post_stash_size - pre_stash_size)) # If the stash size has increased, it means a new stash entry was created. From 1f37c6a0c5bc1e4b0f23f75ef8cd49a91154968f Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 13:24:19 +0100 Subject: [PATCH 22/28] Make it quiet --- scripts/pre-commit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index f0f5b5ab90..a35ca96673 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -66,7 +66,7 @@ exec 1>&2 diff_size=$(git diff | wc -l) pre_stash_size=$(git stash list | wc -l) -git stash push --keep-index --include-untracked --message "pre-commit-stash" +git stash push --quiet --keep-index --include-untracked --message "pre-commit-stash" post_stash_size=$(git stash list | wc -l) increased_stash_size=$((post_stash_size - pre_stash_size)) # If the stash size has increased, it means a new stash entry was created. @@ -127,7 +127,7 @@ do done if [ $increased_stash_size -gt 0 ]; then - git stash pop + git stash pop --quiet fi # exit 1 if there was a nonindented file From 33f6d108ddbffefe5e1f9834f281d093f7551068 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 13:24:48 +0100 Subject: [PATCH 23/28] remove space --- scripts/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index a35ca96673..4cce4aded2 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -66,7 +66,7 @@ exec 1>&2 diff_size=$(git diff | wc -l) pre_stash_size=$(git stash list | wc -l) -git stash push --quiet --keep-index --include-untracked --message "pre-commit-stash" +git stash push --quiet --keep-index --include-untracked --message "pre-commit-stash" post_stash_size=$(git stash list | wc -l) increased_stash_size=$((post_stash_size - pre_stash_size)) # If the stash size has increased, it means a new stash entry was created. From 7bbc64092b8844b160f63828cf9cf1417c3d9322 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 13:38:25 +0100 Subject: [PATCH 24/28] debug --- scripts/pre-commit | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 4cce4aded2..defb6170d5 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -69,10 +69,11 @@ pre_stash_size=$(git stash list | wc -l) git stash push --quiet --keep-index --include-untracked --message "pre-commit-stash" post_stash_size=$(git stash list | wc -l) increased_stash_size=$((post_stash_size - pre_stash_size)) -# If the stash size has increased, it means a new stash entry was created. -if [ $diff_size -gt 0 ]; then - printf '\033[31m%s\033[0m\n' "Unstaged changes have been stashed. They will be popped after the pre-commit checks. Add the changes if you want to include them in the commit." +if [ $increased_stash_size -gt 0 ]; then + echo "Stashed uncommitted changes to ensure a clean working directory for the pre-commit checks." fi +# If the stash size has increased, it means a new stash entry was created. + nocontinue=0 @@ -130,6 +131,10 @@ if [ $increased_stash_size -gt 0 ]; then git stash pop --quiet fi +if [ $nocontinue -ne 0 ]; then + printf '\033[38;5;208m%s\033[0m\n' "Pre-commit found errors. Did you add the latest changes?" +fi + # exit 1 if there was a nonindented file # this will abort the commit exit $nocontinue From c48df079ddb1702abfcf34e3ace40e295a1119e0 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 13:39:05 +0100 Subject: [PATCH 25/28] Debug hello --- scripts/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index defb6170d5..5e941a1d98 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -74,7 +74,7 @@ if [ $increased_stash_size -gt 0 ]; then fi # If the stash size has increased, it means a new stash entry was created. - +echo "Hello from pre-commit" nocontinue=0 From 616d6090b689cdfde6f3fa3569b24f0faff74978 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 13:39:30 +0100 Subject: [PATCH 26/28] remove debug output --- scripts/pre-commit | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 5e941a1d98..81faa206ed 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -74,8 +74,6 @@ if [ $increased_stash_size -gt 0 ]; then fi # If the stash size has increased, it means a new stash entry was created. -echo "Hello from pre-commit" - nocontinue=0 for file in `git diff --cached --name-only` From a0c5bb8cc609ab9e524443af65b1a127666897e5 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 13:47:17 +0100 Subject: [PATCH 27/28] debug --- scripts/pre-commit | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 81faa206ed..e56a38e0bf 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -71,6 +71,7 @@ post_stash_size=$(git stash list | wc -l) increased_stash_size=$((post_stash_size - pre_stash_size)) if [ $increased_stash_size -gt 0 ]; then echo "Stashed uncommitted changes to ensure a clean working directory for the pre-commit checks." + git stash show -p fi # If the stash size has increased, it means a new stash entry was created. @@ -126,7 +127,7 @@ do done if [ $increased_stash_size -gt 0 ]; then - git stash pop --quiet + git stash pop --quiet --index fi if [ $nocontinue -ne 0 ]; then From a993b06ab56b336072a32c9ccc9c2cdde91cdc3f Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 17 Feb 2026 13:48:20 +0100 Subject: [PATCH 28/28] Remove debug output --- scripts/pre-commit | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index e56a38e0bf..19b160f9d9 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -69,10 +69,7 @@ pre_stash_size=$(git stash list | wc -l) git stash push --quiet --keep-index --include-untracked --message "pre-commit-stash" post_stash_size=$(git stash list | wc -l) increased_stash_size=$((post_stash_size - pre_stash_size)) -if [ $increased_stash_size -gt 0 ]; then - echo "Stashed uncommitted changes to ensure a clean working directory for the pre-commit checks." - git stash show -p -fi + # If the stash size has increased, it means a new stash entry was created. nocontinue=0