Skip to content

Slim down kw-pre-commit: drop dead code, delegate to standard hooks - #2641

Merged
blowekamp merged 3 commits into
SimpleITK:mainfrom
blowekamp:fix/kw-pre-commit-submodule-check
Jul 20, 2026
Merged

blowekamp merged 3 commits into
SimpleITK:mainfrom
blowekamp:fix/kw-pre-commit-submodule-check

Conversation

@blowekamp

Copy link
Copy Markdown
Member

Clean up Utilities/Hooks/kw-pre-commit by removing logic that is either
dead or now duplicated by standard pre-commit-hooks, and by extracting
the remaining custom file-size check into its own Python hook.

Changes

  • Remove the broken submodule/merge-rewind check — it called an
    undefined check_module_rewind function and is redundant now that
    forbid-submodules is enabled.
  • Remove the executable/shebang mode check (check_mode,
    mode_looks_exe, mode_not_exe, mode_bad_exe, mode_non_file) —
    superseded by the standard check-shebang-scripts-are-executable
    (already enabled) and newly-added check-executables-have-shebangs
    hooks. This also drops a bug where the catch-all branch mis-flagged
    newly added symlinks as an invalid file mode.
  • Extract the file-size check into Utilities/Hooks/check-file-size.py,
    registered as its own local check-file-size hook (language: python).
    Behavior is preserved: per-path overrides via hooks-max-size/
    hooks.MaxObjectKiB git attributes, falling back to the
    hooks.max-size/hooks.MaxObjectKiB git config defaults. There's no
    standard-hook equivalent since check-added-large-files has no
    per-path attribute-driven override mechanism.

Remaining in kw-pre-commit

Committer-identity validation, non-ascii filename rejection, and the
.gitattributes-driven whitespace checks (tab-in-indent,
no-lf-at-eof) — none of these have standard pre-commit-hooks
equivalents.

@blowekamp
blowekamp force-pushed the fix/kw-pre-commit-submodule-check branch from b2085d2 to 9bbe3a7 Compare July 20, 2026 13:22
The "Merge checks" section called check_module_rewind, a function
that is never defined anywhere in this script (it was dropped when
Gerrit/hook-chaining support was removed), so this branch would fail
with "command not found" if it ever executed on a merge commit
touching a submodule.

It's also moot for this repository: the forbid-submodules hook in
.pre-commit-config.yaml already rejects submodules entirely, so no
commit can ever reach a state where a gitlink (160000) diff entry
exists for this dead code to act on.

Also drops the merge_head variable, which was only used to feed this
now-removed section.
Remove the check_mode/mode_looks_exe/mode_not_exe/mode_bad_exe/mode_non_file
functions from kw-pre-commit. This logic is superseded by the standard
check-shebang-scripts-are-executable (already enabled) and the newly added
check-executables-have-shebangs pre-commit-hooks, which cover the same
executable-bit/shebang mismatch cases using git's own index mode and
identify's content-based type detection, without kw-pre-commit's catch-all
branch that incorrectly flagged newly added symlinks as invalid file modes.

The ghostflow-check-main action enforces Windows batch files to be
marked as executable. This requires exclusion of the bat extension.

WIP: message or fix iup
Move the check_size/size_too_large/size_validate_* logic out of
kw-pre-commit into Utilities/Hooks/check-file-size.py, registered as its
own local pre-commit hook (check-file-size, language: python). Behavior
is preserved exactly: per-path overrides via git attribute file entries
for hooks-max-size/hooks.MaxObjectKiB, falling back to the
hooks.max-size/hooks.MaxObjectKiB git config defaults (1024 KiB).

This has no standard pre-commit-hooks equivalent, since check-added-large-files
has no mechanism for per-path attribute-driven size overrides, so the
custom logic is kept but isolated from the rest of kw-pre-commit's
now-shrinking bash script.
@blowekamp
blowekamp force-pushed the fix/kw-pre-commit-submodule-check branch from 9bbe3a7 to d97d41b Compare July 20, 2026 14:21
@blowekamp
blowekamp marked this pull request as ready for review July 20, 2026 19:40
@blowekamp
blowekamp requested review from dave3d and zivy July 20, 2026 19:41
@blowekamp
blowekamp merged commit 9effe46 into SimpleITK:main Jul 20, 2026
10 checks passed
@blowekamp
blowekamp deleted the fix/kw-pre-commit-submodule-check branch September 9, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants