Commit graph

15 commits

Author SHA1 Message Date
Julian Prein d9fd71fa2a hooks--pre-commit: detect non-ASCII when renaming
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-12-03 11:55:40 +09:00
Lucius Hu 81e3db42f3 templates: fix deprecated type option --bool
The `--bool` option to `git-config` is marked as historical, and users are
recommended to use `--type=bool` instead. This commit replaces all occurrences
of `--bool` in the templates.

Also note that, no other deprecated type options are found, including `--int`,
`--bool-or-int`, `--path`, or `--expiry-date`.

Signed-off-by: Lucius Hu <orctarorga@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-01-21 14:11:20 -08:00
brian m. carlson 03a7f388da Update shell scripts to compute empty tree object ID
Several of our shell scripts hard-code the object ID of the empty tree.
To avoid any problems when changing hashes, compute this value on
startup of the script.  For performance, store the value in a variable
and reuse it throughout the life of the script.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-05-02 13:59:53 +09:00
Johan Herland af1748b31e sample pre-commit hook: use --bool when retrieving config var
Currently if you set

	[hooks]
		allowNonAscii

(or allownonascii = 1, or = yes) in your .git/config then the sample
pre-commit misinterprets the value as "false" and rejects non-ASCII
filenames.  Use "git config --bool" to get the usual nicer boolean
handling.

Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2013-09-24 12:26:49 -07:00
Richard Hartmann 7b3742fa46 templates: spell ASCII in uppercase in pre-commit hook
The name of the encoding is ASCII, not ascii.

Signed-off-by: Richard Hartmann <richih.mailinglist@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-15 09:52:57 -07:00
Richard Hartmann b1d5a570fc templates: Reformat pre-commit hook's message
Now that we're using heredoc, the message can span the full 80 chars.

Signed-off-by: Richard Hartmann <richih.mailinglist@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-15 09:52:52 -07:00
Richard Hartmann 27b6e17a6d templates: Use heredoc in pre-commit hook
This way, it is easier to see how the text we give the end users
would look like, and it will allow us to use (near) full width
of the source file.

Signed-off-by: Richard Hartmann <richih.mailinglist@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-15 09:51:16 -07:00
Jim Meyering c14daa4845 make the sample pre-commit hook script reject names with newlines, too
The sample pre-commit hook script would fail to reject a file name like
"a\nb" because of the way newlines are handled in "$(...)".  Adjust the
test to count filtered bytes and require there be 0.  Also print all
diagnostics to standard error, not stdout, so they will actually be seen.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-26 14:31:14 -07:00
Ben Walton 100e762a60 Modernize git calling conventions in hook templates
The hook templates were still using/referencing 'git-foo' instead of
'git foo.'  This patch updates the sample hooks to use the modern
conventions instead.

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-03-20 09:04:38 -07:00
Björn Steinbrink c30eb852e2 pre-commit.sample: Diff against the empty tree when HEAD is invalid
This was already the case for the old "diff --check" call, but the new
one that checks whether there are any non-ascii file names was missing
it, making that check fail for root commits.

Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-11-06 23:48:09 -08:00
Jim Meyering f1e3156e62 pre-commit.sample: add comment re tr portability; fix grammar
Add a comment explaining why square brackets around a tr range
are not only ok, but actually required in this case.
Correct spelling and grammar.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-09-22 12:15:42 -07:00
Heiko Voigt d00e364de9 Extend sample pre-commit hook to check for non ascii filenames
At the moment non-ascii encodings of filenames are not portably
converted between different filesystems by git. This will most likely
change in the future but to allow repositories to be portable among
different file/operating systems this check is enabled by default.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-05-20 00:04:37 -07:00
Jim Meyering c646217e13 pre-commit.sample: don't print incidental SHA1
Make the sample pre-commit hook script discard
all git-rev-parse output, not just stderr.
Otherwise, it would print an SHA1.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-05-16 11:57:17 -07:00
Junio C Hamano 03e2b630f0 Update sample pre-commit hook to use "diff --check"
Now "diff --check" can detect not just whitespace errors but also notices
leftover conflict marker lines, we can use it in the sample pre-commit
hook script.

These days the object layer knows about the empty tree object without
actually having one in the repository, so we can run the test even for the
initial commit.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-06-26 22:08:25 -07:00
Junio C Hamano f98f8cbac0 Ship sample hooks with .sample suffix
We used to mark hooks we ship as samples by making them unexecutable, but
some filesystems cannot tell what is executable and what is not.

This makes it much more explicit.  The hooks are suffixed with .sample
(but now are made executable), so enabling it is still one step operation
(instead of "chmod +x $hook", you would do "mv $hook.sample $hook") but
now they won't get accidentally enabled on systems without executable bit.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-06-24 19:06:22 -07:00
Renamed from templates/hooks--pre-commit (Browse further)