Fix the wrong push commits in the pull request when force push#36914
Conversation
ae9617b to
2f1862c
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses #36905 by fixing how commit lists are computed for pull request timeline “push” entries after a force-push, ensuring the timeline reflects the full set of commits currently on the PR branch (not just the delta from the previous head).
Changes:
- Update force-push handling in
CreatePushPullCommentto compute PR commit IDs via merge-base comparison against the base branch. - Add a new helper (
GetCompareCommitIDsWithMergeBase) inservices/gitplus unit test coverage for it. - Add a pull service test case intended to cover “missing old commit” scenarios during force-push.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| services/pull/comment.go | Switch force-push commit enumeration to merge-base-based compare logic. |
| services/pull/comment_test.go | Add a force-push test case targeting missing/unreachable old commit scenarios. |
| services/git/compare.go | Introduce GetCompareCommitIDsWithMergeBase helper to list commits from merge-base..head. |
| services/git/compare_test.go | Add unit test validating the helper’s output against CommitsBetweenNotBase. |
| services/git/main_test.go | Add TestMain bootstrap for services/git tests (unittest DB init). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
Don't make it depends on "db" Don't use Why the simple git operation should depend on db? |
|
In essence the fix should be pretty simple: The commit timeline (and tab count) should always show the actual commits present in the branch, ordered into the timeline with their authoring date. Force-push can rewrite the entire commit timeline, so must invalidate all commits in the timeline. Could just make it completely git-based and skip storing in the DB entirely, but do whatever perform better, but a DB cache does bring the invalidation complexity. |
silverwind
left a comment
There was a problem hiding this comment.
Review by Claude on behalf of @silverwind
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses incorrect commit lists shown in pull request timeline “push” comments after a force-push by changing how commit IDs are collected for force-push events.
Changes:
- Update force-push handling to compute commit IDs from the PR base branch to the new head, instead of
oldCommitID..newCommitID. - Add a unit test case intended to cover force-push when the old commit is missing.
- Introduce
gitrepo.GetCommitIDsBetween()plus tests for it.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| services/pull/comment.go | Changes force-push commit range calculation to a base-ref → new-head comparison. |
| services/pull/comment_test.go | Adds a regression-oriented test for missing old commit in force-push. |
| modules/gitrepo/compare.go | Adds a helper to return commit IDs for a rev-list range. |
| modules/gitrepo/compare_test.go | Adds tests covering the new rev-list helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Fixes incorrect “pushed commits” timeline entries after force-pushes by changing how commit ranges are computed, adding a shared gitrepo helper, and extending tests around force-push behavior.
Changes:
- Adjust force-push push-comment behavior to recalculate commit IDs differently and to delete only non-force-push push comments.
- Add
gitrepo.GetCommitIDsBetween(with tests) to centralize commit-range retrieval. - Add
Comment.GetPushActionContentand expand pull push-comment tests for force-push scenarios.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| services/pull/comment.go | Changes push-comment commit ID computation and force-push deletion logic. |
| services/pull/comment_test.go | Adds/adjusts tests for force-push deletion and missing-old-commit scenarios. |
| modules/gitrepo/compare.go | Introduces GetCommitIDsBetween helper based on git rev-list. |
| modules/gitrepo/compare_test.go | Adds unit tests for GetCommitIDsBetween. |
| modules/git/repo_commit.go | Removes CommitsBetweenNotBase implementation. |
| models/issues/comment.go | Adds GetPushActionContent JSON decoder for PR push comment payloads. |
Comments suppressed due to low confidence (1)
services/pull/comment_test.go:173
- The
head-vs-base-branchsubtest validates comment counts, but it doesn't assert anything about the commit IDs captured in the non-force-push push comment created during a force-push. Given the bug being fixed is incorrect commit lists/counts after force-push, it would be good to fetch the non-force-push comment (whereis_force_pushis false) and assert that itscommit_idsmatch the expected PR commits and do not include base-only commits.
comment, err := CreatePushPullComment(t.Context(), pusher, pr, oldCommit.ID.String(), headCommit.ID.String(), true)
assert.NoError(t, err)
assert.NotNil(t, comment)
var createdData issues_model.PushActionContent
assert.NoError(t, json.Unmarshal([]byte(comment.Content), &createdData))
assert.True(t, createdData.IsForcePush)
comments, err = issues_model.FindComments(t.Context(), &issues_model.FindCommentsOptions{
IssueID: pr.IssueID,
Type: issues_model.CommentTypePullRequestPush,
})
assert.NoError(t, err)
// Two comments should exist now: one regular push comment and one force-push comment.
assert.Len(t, comments, 2)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
We can do nothing if unmarshal failed.
Renamed at 628d769
Renamed at 94345ee
We don't need to roll back here.
Fixed.
|
Review update (considering previous review)What's been addressed
What's still outstandingThe reconciliation approach is still overly complex.
Tests still don't cover the reconciliation logic. All test cases create old comments with empty New concerns
Multiple |
Tolerate corrupted database values, otherwise
json.Marshal never fails in these cases. |
It is also a right decision. @silverwind Can you please show your thoughts, instead of just copying AI slop? You should have your judgement, don't let AI slop waste everyone's time or mislead others.
|
I believe it also applies to the reviews & questions: if you are reviewing or questioning, the reviews and questions are from you, not an AI model. |
|
@lunny will you address #36914 (comment)?
My requirement is:
|
I don't understand your second requirement? I think the current behavior matched what Github did. |
silverwind
left a comment
There was a problem hiding this comment.
I guess it is an improvement, but should be iterated upon later.
|
Don't have time or motivation to dig deeper now, so I trust it is correct. |
|
I don't feel good with this |
|
I think we can merge this now. I could fix it if there is any bug. |
* main: Repair duration display for bad stopped timestamps (go-gitea#37121) Add terraform state registry (go-gitea#36710) Add placeholder content for empty content page (go-gitea#37114) Improve control char rendering and escape button styling (go-gitea#37094) Add gpg signing for merge rebase and update by rebase (go-gitea#36701) Move package settings to package instead of being tied to version (go-gitea#37026) Merge some standalone Vite entries into index.js (go-gitea#37085) Update Nix flake (go-gitea#37110) [skip ci] Updated translations via Crowdin Fix the wrong push commits in the pull request when force push (go-gitea#36914)

Fix #36905
The changes focus on force-push PR timeline handling and commit range calculation:
gitrepo.GetCommitIDsBetweenReversehelper, with special handling for force pushes (merge-base based range, tolerate missing/invalid old commits, and keep force-push timeline entries).Comment.GetPushActionContentto parse push comment payloads and used it to delete only non-force-push push comments during force pushes.Repository.CommitsBetweenNotBasehelper frommodules/git/repo_commit.goin favor of the new commit ID range helper.GetCommitIDsBetweenReverse(normal range,notReffiltering, fallback branch usage) and expanded pull comment tests to cover force-push edge cases.