gitea icon indicating copy to clipboard operation
gitea copied to clipboard

Error when pushing to renamed repository

Open lafriks opened this issue 1 year ago • 32 comments

Description

When pushing to/pulling from renamed repository there is error:

git fetch
error: RPC failed; HTTP 307 curl 22 The requested URL returned error: 307
fatal: expected flush after ref listing

Gitea Version

1.21.2

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Binary

Database

PostgreSQL

lafriks avatar Dec 13 '23 19:12 lafriks

Did you push to the old name or the new name?

lunny avatar Dec 17 '23 11:12 lunny

Hi, same issue here: When pushing to the old URL of a repo that has been moved (in my case from a user to an org), I get the same error. Setting the new remote URL works, of course.

PsychotherapistSam avatar Dec 21 '23 13:12 PsychotherapistSam

When pushing to the old remote url, also by just renaming without changing owner

lafriks avatar Dec 28 '23 00:12 lafriks

What's the expectation? Should it be allowed to redirect to the real repository or should it return the 404?

lunny avatar Dec 28 '23 01:12 lunny

Same here. Seems like the 1.21.2 update (or previous) broke the redirect functionality for renamed repos or organization or when moving a repo from one orga to another.

Before it was possible to rename/move a repo/orga and still use (fetch, pull, push) the local copy without having to "fix" the remote url. Gitea redirected from the previous remote url to the new location/name automatically. There was a warning on the console that the operation is executed on a redirected URL.

Please fix! Its a pita to rename an organization with certain number of repos and users without this feature!

chris-08154711 avatar Jan 10 '24 09:01 chris-08154711

What's the expectation? Should it be allowed to redirect to the real repository or should it return the 404?

Previously it allowed to push to old remote url and it would still work as it was pushed to new repo location

lafriks avatar Jan 22 '24 00:01 lafriks

Interesting, it appears as though this is because git doesn't accept redirect headers, and we must've previously accepted pushes to renamed repos with a 200 instead of a 308.

This is also interesting as we allow pushes with or without .git trailing, so there should be similar logic.

techknowlogick avatar Jan 22 '24 01:01 techknowlogick

I cannot reproduce this on main branch with http clone/pull/push when renaming the repository under the same user and also transfer to another org.

lunny avatar Feb 19 '24 12:02 lunny

I cannot reproduce this on main branch with http clone/pull/push when renaming the repository under the same user and also transfer to another org.

Steps to reproduce:

  1. Clone a repo
  2. Rename the repo (or move in another orga) in gitea
  3. Check "git remote -v" on your clone - remote points to the original repo url/name
  4. Try fetch/pull/push with the "invalid" remote url - not working!
  5. The original url is still available in gitea UI but beeing 307 redirected to the renamed repo url

image

image

chris-08154711 avatar Feb 19 '24 13:02 chris-08154711

@lunny comment above updated with steps and screenshots (sorry, was in a hurry yesterday and couldn't complete the post)

gitea version: 1.21.1 git client version: git version 2.41.0.windows.3

chris-08154711 avatar Feb 20 '24 09:02 chris-08154711

Just from attempting to quickly bisect this, the last tagged release where this worked was 1.21.0-rc2, and all subsequent versions can't pull/push from renamed repositories when using the old repository URL.

My team suspects that this PR introduced it: https://github.com/go-gitea/gitea/pull/27875

newgreenshoot avatar Mar 01 '24 05:03 newgreenshoot

I cannot reproduce this on main branch with http clone/pull/push when renaming the repository under the same user and also transfer to another org.

Steps to reproduce:

1. Clone a repo

2. Rename the repo (or move in another orga) in gitea

3. Check "git remote -v" on your clone - remote points to the original repo url/name

4. Try fetch/pull/push with the "invalid" remote url - not working!

5. The original url is still available in gitea UI but beeing 307 redirected to the renamed repo url

image

image

It works for me on main branch. image

lunny avatar Mar 02 '24 11:03 lunny

gitea: 1.21.5 git client: 2.44.0 and 2.43.0 on linux gitea is behind reverse proxy using Apache 2.4.57

Running git clone with GIT_CURL_VERBOSE=1 and GIT_TRACE=1. This is HTTP communication from the trace.

POST /<redacted>/<redacted>.git/git-upload-pack HTTP/1.1
Host: <redacted>
Authorization: Basic <redacted>
User-Agent: git/2.44.0
Accept-Encoding: deflate, gzip
Content-Type: application/x-git-upload-pack-request
Accept: application/x-git-upload-pack-result
Accept-Language: cs-CZ, *;q=0.9
Git-Protocol: version=2
Content-Length: 175

HTTP/1.1 307 Temporary Redirect
Date: Tue, 05 Mar 2024 10:24:42 GMT
Server: Apache/2.4.57 (Debian)
Cache-Control: max-age=0, private, must-revalidate, no-transform
Location: /<redacted>/<redacted>/git-upload-pack
X-Frame-Options: SAMEORIGIN
Content-Length: 0
Set-Cookie: i_like_gitea=<redacted>; Path=/; HttpOnly; Secure; SameSite=Lax
Set-Cookie: _csrf=<redacted>; Path=/; Max-Age=86400; HttpOnly; Secure; SameSite=Lax

Same error error: RPC failed; HTTP 307 curl 22 The requested URL returned error: 307

j123b567 avatar Mar 05 '24 10:03 j123b567

I can confirm the issue. Using Gitea 1.21.7 with docker from the linuxserver.io image. Since we are a small team, I simply had to reset the git origin on my local clone to the new name, but I had to look around for 30 minutes before I found the issue! Good luck all

le-patenteux avatar Mar 05 '24 22:03 le-patenteux

What sorts of setups are other people using? Is Gitea running behind a reverse proxy? Are you requiring HTTP authentication? I'm starting to wonder if there's some specific configuration detail that's responsible for this, since @lunny can't reproduce it under normal conditions. https://github.com/go-gitea/gitea/pull/27875 certainly seems to be responsible though.

This appears to still affect v1.22.0, and my organization is unable to update past v1.21.0-rc2 due to this.

newgreenshoot avatar May 29 '24 22:05 newgreenshoot

We have an possibly related issue renaming a branch via our gitea v 1.21.4 website. If we are at the "branches" view, and try to rename a branch via "rename" symbol at the right side of the branch in question, we get back an http error 404.

netsrotr avatar Jul 22 '24 13:07 netsrotr

We have the same issue in 1.21.10. It appears an upgrade will not solve it, is it correct?

robertschulze avatar Jul 30 '24 12:07 robertschulze

What sorts of setups are other people using? Is Gitea running behind a reverse proxy? Are you requiring HTTP authentication? I'm starting to wonder if there's some specific configuration detail that's responsible for this, since @lunny can't reproduce it under normal conditions. #27875 certainly seems to be responsible though.

This appears to still affect v1.22.0, and my organization is unable to update past v1.21.0-rc2 due to this.

Yes, we are running Gitea behind a reverse proxy (Apache 2.4.58).

robertschulze avatar Jul 30 '24 12:07 robertschulze

We have an possibly related issue renaming a branch via our gitea v 1.21.4 website. If we are at the "branches" view, and try to rename a branch via "rename" symbol at the right side of the branch in question, we get back an http error 404.

Gitea is running behind a apache proxy.

netsrotr avatar Jul 30 '24 19:07 netsrotr

Gitea behind swag (NGINX), authentication by Gitea itself for me. I can't say if the issue has returned as we did not rename a repo since the incident in march

le-patenteux avatar Jul 30 '24 19:07 le-patenteux

I encountered this issue, after changing my username.

winston0410 avatar Oct 05 '24 08:10 winston0410

Please confirm with no reverse proxy after you upgrade to 1.22.2 and I still cannot reproduce it in main branch and 1.22.2 .

lunny avatar Oct 05 '24 19:10 lunny

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

GiteaBot avatar Nov 05 '24 03:11 GiteaBot

@lafriks Can you confirm this is still a problem?

lunny avatar Nov 05 '24 05:11 lunny

Rename branch with v1.22.3 works now--Gesendet mit der GMX Mail AppAm 05.11.24, 06:54 schrieb Lunny Xiao @.***>:

@lafriks Can you confirm this is still a problem?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

netsrotr avatar Nov 05 '24 09:11 netsrotr

This is still a problem after we upgraded to 1.22.6. We are running gitea behind caddy.

GalaxySnail avatar Dec 17 '24 13:12 GalaxySnail

Can you reproduce it on demo site?

lunny avatar Dec 17 '24 15:12 lunny

How to reproduce it on demo site? It requires a renamed repo, but I can't figure out which repo is renamed on demo site.

GalaxySnail avatar Dec 17 '24 16:12 GalaxySnail

You can create a new repository -> rename it and push a commit to the new repository.

lunny avatar Dec 17 '24 18:12 lunny

I can't reproduce it on demo site. These are HTTP requests sent by git remote show origin on our gitea instance:

> CONNECT <domain_name>:443 HTTP/1.1
> Host: <domain_name>:443
> User-Agent: git/2.47.1
> Proxy-Connection: Keep-Alive

< HTTP/1.1 200 Connection established

Info: using HTTP/2
Info: [HTTP/2] [1] OPENED stream for https://<domain_name>/GalaxySnail/<repo_name>.git/info/refs?service=git-upload-pack
Info: [HTTP/2] [1] [:method: GET]
Info: [HTTP/2] [1] [:scheme: https]
Info: [HTTP/2] [1] [:authority: <domain_name>]
Info: [HTTP/2] [1] [:path: /GalaxySnail/<repo_name>.git/info/refs?service=git-upload-pack]
Info: [HTTP/2] [1] [user-agent: git/2.47.1]
Info: [HTTP/2] [1] [accept: */*]
Info: [HTTP/2] [1] [accept-encoding: deflate, gzip, br, zstd]
Info: [HTTP/2] [1] [pragma: no-cache]
Info: [HTTP/2] [1] [git-protocol: version=2]

> GET /GalaxySnail/<repo_name>.git/info/refs?service=git-upload-pack HTTP/2
> Host: <domain_name>
> User-Agent: git/2.47.1
> Accept: */*
> Accept-Encoding: deflate, gzip, br, zstd
> Pragma: no-cache
> Git-Protocol: version=2

< HTTP/2 401
< date: Wed, 18 Dec 2024 10:59:31 GMT
< content-type: text/plain; charset=utf-8
< content-length: 13
< alt-svc: h3=":443"; ma=86400
< cache-control: max-age=0, private, must-revalidate, no-transform
< set-cookie: i_like_gitea=<edited> SameSite=Lax
< set-cookie: _csrf=<edited> SameSite=Lax
< www-authenticate: Basic realm="Gitea"
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< cf-cache-status: DYNAMIC
< report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=<edited>"}],"group":"cf-nel","max_age":604800}
< nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< server: cloudflare
< cf-ray: <edited>
< server-timing: <edited>

Info: Re-using existing connection with proxy 127.0.0.1
Info: Server auth using Basic with user 'GalaxySnail'
Info: [HTTP/2] [3] OPENED stream for https://<domain_name>/GalaxySnail/<repo_name>.git/info/refs?service=git-upload-pack
Info: [HTTP/2] [3] [:method: GET]
Info: [HTTP/2] [3] [:scheme: https]
Info: [HTTP/2] [3] [:authority: <domain_name>]
Info: [HTTP/2] [3] [:path: /GalaxySnail/<repo_name>.git/info/refs?service=git-upload-pack]
Info: [HTTP/2] [3] [authorization: Basic <redacted>]
Info: [HTTP/2] [3] [user-agent: git/2.47.1]
Info: [HTTP/2] [3] [accept: */*]
Info: [HTTP/2] [3] [accept-encoding: deflate, gzip, br, zstd]
Info: [HTTP/2] [3] [pragma: no-cache]
Info: [HTTP/2] [3] [git-protocol: version=2]

> GET /GalaxySnail/<repo_name>.git/info/refs?service=git-upload-pack HTTP/2
> Host: <domain_name>
> Authorization: Basic <redacted>
> User-Agent: git/2.47.1
> Accept: */*
> Accept-Encoding: deflate, gzip, br, zstd
> Pragma: no-cache
> Git-Protocol: version=2

< HTTP/2 307
< date: Wed, 18 Dec 2024 10:59:40 GMT
< content-type: text/html; charset=utf-8
< content-length: 93
< alt-svc: h3=":443"; ma=86400
< cache-control: max-age=0, private, must-revalidate, no-transform
< location: /shared/<repo_name>/info/refs?service=git-upload-pack
< set-cookie: i_like_gitea=<edited> SameSite=Lax
< set-cookie: _csrf=<edited> SameSite=Lax
< x-frame-options: SAMEORIGIN
< cf-cache-status: DYNAMIC
< report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=<edited>"}],"group":"cf-nel","max_age":604800}
< nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< server: cloudflare
< cf-ray: <edited>
< server-timing: <edited>

Info: Connection #0 to host 127.0.0.1 left intact
Info: Issue another request to this URL: 'https://GalaxySnail:<password>@<domain_name>/shared/<repo_name>/info/refs?service=git-upload-pack'
Info: Re-using existing connection with proxy 127.0.0.1
Info: Server auth using Basic with user 'GalaxySnail'
Info: [HTTP/2] [5] OPENED stream for https://GalaxySnail:<password>@<domain_name>/shared/<repo_name>/info/refs?service=git-upload-pack
Info: [HTTP/2] [5] [:method: GET]
Info: [HTTP/2] [5] [:scheme: https]
Info: [HTTP/2] [5] [:authority: <domain_name>]
Info: [HTTP/2] [5] [:path: /shared/<repo_name>/info/refs?service=git-upload-pack]
Info: [HTTP/2] [5] [authorization: Basic <redacted>]
Info: [HTTP/2] [5] [user-agent: git/2.47.1]
Info: [HTTP/2] [5] [accept: */*]
Info: [HTTP/2] [5] [accept-encoding: deflate, gzip, br, zstd]
Info: [HTTP/2] [5] [pragma: no-cache]
Info: [HTTP/2] [5] [git-protocol: version=2]

> GET /shared/<repo_name>/info/refs?service=git-upload-pack HTTP/2
> Host: <domain_name>
> Authorization: Basic <redacted>
> User-Agent: git/2.47.1
> Accept: */*
> Accept-Encoding: deflate, gzip, br, zstd
> Pragma: no-cache
> Git-Protocol: version=2

< HTTP/2 200
< date: Wed, 18 Dec 2024 10:59:41 GMT
< content-type: application/x-git-upload-pack-advertisement
< content-length: 188
< alt-svc: h3=":443"; ma=86400
< cache-control: no-cache, max-age=0, must-revalidate
< expires: Fri, 01 Jan 1980 00:00:00 GMT
< pragma: no-cache
< set-cookie: i_like_gitea=<edited> SameSite=Lax
< set-cookie: _csrf=<edited> SameSite=Lax
< x-frame-options: SAMEORIGIN
< cf-cache-status: DYNAMIC
< report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=<edited>"}],"group":"cf-nel","max_age":604800}
< nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< server: cloudflare
< cf-ray: <edited>
< server-timing: <edited>

Info: Re-using existing connection with proxy 127.0.0.1
Info: Server auth using Basic with user 'GalaxySnail'
Info: [HTTP/2] [7] OPENED stream for https://<domain_name>/GalaxySnail/<repo_name>.git/git-upload-pack
Info: [HTTP/2] [7] [:method: POST]
Info: [HTTP/2] [7] [:scheme: https]
Info: [HTTP/2] [7] [:authority: <domain_name>]
Info: [HTTP/2] [7] [:path: /GalaxySnail/<repo_name>.git/git-upload-pack]
Info: [HTTP/2] [7] [authorization: Basic <redacted>]
Info: [HTTP/2] [7] [user-agent: git/2.47.1]
Info: [HTTP/2] [7] [accept-encoding: deflate, gzip, br, zstd]
Info: [HTTP/2] [7] [content-type: application/x-git-upload-pack-request]
Info: [HTTP/2] [7] [accept: application/x-git-upload-pack-result]
Info: [HTTP/2] [7] [git-protocol: version=2]
Info: [HTTP/2] [7] [content-length: 102]

> POST /GalaxySnail/<repo_name>.git/git-upload-pack HTTP/2
> Host: <domain_name>
> Authorization: Basic <redacted>
> User-Agent: git/2.47.1
> Accept-Encoding: deflate, gzip, br, zstd
> Content-Type: application/x-git-upload-pack-request
> Accept: application/x-git-upload-pack-result
> Git-Protocol: version=2
> Content-Length: 102

< HTTP/2 307
< date: Wed, 18 Dec 2024 10:59:41 GMT
< content-length: 0
< alt-svc: h3=":443"; ma=86400
< cache-control: max-age=0, private, must-revalidate, no-transform
< location: /shared/<repo_name>/git-upload-pack
< set-cookie: i_like_gitea=<edited> SameSite=Lax
< set-cookie: _csrf=<edited> SameSite=Lax
< x-frame-options: SAMEORIGIN
< cf-cache-status: DYNAMIC
< report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=<edited>"}],"group":"cf-nel","max_age":604800}
< nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< server: cloudflare
< cf-ray: <edited>
< server-timing: <edited>

Info: Connection #0 to host 127.0.0.1 left intact

error: RPC failed; HTTP 307 curl 22 The requested URL returned error: 307
fatal: expected flush after ref listing

It seems related to the fact that we enabled [service].REQUIRE_SIGNIN_VIEW.

GalaxySnail avatar Dec 18 '24 12:12 GalaxySnail