buf: buf breaking in pre-commit will set core.bare to 'true' and failed

GitHub repository with your minimal reproducible example (do not leave this field blank or fill out this field with “github.com/bufbuild/buf” or we will automatically close your issue, see the instructions above!)

No response

What’s up?

When I run pre-commit run --all-files or buf breaking --against "ssh://git@github.com/provistaai/protobuf.git#branch=main", It’s all right. But when I run git commit, It will auto set core.bare to ‘true’ and failed.

Image

It’s a submodule and my .pre-commit-config.yaml is:

repos:
  - repo: local
    hooks:
      - id: buf-format
        name: Format Protobuf Files
        entry: buf format -w
        language: system
        files: \.proto$
        pass_filenames: false

      - id: buf-breaking
        name: Check Protobuf Breaking Changes
        entry: buf breaking --against "ssh://git@github.com/provistaai/protobuf.git#branch=main"
        language: system
        files: \.proto$
        pass_filenames: false

Is that a bug? What should I do? Thx a lot

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

I’ve managed to create a repro of this issue, going to continue to investigate.

EDIT: I was able to create a commit with the fix I just opened a PR for, once we get that reviewed, merged, and released, hopefully this will help. Thanks!

I try it in linux but the result is the same:

[ec2-user@ip-172-31-2-152 protos]$ git commit -m "test"
Format Protobuf Files....................................................Passed
Check Protobuf Breaking Changes..........................................Failed
- hook id: buf-breaking
- files were modified by this hook
[ec2-user@ip-172-31-2-152 protos]$ pre-commit
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /home/ec2-user/.cache/pre-commit/patch1746067313-31198.
Format Protobuf Files................................(no files to check)Skipped
Check Protobuf Breaking Changes......................(no files to check)Skipped
[INFO] Restored changes from /home/ec2-user/.cache/pre-commit/patch1746067313-31198.
[ec2-user@ip-172-31-2-152 protos]$ buf --version
1.53.0

@doriable I removed the repository and made a clean clone. But the result is the same.

The steps I took:

Step 1: git clone git@github.com:Wu-Jiayang/test-a.git and cd test-a

Step 2: git submodule update --init --recursive and cd app/protos

Step 3:

PS D:\py\test-a\app\protos> pre-commit install
pre-commit installed at D:\py\test-a\.git\modules\app\protos\hooks\pre-commit

Step 4: add // test in the end of content.proto

Step 5:

PS D:\py\test-a\app\protos> git add .                         
PS D:\py\test-a\app\protos> git commit -m "test pre-commit"
Format Protobuf Files....................................................Passed
Check Protobuf Breaking Changes..........................................Failed
- hook id: buf-breaking
- files were modified by this hook
PS D:\py\test-a\app\protos> pre-commit    
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\Wu Jiayang\.cache\pre-commit\patch1746065237-12056.
Format Protobuf Files................................(no files to check)Skipped
Check Protobuf Breaking Changes......................(no files to check)Skipped
[INFO] Restored changes from C:\Users\Wu Jiayang\.cache\pre-commit\patch1746065237-12056.

The .git/modules/app/protos/config is:

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
	worktree = ../../../../app/protos
[remote "origin"]
	url = https://github.com/Wu-Jiayang/test-b.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
	remote = origin
	merge = refs/heads/main

The issue is that the environment from the pre-commit in the submodule is passed to the buf command. This env contains the git variable GIT_DIR which currently breaks buf breaking. We have a fix to remove this in #3760. As a workaround for now you may be able to unset this variable before invoking buf breaking.

The root cause has been identified, we are working on resolving. This is currently an issue specific to submodules with repository-local hooks, I will keep this issue updated when a fix becomes available. Thanks!

Thank you for the detailed instructions, I followed them but was unable to reproduce the exact symptoms. Here are the steps I took:

~/src/playground/buf-3752/test-a/app/protos @ $ git status
HEAD detached at c3c115e
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   foo.proto

~/src/playground/buf-3752/test-a/app/protos @ $ git commit -m "test"
[detached HEAD b8ee546] test
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 foo.proto

If I do a reset and run pre-commit to test, I get the following:

~/src/playground/buf-3752/test-a/app/protos @ $ pre-commit
Format Protobuf Files....................................................Passed
Check Protobuf Breaking Changes..........................................Failed
- hook id: buf-breaking
- exit code: 1

Failure: could not clone ssh://git@github.com:Wu-Jiayang/test-b.git: exit status 128
ssh: Could not resolve hostname github.com:Wu-Jiayang: nodename nor servname provided, or not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Which is fine, I adjusted the .pre-commit-config.yaml to use https instead:

~/src/playground/buf-3752/test-a/app/protos @ $ git diff
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 2a898da..422bcbb 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -10,7 +10,7 @@ repos:

       - id: buf-breaking
         name: Check Protobuf Breaking Changes
-        entry: buf breaking --against "ssh://git@github.com:Wu-Jiayang/test-b.git#branch=main"
+        entry: buf breaking --against "https://github.com/Wu-Jiayang/test-b.git#branch=main"
         language: system
         files: \.proto$
         pass_filenames: false

Then I get:

~/src/playground/buf-3752/test-a/app/protos @ $ pre-commit
Format Protobuf Files....................................................Passed
Check Protobuf Breaking Changes..........................................Failed
- hook id: buf-breaking
- exit code: 1

Failure: Module "path: "."" had no .proto files

Which is expected, since the --against target would have no proto files. But this is not the git failure that you’re experiencing. I did note that you are on Windows, so I also checked on a Windows machine. I also had to adjust the pre-commit hook to use https, and got valid failures:

C:\Users\lokop\src\buf-3752\test-a\app\protos [(c3c115e...) +1 ~0 -0 | +0 ~1 -0 !]> git add .
C:\Users\lokop\src\buf-3752\test-a\app\protos [(c3c115e...) +1 ~1 -0 ~]> pre-commit
Format Protobuf Files....................................................Failed
- hook id: buf-format
- exit code: 1

Failure: exec: "diff": executable file not found in %PATH%

Check Protobuf Breaking Changes..........................................Failed
- hook id: buf-breaking
- exit code: 1

Failure: "." had no .proto files

On Windows, I am running:

C:\Users\lokop\src\buf-3752\test-a\app\protos [(c3c115e...) +1 ~1 -0 ~]> git --version
git version 2.34.1.windows.1
C:\Users\lokop\src\buf-3752\test-a\app\protos [(c3c115e...) +1 ~1 -0 ~]> pre-commit --version
pre-commit 4.2.0

and on Mac, I am running:


~/src/playground/buf-3752/test-a/app/protos @ $ git --version
git version 2.45.2
~/src/playground/buf-3752/test-a/app/protos @ $ pre-commit --version
pre-commit 4.2.0

My pre-commit version is 4.2.0. Wu-Jiayang/test-a and Wu-Jiayang/test-b are public repos. You can visit them.

I have tried 1.52.1 and 1.47.0. Unfortunately, they both have the same problem. I will try to reproduce it on a new GitHub repository.