View PR in UI always returns 500 #4645

Closed
opened 2025-11-02 05:57:17 -06:00 by GiteaMirror · 16 comments
Owner

Originally created by @gerritc on GitHub (Jan 14, 2020).

  • Gitea version (or commit ref):
  • Git version: 1.11.0-rc1
  • Operating system: Ubuntu 18.04.3
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:
2020/01/14 05:32:33 routers/repo/pull.go:320:PrepareMergedViewPullInfo() [E] GetCompareInfo: exit status 128 - fatal: ambiguous argument 'a6bb53d9d3ae1d78dd55fdd202aec98c62836485...refs/pull/14/head': unknown revision or path not in the working tree.
        Use '--' to separate paths from revisions, like this:
        'git <command> [<revision>...] -- [<file>...]'
2020/01/14 05:35:18 routers/repo/pull.go:383:PrepareViewPullInfo() [E] GetRefCommitID(refs/pull/84/head): reference not found

Description

After upgrading from 1.10.2 we can't open any pull-request. Gitea returns always a 500. The first error appears when opening a merged pull-request. The second error appears when opening a open pull-request. I can't figure out how to reproduce this situation.

Screenshot

image

Originally created by @gerritc on GitHub (Jan 14, 2020). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): - Git version: 1.11.0-rc1 - Operating system: Ubuntu 18.04.3 - Database (use `[x]`): - [x] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [ ] Not relevant - Log gist: ``` 2020/01/14 05:32:33 routers/repo/pull.go:320:PrepareMergedViewPullInfo() [E] GetCompareInfo: exit status 128 - fatal: ambiguous argument 'a6bb53d9d3ae1d78dd55fdd202aec98c62836485...refs/pull/14/head': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' ``` ``` 2020/01/14 05:35:18 routers/repo/pull.go:383:PrepareViewPullInfo() [E] GetRefCommitID(refs/pull/84/head): reference not found ``` ## Description After upgrading from 1.10.2 we can't open any pull-request. Gitea returns always a 500. The first error appears when opening a merged pull-request. The second error appears when opening a open pull-request. I can't figure out how to reproduce this situation. ## Screenshot ![image](https://user-images.githubusercontent.com/32355528/72318753-6d50d200-369d-11ea-9ba2-da0e180926dd.png)
GiteaMirror added the issue/regressiontype/bug labels 2025-11-02 05:57:17 -06:00
Author
Owner

@zeripath commented on GitHub (Jan 14, 2020):

What version of git are you running?

@zeripath commented on GitHub (Jan 14, 2020): What version of git are you running?
Author
Owner

@zeripath commented on GitHub (Jan 14, 2020):

Presumably you're running quite an old git and this notation doesn't work on that version. We'll have to figure out the correct call and then send a patch.

@zeripath commented on GitHub (Jan 14, 2020): Presumably you're running quite an old git and this notation doesn't work on that version. We'll have to figure out the correct call and then send a patch.
Author
Owner

@gerritc commented on GitHub (Jan 15, 2020):

git version: 2.17.1
The problem exists also with current (2.25.0) git version.

@gerritc commented on GitHub (Jan 15, 2020): git version: 2.17.1 The problem exists also with current (2.25.0) git version.
Author
Owner

@zeripath commented on GitHub (Jan 15, 2020):

Ok. I thought that this would be an old syntax problem.

The problem line is here:

25531c71a7/modules/git/repo_compare.go (L70)

Right. Do you have access to Gitea's repositories on the server?

If so can you go to the repo and try:

git rev-parse --verify refs/pull/14/head

What I am presuming is that git can't find that unusual ref, if this works we can then try the git log a6bb53d9d3ae1d78dd55fdd202aec98c62836485...the_sha_you_obtain

If the rev-parse doesn't work I'd like you to check in the refs/pull directory to ensure that the pull does actually have a ref.

If it doesn't then I'm confused as there should be one there - but it would at least explain why there is this problem.

@zeripath commented on GitHub (Jan 15, 2020): Ok. I thought that this would be an old syntax problem. The problem line is here: https://github.com/go-gitea/gitea/blob/25531c71a78b98af91f25d5e6eaa362e5fc54a86/modules/git/repo_compare.go#L70 Right. Do you have access to Gitea's repositories on the server? If so can you go to the repo and try: git rev-parse --verify refs/pull/14/head What I am presuming is that git can't find that unusual ref, if this works we can then try the `git log a6bb53d9d3ae1d78dd55fdd202aec98c62836485...the_sha_you_obtain` If the rev-parse doesn't work I'd like you to check in the refs/pull directory to ensure that the pull does actually have a ref. If it doesn't then I'm confused as there should be one there - but it would at least explain why there is this problem.
Author
Owner

@zeripath commented on GitHub (Jan 15, 2020):

I think the attached pr fixes this because I suspect what is happening is that the queue gets locked and then the branch never gets updated.

Hopefully that is the issue.

@zeripath commented on GitHub (Jan 15, 2020): I think the attached pr fixes this because I suspect what is happening is that the queue gets locked and then the branch never gets updated. Hopefully that is the issue.
Author
Owner

@ryan-shaw commented on GitHub (Jan 20, 2020):

@zeripath I'm running into the same issue here GetRefCommitID(refs/pull/3/head): reference not found

version 1.10.3, I don't think your patch will fix it as the code you are changing doesn't exist in 1.10.3 > https://github.com/go-gitea/gitea/blob/v1.10.3/modules/sync/unique_queue.go#L47

git show-ref refs/pull/3/head shows no commit when ran (in gitea repos)

Let me know if you need any information.

@ryan-shaw commented on GitHub (Jan 20, 2020): @zeripath I'm running into the same issue here `GetRefCommitID(refs/pull/3/head): reference not found` version 1.10.3, I don't think your patch will fix it as the code you are changing doesn't exist in 1.10.3 > https://github.com/go-gitea/gitea/blob/v1.10.3/modules/sync/unique_queue.go#L47 `git show-ref refs/pull/3/head` shows no commit when ran (in gitea repos) Let me know if you need any information.
Author
Owner

@lunny commented on GitHub (Jan 20, 2020):

@ryan-shaw could you reproduce that on try.gitea.io?

@lunny commented on GitHub (Jan 20, 2020): @ryan-shaw could you reproduce that on try.gitea.io?
Author
Owner

@ryan-shaw commented on GitHub (Jan 20, 2020):

@lunny I'm not sure I could as I don't know how it got into this state.

@ryan-shaw commented on GitHub (Jan 20, 2020): @lunny I'm not sure I could as I don't know how it got into this state.
Author
Owner

@lunny commented on GitHub (Jan 20, 2020):

OKay. any log could you found when the 500 happened?

@lunny commented on GitHub (Jan 20, 2020): OKay. any log could you found when the 500 happened?
Author
Owner

@ryan-shaw commented on GitHub (Jan 20, 2020):

The ref file I'd expect to see in /data/git/repositories/<owner>/<repo>.git/refs/pull/3/head does not exist either so some how Gitea has deleted the references whilst the pull request is still open.

The only log entry available is 2020/01/20 15:08:19 routers/repo/pull.go:368:PrepareViewPullInfo() [E] GetRefCommitID(refs/pull/3/head): reference not found

@ryan-shaw commented on GitHub (Jan 20, 2020): The ref file I'd expect to see in `/data/git/repositories/<owner>/<repo>.git/refs/pull/3/head` does not exist either so some how Gitea has deleted the references whilst the pull request is still open. The only log entry available is `2020/01/20 15:08:19 routers/repo/pull.go:368:PrepareViewPullInfo() [E] GetRefCommitID(refs/pull/3/head): reference not found`
Author
Owner

@ryan-shaw commented on GitHub (Jan 20, 2020):

It appears the PRs with missing refs were before we migrated to a new host with a backup/restore, in our 14/01/2020 (pre-migration) backup I see the file refs/pull/3/head but in the first backup after the restore that file has gone. Could this be restore related?

Our restore script does


s6-svc -d /var/run/s6/services/gitea

sleep 5

mv data/conf/app.ini /data/gitea/conf/app.ini

unzip gitea-repo.zip

rm -rf /data/git/repositories
mv repositories /data/git/

chown -R git:git /data/git/ /data/gitea/conf/app.ini
@ryan-shaw commented on GitHub (Jan 20, 2020): It appears the PRs with missing refs were before we migrated to a new host with a backup/restore, in our 14/01/2020 (pre-migration) backup I see the file `refs/pull/3/head` but in the first backup after the restore that file has gone. Could this be restore related? Our restore script does ```unzip $backup s6-svc -d /var/run/s6/services/gitea sleep 5 mv data/conf/app.ini /data/gitea/conf/app.ini unzip gitea-repo.zip rm -rf /data/git/repositories mv repositories /data/git/ chown -R git:git /data/git/ /data/gitea/conf/app.ini ```
Author
Owner

@guillep2k commented on GitHub (Jan 20, 2020):

@ryan-shaw Not that this is related to your problem, but just in case: if you ever move the gitea executable or gitea-repositories, you need to recreate the hooks and the authorized_keys file from the site admin menu.

About your script, the question is whether the refs are in the zip file or not. Try extracting one of the refs files directly from the zip and check what it looks like. It should have entries like:

2509627ed6e459d8f8c4af9d3e1c26fd16413930        refs/heads/master
33bc2703b09b9998d355503173f410909fe2c19d        refs/pull/2/head

The refs file should be found on each repo at:

gitea-repositories/user1/repouser1.git/info/refs
@guillep2k commented on GitHub (Jan 20, 2020): @ryan-shaw Not that this is related to your problem, but just in case: if you ever move the `gitea` executable or `gitea-repositories`, you need to recreate the hooks and the `authorized_keys` file from the site admin menu. About your script, the question is whether the refs are in the zip file or not. Try extracting one of the refs files directly from the zip and check what it looks like. It should have entries like: ``` 2509627ed6e459d8f8c4af9d3e1c26fd16413930 refs/heads/master 33bc2703b09b9998d355503173f410909fe2c19d refs/pull/2/head ``` The `refs` file should be found on each repo at: ``` gitea-repositories/user1/repouser1.git/info/refs ```
Author
Owner

@ryan-shaw commented on GitHub (Jan 20, 2020):

@guillep2k yep, that's already part of our internal restore docs :)

I can find the the refs/pull/3/head in our pre-migration backup, in all subsequent ones it does not exist

@ryan-shaw commented on GitHub (Jan 20, 2020): @guillep2k yep, that's already part of our internal restore docs :) I can find the the `refs/pull/3/head` in our pre-migration backup, in all subsequent ones it does not exist
Author
Owner

@ryan-shaw commented on GitHub (Jan 20, 2020):

@guillep2k

Interestingly, in our pre-migration backup and current state don't have refs/pull/3/head in gitea-repositories/<user>/<repo>.git/info/refs but the backup does have gitea-repositories/<user>/<repo>.git/refs/pull/3/head

I guess the above is because git gc (?)

@ryan-shaw commented on GitHub (Jan 20, 2020): @guillep2k Interestingly, in our pre-migration backup and current state don't have `refs/pull/3/head` in `gitea-repositories/<user>/<repo>.git/info/refs` but the backup does have `gitea-repositories/<user>/<repo>.git/refs/pull/3/head` I guess the above is because git gc (?)
Author
Owner

@ryan-shaw commented on GitHub (Jan 20, 2020):

I think I know what caused the missing ref, we migrated from Gitlab and in doing so we were using git remote update && git push --mirror to sync changes from Gitlab to Gitea, before we switched I opened a couple of PRs to test Gitea, I think what happened with the git push --mirror is it deleted the refs it didn't see locally

https://git-scm.com/docs/git-push#Documentation/git-push.txt---mirror

Turns out to be user error :)

edit:
To fix the issue:

git update-ref refs/pull/3/head 1b3326980d4050067bbbbe2e49bb881f7c64f13f
(commit hash of head of that branch)
git push refs/pull/3/head
@ryan-shaw commented on GitHub (Jan 20, 2020): I think I know what caused the missing ref, we migrated from Gitlab and in doing so we were using `git remote update && git push --mirror` to sync changes from Gitlab to Gitea, before we switched I opened a couple of PRs to test Gitea, I think what happened with the `git push --mirror` is it deleted the refs it didn't see locally https://git-scm.com/docs/git-push#Documentation/git-push.txt---mirror Turns out to be user error :) edit: To fix the issue: ``` git update-ref refs/pull/3/head 1b3326980d4050067bbbbe2e49bb881f7c64f13f (commit hash of head of that branch) git push refs/pull/3/head ```
Author
Owner

@guillep2k commented on GitHub (Jan 20, 2020):

@ryan-shaw Glad you could solve it! 😄

@guillep2k commented on GitHub (Jan 20, 2020): @ryan-shaw Glad you could solve it! 😄
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#4645