go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
45.35k stars 5.51k forks source link

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

Open na-Itms opened 2 months ago

na-Itms commented 2 months ago

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

na-Itms commented 2 months ago

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.

lunny commented 2 months ago

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?

na-Itms commented 2 months ago

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?

GiteaBot commented 1 month ago

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

StanleySweet commented 2 weeks ago

Any news?

lunny commented 2 weeks ago

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

na-Itms commented 1 week ago

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 "$@"
lunny commented 1 week ago

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.