Skip to content

Fix the wrong push commits in the pull request when force push#36914

Open
lunny wants to merge 8 commits intogo-gitea:mainfrom
lunny:lunny/fix_force_push
Open

Fix the wrong push commits in the pull request when force push#36914
lunny wants to merge 8 commits intogo-gitea:mainfrom
lunny:lunny/fix_force_push

Conversation

@lunny
Copy link
Member

@lunny lunny commented Mar 17, 2026

Fix #36905

  • Force-push push comments now compute commit IDs via a symmetric range against the base branch, while normal pushes use a linear range; force-
    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.
  • Introduces gitrepo.GetCommitIDsBetween to centralize commit-range retrieval (supports .. and ...) with unit tests.
    modules/gitrepo/compare.go:46 modules/gitrepo/compare_test.go:44
  • Adds Comment.GetPushActionContent for decoding PR push comment payloads to identify force-push entries. models/issues/comment.go:343
  • Expands pull comment tests to cover deletion behavior, missing old commit, and base/head branch scenarios. services/pull/comment_test.go:18

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 17, 2026
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Mar 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CreatePushPullComment to compute PR commit IDs via merge-base comparison against the base branch.
  • Add a new helper (GetCompareCommitIDsWithMergeBase) in services/git plus 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.

@wxiaoguang
Copy link
Contributor

Don't make it depends on "db"

Don't use func TestMain(m *testing.M) { unittest.MainTest(m) }

Why the simple git operation should depend on db?

@silverwind
Copy link
Member

silverwind commented Mar 17, 2026

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

This comment was marked as outdated.

Copy link
Member

@silverwind silverwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Claude on behalf of @silverwind

lunny and others added 3 commits March 17, 2026 14:03
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
@lunny lunny requested a review from Copilot March 18, 2026 22:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/v1.25 lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/go Pull requests that update Go code type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect commit count in timeline after force-push

5 participants