mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-15 20:52:52 -05:00
[Bug] Merged PRs have their commits and files changed metadata 'zeroed'... sometimes. #5079
Closed
opened 2025-11-02 06:13:37 -06:00 by GiteaMirror
·
31 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
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0-rc2
v1.3.3
v1.4.0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
type/bug
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#5079
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jamesorlakin on GitHub (Mar 18, 2020).
[x]):Description
As of recent (within the last month I'd estimate), many PRs have their commits and files changed counters zeroed out after merging. This happens most of the time but weirdly not always on my instance now. Deleting the branch afterwards doesn't make seem to make a difference if that makes a difference.
I'm not sure how a lot of the internal Git plumbing works for Gitea so I haven't managed to take a look at the code directly. I know that #10618 seemed to be somewhat relevant - and the linked PR example in there does indeed show the behaviour below! I'm confused as to why this is shown for me as both branches definitely still exist.
Screenshots
@lunny commented on GitHub (Mar 19, 2020):
It should be related with #10618. @zeripath
@zeripath commented on GitHub (Mar 19, 2020):
Nope. Merged PRs are displayed by a different set of code.
7225453d5f/routers/repo/pull.go (L303-L328)@zeripath commented on GitHub (Mar 19, 2020):
So the problem seems to be that the mergebase is incorrect - it's somehow ending up being the head!
@zeripath commented on GitHub (Mar 19, 2020):
This means that v128.go is incorrect.
The trouble is that:
Appears to have selected the gitRefName if it's a parent of MergedCommitID instead of searching for the common root for the other parent.
@jamesorlakin commented on GitHub (Mar 19, 2020):
Would you reckon this is a migration problem? This has been happening on new PRs straight after merging.
I tried running it in debug mode (to use breakpoints) with SQLite in VS Code on my Windows machine but hit issues around needing gcc setup properly. I may try and migrate the existing DB to MySQL before investigating further if I get time tomorrow 😃
@zeripath commented on GitHub (Mar 19, 2020):
It's probably the same issue if something recalculates the mergebase.
@zeripath commented on GitHub (Mar 19, 2020):
We need to calculate the merge base from the other parents of the mergecommitid (if there are multiple parents)
Will give the commit id followed by the parents. Can get the merge base from those.
Damn sorry for this bug the original code seemed to work in testing not sure why it didn't work in practice.
@jamesorlakin commented on GitHub (Mar 20, 2020):
EDIT: Ignore me. It was the debugger... Printing it out to the console was fine.
@jamesorlakin commented on GitHub (Mar 20, 2020):
Aah I think I've gotcha, so this bug will appear if the merge commit created by a PR has a parent that's also a merge commit? That would explain it not always appearing!
@zeripath commented on GitHub (Mar 20, 2020):
@jamesorlakin - ah I see how you're getting the problem of the randomly updating merge base.We're back to the race between the checker and merger - which is mostly fixed in 1.12--
Nope that can't happen because we check if it is an ancestor...
@zeripath commented on GitHub (Mar 20, 2020):
Are you sure you're definitely getting this after merging PRs? Could you check what the contenst of the version table is in your DB?
@jamesorlakin commented on GitHub (Mar 23, 2020):
This instance (v1.11.3) is currently on DB version 118:

The


MergeBaseof the Pull model ends up being the commit thatgitRefNamepoints to:It's very strange, and doesn't happen all the time. Some PRs are just fine after merging. I can't seem to figure out any consistent behaviour that would cause this - my theory about merge commits doesn't hold out, as we use a protected branch workflow so every commit the branch points to is a merge commit from a previous PR...
@zeripath commented on GitHub (Mar 23, 2020):
Have they been marked manually merged?
@jamesorlakin commented on GitHub (Mar 23, 2020):
...Marked as manually merged? We just use the big green
Merge Pull Requestbutton - no rebasing or anything fancy... if that helps at all!@zeripath commented on GitHub (Mar 23, 2020):
In the database
pull_requesttable thestatuscolumn do the broken ones havestatus == 3.There's a check goroutine that has almost zero locking in 1.11 - I've mostly fixed this in master (1.12) - that goes around checking if PRs have been merged. If the checker starts during the PR merging phase and runs at or around the same as the PR being merged - it can see the commit in the git repository and think that the commit has been merged manually. At which point I could imagine it might incorrectly update the MergeBase.
@jamesorlakin commented on GitHub (Mar 23, 2020):
Aah right, indeed there is a

status== 3 on a recent 'bad' one.These two PRs were created and merged today. 556 contained one commit from a branch into
dev, and 557 was another PR to merge that intoawswhich contained a commit and the merge commit from 556. No branches have been deleted at this stage.@zeripath commented on GitHub (Mar 23, 2020):
OK that means it is very likely to be the checker.
@jamesorlakin commented on GitHub (Mar 23, 2020):
Aah okay, would you expect to see a lot of manually merged PRs? (what triggers it?)
For reference I have quite a few!

@zeripath commented on GitHub (Mar 31, 2020):
OK so I think I've worked it out:
139fc7cfee/services/pull/check.go (L187-L218)This is the checker from release/v1.11. As I've said before there is a race in this code - it's possible to run this as the PR is being merged or just after it is merged.
Line 203:
139fc7cfee/services/pull/check.go (L203)Calls TestPatch here:
139fc7cfee/services/pull/patch.go (L71-L215)Which updates the pr.MergeBase - but as I say above this can end up being after the PR is merged.
Finally the checker calls:
139fc7cfee/services/pull/check.go (L211)139fc7cfee/services/pull/check.go (L40-L54)which will update the PR without checking if it is merged or not.
The situation is similar on 1.12 but happens less frequently because we're attempting to prevent some of the raceyness.
I think the answer is to change from
pr.UpdateColsto:@zeripath commented on GitHub (Mar 31, 2020):
would it be possible for any of you to test those PRs? I think that they should fix the problem.
@jamesorlakin commented on GitHub (Apr 1, 2020):
I can try and test the backport by building a new Docker image. I'll try and report back tonight or tomorrow if it's worked. 👍
@jamesorlakin commented on GitHub (Apr 1, 2020):
7 PRs down and I've not seen a zeroed one yet. Thanks Zeripath!
@zeripath commented on GitHub (Apr 1, 2020):
Still sorry that I broke it. The broken PRs will be fixed when the migration in #10786 runs - but you might be able to backport the migration manually or fix the broken PRs in the db.
In case you're interested. The correct git command for finding the merge base is: (With
$MERGE_COMMIT_IDand$PR_IDas appropriate)@jamesorlakin commented on GitHub (Apr 2, 2020):
There's nothing to be sorry about, we all make small mistakes here and there. I'm very appreciative of all the work done in an open source project - voluntary work is very respectable and I can see it being a bit of a thankless job at times. Where our team doesn't pay for Gitea (and I'm unfortunately not somebody with financial power to sponsor/donate) I can't expect a support team dedicated to fix things for me 🙂
That said I try and 'pay my debts' to the community that's helped me, so making PRs and generally improving Gitea is in my interest too. Win win!
Oh, and you've also taught me about the
merge-basecommand and some of Gitea's pull logic. ❤️@tanrui8765 commented on GitHub (Apr 17, 2020):
Hello friends, I found this problem seems like still happens in Gitea v1.11.4
A recent pull request:

An old pull request:

@6543 commented on GitHub (Apr 17, 2020):
you have to manualy fix them - a
gitea doctor taskfor this will be in 1.11.5@6543 commented on GitHub (Apr 17, 2020):
@tanrui8765 https://github.com/go-gitea/gitea/pull/10991
"Add non-default recalculate merge bases check/fixer to doctor"
@tanrui8765 commented on GitHub (Apr 17, 2020):
ok, got it, thanks~~ @6543
@tanrui8765 commented on GitHub (May 11, 2020):
@6543
Hello friend, I deployed the gitea version V1.11.5, and tried to use
gitea doctor taskto check this problem, the results was OK, but the problem still exist on our gitea repo.Could you please tell me what to do to manually fix these problems? I'm so confused...
Many Thanks
@6543 commented on GitHub (May 11, 2020):
./gitea doctor --all --fix@tanrui8765@tanrui8765 commented on GitHub (May 12, 2020):
Thank you very much @6543, it worked~