Git LFS hooks are recreated server-side when the repository has custom hooks #13444

Closed
opened 2025-11-02 10:42:33 -06:00 by GiteaMirror · 9 comments
Owner

Originally created by @na-Itms on GitHub (Sep 3, 2024).

Description

This issue is similar to #19810 and #23765.

Whenever I try to create a PR from a branch on the same repository ("merge into repo:main / pull from repo:branch"), I receive the infamous error batch request: missing protocol: "".

The error is caused by Git LFS hooks getting installed on the repo server-side. Deleting them temporarily fixes the error and allows me to create the PR.

I noticed after a while that the issue arises as soon as the repo of the origin branch contains custom hooks (in our case, under update.d. Other repos do not face the issue.

Additionally, as soon as the PR is created (from a branch suffering from the problem), the LFS hooks get recreated.

Gitea Version

1.22.1

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.43.5

Operating System

AlmaLinux 9

How are you running Gitea?

Install from binary, run with systemd

Database

MySQL/MariaDB

Originally created by @na-Itms on GitHub (Sep 3, 2024). ### Description This issue is similar to #19810 and #23765. Whenever I try to create a PR from a branch **on the same repository** ("merge into repo:main / pull from repo:branch"), I receive the infamous error `batch request: missing protocol: ""`. The error is caused by Git LFS hooks getting installed on the repo server-side. Deleting them temporarily fixes the error and allows me to create the PR. I noticed after a while that the issue arises as soon as the repo of the origin branch contains custom hooks (in our case, under `update.d`. Other repos do not face the issue. Additionally, as soon as the PR is created (from a branch suffering from the problem), the LFS hooks get recreated. ### Gitea Version 1.22.1 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version 2.43.5 ### Operating System AlmaLinux 9 ### How are you running Gitea? Install from binary, run with systemd ### Database MySQL/MariaDB
GiteaMirror added the type/bug label 2025-11-02 10:42:33 -06:00
Author
Owner

@na-Itms commented on GitHub (Sep 16, 2024):

It looks like the issue does not stem from PRs being "same-repository" PRs: I get the issue on all origin repos where a server-side custom hook is installed (in our case, under update.d).

I edited the OP.

@na-Itms commented on GitHub (Sep 16, 2024): It looks like the issue does not stem from PRs being "same-repository" PRs: I get the issue on all origin repos where a server-side custom hook is installed (in our case, under `update.d`). I edited the OP.
Author
Owner

@lunny commented on GitHub (Sep 17, 2024):

Did you mean a new hook file created under update.d after a pull request created? Can you paste the content of this new-installed hook file?

@lunny commented on GitHub (Sep 17, 2024): Did you mean a new hook file created under `update.d` after a pull request created? Can you paste the content of this new-installed hook file?
Author
Owner

@na-Itms commented on GitHub (Sep 18, 2024):

Did you mean a new hook file created under update.d after a pull request created? Can you paste the content of this new-installed hook file?

Hello @lunny, no, the files that are created and cause the issue are the post-checkout, post-commit, post-merge and pre-push LFS hooks. However, I discovered that those are only created in the repos where we installed our own custom hooks under update.d.

By typing this I think I know what the issue is. One of our update.d hooks checks that no raw binary files were pushed by users who haven't installed git-lfs. This hook runs the git-lfs-fsck command to verify the integrity of the LFS tracking. I believe this command is the one causing the LFS hooks to be recreated.

How should we move forward to avoid the batch request: missing protocol: "" error?

@na-Itms commented on GitHub (Sep 18, 2024): > Did you mean a new hook file created under `update.d` after a pull request created? Can you paste the content of this new-installed hook file? Hello @lunny, no, the files that are created and cause the issue are the `post-checkout`, `post-commit`, `post-merge` and `pre-push` LFS hooks. However, I discovered that those are only created in the repos where we installed our own custom hooks under `update.d`. By typing this I think I know what the issue is. One of our `update.d` hooks checks that no raw binary files were pushed by users who haven't installed git-lfs. This hook runs the `git-lfs-fsck` command to verify the integrity of the LFS tracking. I believe this command is the one causing the LFS hooks to be recreated. How should we move forward to avoid the `batch request: missing protocol: ""` error?
Author
Owner

@GiteaBot commented on GitHub (Oct 19, 2024):

We close issues that need feedback from the author if there were no new comments for a month. 🍵

@GiteaBot commented on GitHub (Oct 19, 2024): We close issues that need feedback from the author if there were no new comments for a month. :tea:
Author
Owner

@StanleySweet commented on GitHub (Nov 13, 2024):

Any news?

@StanleySweet commented on GitHub (Nov 13, 2024): Any news?
Author
Owner

@lunny commented on GitHub (Nov 13, 2024):

I haven't figured out how to reproduce it. What did you mean LFS hooks?

@lunny commented on GitHub (Nov 13, 2024): I haven't figured out how to reproduce it. What did you mean `LFS hooks`?
Author
Owner

@na-Itms commented on GitHub (Nov 18, 2024):

Hi. I am not sure I understand what you are asking.

By LFS hooks I mean the default hooks post-checkout, post-commit, post-merge and pre-push. Just like in the other issues mentioned in the top post, the contents of these hooks are (for instance this is pre-push):

#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\n"; exit 2; }
git lfs pre-push "$@"
@na-Itms commented on GitHub (Nov 18, 2024): Hi. I am not sure I understand what you are asking. By LFS hooks I mean the default hooks `post-checkout`, `post-commit`, `post-merge` and `pre-push`. Just like in the other issues mentioned in the top post, the contents of these hooks are (for instance this is `pre-push`): ``` #!/bin/sh command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\n"; exit 2; } git lfs pre-push "$@" ```
Author
Owner

@lunny commented on GitHub (Nov 18, 2024):

Loos like all these hooks are git client side hooks but not server side's. From Gitea side, it has itself git config and it will only have server-side hooks pre-receive, update, post-receive and proc-receive.

@lunny commented on GitHub (Nov 18, 2024): Loos like all these hooks are git client side hooks but not server side's. From Gitea side, it has itself git config and it will only have server-side hooks `pre-receive`, `update`, `post-receive` and `proc-receive`.
Author
Owner

@na-Itms commented on GitHub (Mar 2, 2025):

Hello, I have managed to understand the issue and I am summarizing it again with a fix.

Our repository contains a custom update.d hook on the server that calls the git-lfs-fsck command. Every time a PR is opened or merged against the repository, this command is called to check that the PR contains the correct LFS pointers.

Because of https://github.com/git-lfs/git-lfs/issues/3706#issuecomment-509217575, when this command is called, it creates the post-checkout, post-commit, post-merge and pre-push hooks on the server. These hooks contain the code posted above in https://github.com/go-gitea/gitea/issues/31960#issuecomment-2483263067.

These hooks cause the Gitea error batch request: missing protocol: "". I do not understand why Gitea fails here, as Git LFS is installed on the server. Please reopen this issue if there is a way to make Gitea accept these hooks.

In order to prevent the LFS hooks to get installed in the repository on the server, I followed the advice from https://github.com/git-lfs/git-lfs/issues/3706#issuecomment-509217575: I explicitly created the post-checkout, post-commit, post-merge and pre-push hooks with the content

#!/bin/sh
exit 0

According to the git-lfs developer, this should work for recent versions of git-lfs.

These dummy hooks do not get overwritten as they are not empty, and they do not cause the Gitea error.

@na-Itms commented on GitHub (Mar 2, 2025): Hello, I have managed to understand the issue and I am summarizing it again with a fix. Our repository contains a custom `update.d` hook on the server that calls the `git-lfs-fsck` command. Every time a PR is opened or merged against the repository, this command is called to check that the PR contains the correct LFS pointers. Because of https://github.com/git-lfs/git-lfs/issues/3706#issuecomment-509217575, when this command is called, it creates the `post-checkout`, `post-commit`, `post-merge` and `pre-push` hooks on the server. These hooks contain the code posted above in https://github.com/go-gitea/gitea/issues/31960#issuecomment-2483263067. These hooks cause the Gitea error `batch request: missing protocol: ""`. I do not understand why Gitea fails here, as Git LFS is installed on the server. Please reopen this issue if there is a way to make Gitea accept these hooks. In order to prevent the LFS hooks to get installed in the repository on the server, I followed the advice from https://github.com/git-lfs/git-lfs/issues/3706#issuecomment-509217575: I explicitly created the `post-checkout`, `post-commit`, `post-merge` and `pre-push` hooks with the content ``` #!/bin/sh exit 0 ``` According to the git-lfs developer, this should work for recent versions of git-lfs. These dummy hooks do not get overwritten as they are not empty, and they do not cause the Gitea error.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13444