Skip to content
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

After downloading a repository with LFS files as an archive, unnecessary git-hooks created and as a result trying to create a PR results in an error 500 #21148

Closed
dav-sea opened this issue Sep 12, 2022 · 5 comments
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented issue/critical This issue should be fixed ASAP. If it is a PR, the PR should be merged ASAP topic/lfs type/bug

Comments

@dav-sea
Copy link

dav-sea commented Sep 12, 2022

Description

After downloading a repository with LFS files as an archive, unnecessary git-hooks created and as a result trying to create a PR results in an error 500

Steps for representation:

  1. Import or clone this repo
  2. Download the repository as an archive via the Web UI
  3. Create a PR with any modified lfs file
  4. Close the PR and then create a new one just like it
  5. Get error 500 and broken PR

git lfs env

git-lfs/3.0.2 (GitHub; windows amd64; go 1.17.2)
git version 2.35.1.windows.2

Logs

2022/09/12 14:35:04 ...ervices/pull/pull.go:477:pushToBaseRepoHelper() [E] [631f1967-13] Unable to push PR head for sergey-cs/representation-for-bug-with-download-archive#4 (89:sergey-cs/representation-for-bug-with-download-archive:refs/pull/4/head) due to Error: exit status 1 - batch request: missing protocol: ""
        error: failed to push some refs to 'HIDDEN\\sergey-cs\representation-for-bug-with-download-archive.git'

        /source/services/pull/pull.go:477 (0x1c099ee)
        /source/services/pull/pull.go:426 (0x1c050f2)
        /source/services/pull/pull.go:71 (0x1c050f3)
        /source/routers/web/repo/pull.go:1220 (0x21a05d2)
        /source/modules/web/wrap_convert.go:47 (0x1fae9f6)
        /source/modules/web/wrap.go:41 (0x1facc29)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442 (0x1792bf5)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/wrap.go:63 (0x1fad0af)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/wrap.go:63 (0x1fad0af)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/wrap.go:63 (0x1fad0af)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/middleware/get_head.go:37 (0x2014ea4)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/wrap.go:63 (0x1fad0af)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/context/context.go:802 (0x1b7989a)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:71 (0x1790a2c)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:314 (0x17923db)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442 (0x1792bf5)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/routers/web/base.go:174 (0x21e3151)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/gitea.com/go-chi/[email protected]/session.go:257 (0x1584ddd)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/wrap.go:110 (0x1fadb48)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:71 (0x1790a2c)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:314 (0x17923db)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442 (0x1792bf5)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/routers/common/middleware.go:79 (0x201a4a2)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/routing/logger_manager.go:123 (0x1fa894f)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/middleware/strip.go:30 (0x2017c18)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/chi-middleware/[email protected]/middleware.go:37 (0x201451e)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/routers/common/middleware.go:32 (0x201a2f2)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:88 (0x17909e1)
        /source/modules/web/route.go:200 (0x1fac06d)
        /usr/local/go/src/net/http/server.go:2916 (0x8914da)
        /usr/local/go/src/net/http/server.go:1966 (0x88c996)
        /usr/local/go/src/runtime/asm_amd64.s:1571 (0x3adf80)


2022/09/12 14:35:04 ...ers/web/repo/pull.go:1244:CompareAndPullRequestPost() [E] NewPullRequest: Push: sergey-cs/representation-for-bug-with-download-archive:branch-with-changed-lfs-file sergey-cs/representation-for-bug-with-download-archive:refs/pull/4/head exit status 1 - batch request: missing protocol: ""
        error: failed to push some refs to 'HIDDEN\sergey-cs\representation-for-bug-with-download-archive.git'

        /source/routers/web/repo/pull.go:1244 (0x21a09b3)
        /source/modules/web/wrap_convert.go:47 (0x1fae9f6)
        /source/modules/web/wrap.go:41 (0x1facc29)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442 (0x1792bf5)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/wrap.go:63 (0x1fad0af)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/wrap.go:63 (0x1fad0af)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/wrap.go:63 (0x1fad0af)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/middleware/get_head.go:37 (0x2014ea4)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/wrap.go:63 (0x1fad0af)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/context/context.go:802 (0x1b7989a)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:71 (0x1790a2c)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:314 (0x17923db)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442 (0x1792bf5)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/routers/web/base.go:174 (0x21e3151)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/gitea.com/go-chi/[email protected]/session.go:257 (0x1584ddd)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/wrap.go:110 (0x1fadb48)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:71 (0x1790a2c)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:314 (0x17923db)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442 (0x1792bf5)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/routers/common/middleware.go:79 (0x201a4a2)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/modules/web/routing/logger_manager.go:123 (0x1fa894f)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/middleware/strip.go:30 (0x2017c18)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/chi-middleware/[email protected]/middleware.go:37 (0x201451e)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /source/routers/common/middleware.go:32 (0x201a2f2)
        /usr/local/go/src/net/http/server.go:2084 (0x88deee)
        /go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:88 (0x17909e1)
        /source/modules/web/route.go:200 (0x1fac06d)
        /usr/local/go/src/net/http/server.go:2916 (0x8914da)
        /usr/local/go/src/net/http/server.go:1966 (0x88c996)
        /usr/local/go/src/runtime/asm_amd64.s:1571 (0x3adf80)

Workaround

At the moment of downloading the archive via Web UI, unnecessary hooks created in the git folder. If you remove them, the problem will be fixed

image

Also, to prevent the same problem, repeatedly disable the ability to download the repository as an archive from the web ui using config the repository.DISABLE_DOWNLOAD_SOURCE_ARCHIVES=true

The problem also persists in 1.17.2

Gitea Version

1.17.1

Can you reproduce the bug on the Gitea demo site?

No

@dav-sea dav-sea changed the title After downloading a repository with LFS as an archive, unnecessary git-hooks appear and as a consequence break PR After downloading a repository with LFS files as an archive, unnecessary git-hooks created and as a result trying to create a PR results in an error 500 Oct 21, 2022
@philip-peterson
Copy link
Contributor

I believe this is the same as #19810 . I have a plan to fix, posted as a comment on that issue today.

@philip-peterson
Copy link
Contributor

I actually can't reproduce it on vanilla Gitea, but here's a branch, maybe someone can see if it fixes it for them. https://github.com/go-gitea/gitea/compare/main...philip-peterson:gitea:peterson/poc-archive-patch?expand=1

@dav-sea
Copy link
Author

dav-sea commented Oct 31, 2022

@philip-peterson, Are you moving LFS files to the gitea repository?
image

After downloading the archive do you get unnecessary git-hooks?

Update: The problem occurs only after closing the PR and creating a new one exactly the same. Specified it in the steps for reproduction here.

@wxiaoguang wxiaoguang added issue/critical This issue should be fixed ASAP. If it is a PR, the PR should be merged ASAP issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented labels May 22, 2023
@wxiaoguang wxiaoguang added this to the 1.20.0 milestone May 22, 2023
@delvh delvh removed this from the 1.20.0 milestone Jun 5, 2023
brechtvl added a commit to brechtvl/gitea that referenced this issue Jan 19, 2024
When LFS hooks are present in gitea-repositories, operations like git
push for creating a pull request fail. These repositories are not meant
to include LFS files or git push them, that is handled separately. And
so they should not have LFS hooks.

Installing git-lfs on some systems (like Debian Linux) will automatically
set up /etc/gitconfig to create LFS hooks in repositories. For most git
commands in Gitea this is not a problem, either because they run on a
temporary clone or the git command does not create LFS hooks.

But one case where this happens is git archive for creating repository
archives. To fix that, add a GIT_CONFIG_NOSYSTEM=1 to disable using the
system configuration for that command.

According to a comment, GIT_CONFIG_NOSYSTEM is not used for all git
commands because the system configuration can be intentionally set up
for Gitea to use.

Resolves go-gitea#19810, go-gitea#21148
lunny pushed a commit that referenced this issue Jan 19, 2024
When LFS hooks are present in gitea-repositories, operations like git
push for creating a pull request fail. These repositories are not meant
to include LFS files or git push them, that is handled separately. And
so they should not have LFS hooks.

Installing git-lfs on some systems (like Debian Linux) will
automatically set up /etc/gitconfig to create LFS hooks in repositories.
For most git commands in Gitea this is not a problem, either because
they run on a temporary clone or the git command does not create LFS
hooks.

But one case where this happens is git archive for creating repository
archives. To fix that, add a GIT_CONFIG_NOSYSTEM=1 to disable using the
system configuration for that command.

According to a comment, GIT_CONFIG_NOSYSTEM is not used for all git
commands because the system configuration can be intentionally set up
for Gitea to use.

Resolves #19810, #21148
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Jan 19, 2024
…8848)

When LFS hooks are present in gitea-repositories, operations like git
push for creating a pull request fail. These repositories are not meant
to include LFS files or git push them, that is handled separately. And
so they should not have LFS hooks.

Installing git-lfs on some systems (like Debian Linux) will
automatically set up /etc/gitconfig to create LFS hooks in repositories.
For most git commands in Gitea this is not a problem, either because
they run on a temporary clone or the git command does not create LFS
hooks.

But one case where this happens is git archive for creating repository
archives. To fix that, add a GIT_CONFIG_NOSYSTEM=1 to disable using the
system configuration for that command.

According to a comment, GIT_CONFIG_NOSYSTEM is not used for all git
commands because the system configuration can be intentionally set up
for Gitea to use.

Resolves go-gitea#19810, go-gitea#21148
@brechtvl
Copy link
Contributor

This issue can be closed along with #19810.

@delvh delvh closed this as completed Jan 19, 2024
KN4CK3R pushed a commit that referenced this issue Jan 21, 2024
…28851)

Backport #28848 by @brechtvl

When LFS hooks are present in gitea-repositories, operations like git
push for creating a pull request fail. These repositories are not meant
to include LFS files or git push them, that is handled separately. And
so they should not have LFS hooks.

Installing git-lfs on some systems (like Debian Linux) will
automatically set up /etc/gitconfig to create LFS hooks in repositories.
For most git commands in Gitea this is not a problem, either because
they run on a temporary clone or the git command does not create LFS
hooks.

But one case where this happens is git archive for creating repository
archives. To fix that, add a GIT_CONFIG_NOSYSTEM=1 to disable using the
system configuration for that command.

According to a comment, GIT_CONFIG_NOSYSTEM is not used for all git
commands because the system configuration can be intentionally set up
for Gitea to use.

Resolves #19810, #21148

Co-authored-by: Brecht Van Lommel <[email protected]>
henrygoodman pushed a commit to henrygoodman/gitea that referenced this issue Jan 31, 2024
…8848)

When LFS hooks are present in gitea-repositories, operations like git
push for creating a pull request fail. These repositories are not meant
to include LFS files or git push them, that is handled separately. And
so they should not have LFS hooks.

Installing git-lfs on some systems (like Debian Linux) will
automatically set up /etc/gitconfig to create LFS hooks in repositories.
For most git commands in Gitea this is not a problem, either because
they run on a temporary clone or the git command does not create LFS
hooks.

But one case where this happens is git archive for creating repository
archives. To fix that, add a GIT_CONFIG_NOSYSTEM=1 to disable using the
system configuration for that command.

According to a comment, GIT_CONFIG_NOSYSTEM is not used for all git
commands because the system configuration can be intentionally set up
for Gitea to use.

Resolves go-gitea#19810, go-gitea#21148
silverwind pushed a commit to silverwind/gitea that referenced this issue Feb 20, 2024
…8848)

When LFS hooks are present in gitea-repositories, operations like git
push for creating a pull request fail. These repositories are not meant
to include LFS files or git push them, that is handled separately. And
so they should not have LFS hooks.

Installing git-lfs on some systems (like Debian Linux) will
automatically set up /etc/gitconfig to create LFS hooks in repositories.
For most git commands in Gitea this is not a problem, either because
they run on a temporary clone or the git command does not create LFS
hooks.

But one case where this happens is git archive for creating repository
archives. To fix that, add a GIT_CONFIG_NOSYSTEM=1 to disable using the
system configuration for that command.

According to a comment, GIT_CONFIG_NOSYSTEM is not used for all git
commands because the system configuration can be intentionally set up
for Gitea to use.

Resolves go-gitea#19810, go-gitea#21148
Copy link

github-actions bot commented Mar 1, 2024

Automatically locked because of our CONTRIBUTING guidelines

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented issue/critical This issue should be fixed ASAP. If it is a PR, the PR should be merged ASAP topic/lfs type/bug
Projects
None yet
Development

No branches or pull requests

6 participants