Fix the wrong push commits in the pull request when force push#36914
Fix the wrong push commits in the pull request when force push#36914lunny wants to merge 8 commits intogo-gitea:mainfrom
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.
Fix #36905
pushes delete only non-force-push comments and tolerate missing old commits.
services/pull/comment.go:17. In a force-push scenario, oldCommitID refers to the commit that existed before the force push, so using it as the start of the range may miss relevant commits or produce incorrect results.gitrepo.GetCommitIDsBetweento centralize commit-range retrieval (supports..and...) with unit tests.modules/gitrepo/compare.go:46modules/gitrepo/compare_test.go:44Comment.GetPushActionContentfor decoding PR push comment payloads to identify force-push entries.models/issues/comment.go:343services/pull/comment_test.go:18