Skip to content

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

@maruel

Description

@maruel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions