* [PATCH] hooks--pre-commit: detect non-ASCII when renaming
@ 2022-07-14 22:17 Julian Prein via GitGitGadget
2022-07-14 23:03 ` Junio C Hamano
2023-11-30 16:13 ` [PATCH v2] " Julian Prein via GitGitGadget
0 siblings, 2 replies; 5+ messages in thread
From: Julian Prein via GitGitGadget @ 2022-07-14 22:17 UTC (permalink / raw
To: git; +Cc: Julian Prein, Julian Prein
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] hooks--pre-commit: detect non-ASCII when renaming
2022-07-14 22:17 [PATCH] hooks--pre-commit: detect non-ASCII when renaming Julian Prein via GitGitGadget
@ 2022-07-14 23:03 ` Junio C Hamano
2022-07-14 23:08 ` Junio C Hamano
2023-11-30 16:13 ` [PATCH v2] " Julian Prein via GitGitGadget
1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2022-07-14 23:03 UTC (permalink / raw
To: Julian Prein via GitGitGadget; +Cc: git, Julian Prein
"Julian Prein via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 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.
It would probably be a better implementation to disable the rename
detection, instead of adding Copies and Renames.
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hooks--pre-commit: detect non-ASCII when renaming
2022-07-14 23:03 ` Junio C Hamano
@ 2022-07-14 23:08 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2022-07-14 23:08 UTC (permalink / raw
To: Julian Prein via GitGitGadget; +Cc: git, Julian Prein
Junio C Hamano <gitster@pobox.com> writes:
> "Julian Prein via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> 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.
>
> It would probably be a better implementation to disable the rename
> detection, instead of adding Copies and Renames.
That is ...
>> - test $(git diff --cached --name-only --diff-filter=A -z $against |
... instead of using the "git diff" Porcelain, we can probably use
the "git diff-index" plumbing command here, which will not be
affected by end-user configuration or by the fact that recent "git
diff" turns on the rename detection by default.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] hooks--pre-commit: detect non-ASCII when renaming
2022-07-14 22:17 [PATCH] hooks--pre-commit: detect non-ASCII when renaming Julian Prein via GitGitGadget
2022-07-14 23:03 ` Junio C Hamano
@ 2023-11-30 16:13 ` Julian Prein via GitGitGadget
2023-12-03 13:15 ` Junio C Hamano
1 sibling, 1 reply; 5+ messages in thread
From: Julian Prein via GitGitGadget @ 2023-11-30 16:13 UTC (permalink / raw
To: git; +Cc: Julian Prein, Julian Prein
From: Julian Prein <druckdev@protonmail.com>
When diff.renames is turned on, the diff-filter will not return renamed
files (or copied ones with diff.renames=copy) and potential non-ASCII
characters would not be caught by this hook.
Use the plumbing command diff-index instead of the porcelain one to not
be affected by diff.rename.
Signed-off-by: Julian Prein <druckdev@protonmail.com>
---
hooks--pre-commit: detect non-ASCII when renaming
A bit later than I expected, but here is v2.
Changes since v1:
* Switched to using diff-index and back to just the A filter as
suggested by Junio C Hamano
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1291%2Fdruckdev%2Fpre-commit-renames-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1291/druckdev/pre-commit-renames-v2
Pull-Request: https://github.com/git/git/pull/1291
Range-diff vs v1:
1: 101f327a040 ! 1: 1f6ca0dd3eb hooks--pre-commit: detect non-ASCII when renaming
@@ Metadata
## Commit message ##
hooks--pre-commit: detect non-ASCII when renaming
- Currently the diff-filter that is used to check for non-ASCII characters
- in filenames only checks new additions.
+ When diff.renames is turned on, the diff-filter will not return renamed
+ files (or copied ones with diff.renames=copy) and potential non-ASCII
+ characters would not be caught by this hook.
- 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.
+ Use the plumbing command diff-index instead of the porcelain one to not
+ be affected by diff.rename.
Signed-off-by: Julian Prein <druckdev@protonmail.com>
@@ templates/hooks--pre-commit.sample: if [ "$allownonascii" != "true" ] &&
# 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 |
++ test $(git diff-index --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
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..29ed5ee486a 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-index --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
base-commit: 61a22ddaf0626111193a17ac12f366bd6d167dff
--
gitgitgadget
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] hooks--pre-commit: detect non-ASCII when renaming
2023-11-30 16:13 ` [PATCH v2] " Julian Prein via GitGitGadget
@ 2023-12-03 13:15 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2023-12-03 13:15 UTC (permalink / raw
To: Julian Prein via GitGitGadget; +Cc: git, Julian Prein
"Julian Prein via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Julian Prein <druckdev@protonmail.com>
>
> When diff.renames is turned on, the diff-filter will not return renamed
> files (or copied ones with diff.renames=copy) and potential non-ASCII
> characters would not be caught by this hook.
>
> Use the plumbing command diff-index instead of the porcelain one to not
> be affected by diff.rename.
Makes sense.
An obvious alternative would be to pass "--no-renames" and keep
using the Porcelain "git diff", but this is how the plumbing
"diff-index" and friends are meant to be used. Looking good.
Will queue. Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-12-03 13:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-14 22:17 [PATCH] hooks--pre-commit: detect non-ASCII when renaming Julian Prein via GitGitGadget
2022-07-14 23:03 ` Junio C Hamano
2022-07-14 23:08 ` Junio C Hamano
2023-11-30 16:13 ` [PATCH v2] " Julian Prein via GitGitGadget
2023-12-03 13:15 ` Junio C Hamano
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).