8000 Pre-commit installation fails · Issue #78 · hashicorp/copywrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Pre-commit installation fails #78

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

Open
sgabenov opened this issue Jul 11, 2023 · 5 comments · May be fixed by #120
Open

Pre-commit installation fails #78

sgabenov opened this issue Jul 11, 2023 · 5 comments · May be fixed by #120
Assignees
Labels
bug Something isn't working

Comments

@sgabenov
Copy link
sgabenov commented Jul 11, 2023

It seems like, if i use this tool with pre-commit, it tries to search Go files not in pre-commit .cache directory, but from root path of the repo. Could you please check with some empty git repo to use this pre-commit configuration to get same errors.

After creating .pre-commit-config.yaml and commiting files \ executing pre-commit run

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

have such error:

Add copyright headers....................................................Failed
- hook id: add-headers
- exit code: 1
go: cannot find main module, but found .git/config in /Users/gabenov/git/sandbox/pre-commit
	to create a module there, run:
	go mod init

or after executing go mod init pre-commit

Validate copyright headers...............................................Failed
- hook id: check-headers
- exit code: 1
no Go files in /Users/gabenov/git/sandbox/pre-commit

version: pre-commit 3.3.2

@bloudraak
Copy link

Getting the same error. I do have Go installed, but I'm using it in .NET project (with some Terraform).

I installed the tool using homebrew, so I was expecting the pre-commit-hooks to run the installed binary instead of doing go run.

@CalebAlbers
Copy link
Member

Hey folks!

Before I jump into troubleshooting, it sounds like there may be some ergonomics issues with using the Golang-mechanism for installation. To make things more idiomatic with how you would expect pre-commit hooks to work, would it be preferable to have the hook install the binary from GitHub releases or expect it to already be in the user's $PATH?

@CalebAlbers CalebAlbers self-assigned this Jul 23, 2023
@CalebAlbers CalebAlbers added the bug Something isn't working label Jul 23, 2023
@bloudraak
Copy link

I expected it to use the copy I installed. That being said, it would be preferable if the hook installed the binary, so it can work on any supported platform, including Windows (which some teammates use).

@sgabenov
Copy link
Author
sgabenov commented Aug 9, 2023

I think, that pre-hook should not install golang itself. The better is to distribute 'copywrite' as a prebuild binary, as it said, it could be executed on each platform.

@bhundven
Copy link
bhundven commented Feb 2, 2025

on v0.20.0, using any of the 4 hooks:

- id: add-headers
- id: check-headers
- id: add-license
- id: check-license

I get:

Validate copyright headers...............................................Failed
- hook id: check-headers
- exit code: 1

This binary is a plugin. These are not meant to be executed directly.
Please execute the program that consumes these plugins, which will
load any plugins automatically
exit status 1
repos:
...
  - repo: https://github.com/hashicorp/copywrite
    rev: v0.20.0
    hooks:
      - id: add-headers
      - id: check-headers
      - id: add-license
      - id: check-license
...

bhundven added a commit to bhundven/copywrite that referenced this issue Feb 22, 2025
If you use copywrite in your repo, you probably already have copywrite
installed.

The hooks running `go run .` doesn't work in my terraform provider,
because it is a plugin:

```
This binary is a plugin. These are not meant to be executed directly.
Please execute the program that consumes these plugins, which will
load any plugins automatically
exit status 1
```

So switch the entry point to be the copywrite program.
Don't pass filenames. copywrite knows what to do.

Pass arguments directly on the entry.

Closes hashicorp#78

Signed-off-by: Bryan Hundven <bryanhundven@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0