History

Fix pull request update showing too many commits with multiple branches (#22856)

When the base repository contains multiple branches with the same commits as the base branch, pull requests can show a long list of commits already in the base branch as having been added. What this is supposed to do is exclude commits already in the base branch. But the mechansim to do so assumed a commit only exists in a single branch. Now use `git rev-list A B --not branchName` instead of filtering commits afterwards. The logic to detect if there was a force push also was wrong for multiple branches. If the old commit existed in any branch in the base repository it would assume there was no force push. Instead check if the old commit is an ancestor of the new commit.

Brecht Van Lommel committed 3 years ago

Commit 8bdc0ac1 parent 689770c5 files · +49 −99Browse files

Showing the changes to modules/git/commit.go (1 of 5 files). Show all

Unified · Split

modules/git/commit.go+13−0
@@ -218,6 +218,19 @@ func (c *Commit) HasPreviousCommit(commitHash SHA1) (bool, error) { · 217 unmodified lines
218 return false, err218 return false, err
219}219}
220 220
221// IsForcePush returns true if a push from oldCommitHash to this is a force push
222func (c *Commit) IsForcePush(oldCommitID string) (bool, error) {
223 if oldCommitID == EmptySHA {
224 return false, nil
225 }
226 oldCommit, err := c.repo.GetCommit(oldCommitID)
227 if err != nil {
228 return false, err
229 }
230 hasPreviousCommit, err := c.HasPreviousCommit(oldCommit.ID)
231 return !hasPreviousCommit, err
232}
233
221// CommitsBeforeLimit returns num commits before current revision234// CommitsBeforeLimit returns num commits before current revision
222func (c *Commit) CommitsBeforeLimit(num int) ([]*Commit, error) {235func (c *Commit) CommitsBeforeLimit(num int) ([]*Commit, error) {
223 return c.repo.getCommitsBeforeLimit(c.ID, num)236 return c.repo.getCommitsBeforeLimit(c.ID, num)