Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert-license tries to add license to the file specified as --license-filepath #102

Open
maruel opened this issue Nov 4, 2024 · 1 comment

Comments

@maruel
Copy link

maruel commented Nov 4, 2024

Repro

$ cat .github/LICENSE
Copyright 2024 Marc-Antoine Ruel. All rights reserved.
Use of this source code is governed under the Apache License, Version 2.0
that can be found in the LICENSE file.

$ cat .pre-commit-config.yaml
# Copyright 2024 Marc-Antoine Ruel. All rights reserved. 
# Use of this source code is governed under the Apache License, Version 2.0 
# that can be found in the LICENSE file. 
 
repos: 
- repo: https://github.com/Lucas-C/pre-commit-hooks 
  rev: v1.5.5 
  hooks: 
  - id: insert-license 
    name: "Insert license header in C++ source files" 
    args: ["--license-filepath=.github/LICENSE"] 

Expected

Hook insert-license doesn't touch the file specified as --license-filepath

Actual

Hook insert-license inserts the license (duplicate) to the file specified as --license-filepath, breaking the license check.

$ pre-commit
Insert license header in C++ source files................................Failed
- hook id: insert-license
- exit code: 1
- files were modified by this hook

Some sources were modified by the hook ['.github/LICENSE']
Now aborting the commit.
You should check the changes made. Then simply "git add --update ." and re-commit

$ git diff
diff --git .github/LICENSE .github/LICENSE
index cb92896..ba4255b 100644
--- .github/LICENSE
+++ .github/LICENSE
@@ -1,3 +1,7 @@
+# Copyright 2024 Marc-Antoine Ruel. All rights reserved.
+# Use of this source code is governed under the Apache License, Version 2.0
+# that can be found in the LICENSE file.
+
 Copyright 2024 Marc-Antoine Ruel. All rights reserved.
 Use of this source code is governed under the Apache License, Version 2.0
 that can be found in the LICENSE file.
@maruel
Copy link
Author

maruel commented Nov 4, 2024

Workaround:

rm .git/hooks/pre-commit
git commit -a -m "Add license check"
pre-commit install

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

No branches or pull requests

1 participant