git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] hooks--pre-commit: detect non-ASCII when renaming

From
Julian Prein via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 14, 2022, 22:17 UTC
Message-ID
<pull.1291.git.git.1657837073372.gitgitgadget@gmail.com>
From: Julian Prein <druckdev@protonmail.com>

Currently the diff-filter that is used to check for non-ASCII characters in filenames only checks new additions.

Extend the diff-filter in the pre-commit sample to include `CR` as well. This way non-ASCII character in filenames are detected on a rename/copy as well.

Signed-off-by: Julian Prein <druckdev@protonmail.com>
---
    hooks--pre-commit: detect non-ASCII when renaming
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1291%2Fdruckdev%2Fpre-commit-renames-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1291/druckdev/pre-commit-renames-v1
Pull-Request: https://github.com/git/git/pull/1291
 templates/hooks--pre-commit.sample | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample
index e144712c85c..95c327832da 100755
--- a/templates/hooks--pre-commit.sample
+++ b/templates/hooks--pre-commit.sample
@@ -28,7 +28,7 @@ if [ "$allownonascii" != "true" ] &&
 	# Note that the use of brackets around a tr range is ok here, (it's
 	# even required, for portability to Solaris 10's /usr/bin/tr), since
 	# the square bracket bytes happen to fall in the designated range.
-	test $(git diff --cached --name-only --diff-filter=A -z $against |
+	test $(git diff --cached --name-only --diff-filter=ACR -z $against |
 	  LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
 then
 	cat <<\EOF

base-commit: bbea4dcf42b28eb7ce64a6306cdde875ae5d09ca
-- 
gitgitgadget
Next: Junio C Hamano
Message 1 of 5 in “hooks--pre-commit: detect non-ASCII when renaming”
  1. hooks--pre-commit: detect non-ASCII when renamingJulian Prein via GitGitGadget, Jul 14, 2022
  2. Junio C HamanoJul 14, 2022
  3. Junio C HamanoJul 14, 2022
  4. hooks--pre-commit: detect non-ASCII when renamingJulian Prein via GitGitGadget, Nov 30, 2023
  5. Junio C HamanoDec 3, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.