Skip to content

Hook takes minutes and may fail without a valid reason on medium/big codebases #211

@danielelotito

Description

@danielelotito

Describe the bug
The add-headers pre-commit hook from hashicorp/copywrite is exhibiting significant performance issues and occasional failures. On my development machine, the hook takes between 1.5 and 3.2 minutes to complete (on a rather big repo, https://github.com/IBM/ado), which slows down the commit process considerably.

Additionally, the hook sometimes fails when it should have passed.

To Reproduce
Steps to (try to) reproduce the behavior:

Clone the repository where the issue is observed: git clone https://github.com/IBM/ado

Follow the project's development setup instructions: Project Setup Guide

Stage some files and attempt to commit the changes: git commit

Expected behavior
I expect the add-headers hook to run quickly (ideally in a few seconds) and to only modify files when copyright headers are genuinely missing or incorrect. It should not fail a commit when the headers are already compliant.

Screenshots / Log Files
Here is an example of the output when the hook fails without a legitimate reason:

git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
Detect secrets...........................................................Passed
ruff (legacy alias)..................................(no files to check)Skipped
black-jupyter........................................(no files to check)Skipped
codespell................................................................Passed
uv-lock..............................................(no files to check)Skipped
uv-export............................................(no files to check)Skipped
Add copyright headers....................................................Failed
- hook id: add-headers
- files were modified by this hook
Using license identifier: MIT
Using copyright holder: IBM Corporation
[1mExempting the following search patterns:\[0m
\[36m.cra/\*\*\[0m
\[36m.eggs/\*\*\[0m
\[36m.git/\*\*\[0m
\[36m.github/\*\*\[0m
\[36m.idea/\*\*\[0m
\[36m.pre-commit-config.yaml\[0m
\[36m.tox/\*\*\[0m
\[36m.venv/\*\*\[0m
\[36m.vscode/\*\*\[0m
\[36m\*\*build/lib/\*\*\[0m
\[36mdist/\*\*\[0m
\[36mtoxenv/\*\*\[0m
\[1mUpdating existing copyright headers:\[0m
\[1mAdding missing copyright headers:\[0m
markdownlint-cli2........................................................Passed
yamlfmt..............................................(no files to check)Skipped
tombi-format.........................................(no files to check)Skipped

env

OS: macOS

Python Version: 3.12 (failed with 3.10.7 as well)

copywrite version: v0.25.1

  - repo: https://github.com/hashicorp/copywrite
    rev: v0.25.1
    hooks:
      - id: add-headers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions