Skip to content

Commit 208cbd5

Browse files
authored
Fix bug when list pull request commits (go-gitea#36485)
Fix go-gitea#36483 In git log/rev-list, the "..." syntax represents the symmetric difference between two references, which is different from the meaning of "..." in git diff (where it implies diffing from the merge base). For listing PR commits, we must use `merge-base..head` to include only the commits introduced by the head branch. Otherwise, commits newly pushed to the base branch would also be included, which is incorrect.
1 parent de829c7 commit 208cbd5

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

services/git/compare.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
8484

8585
// We have a common base - therefore we know that ... should work
8686
if !fileOnly {
87-
compareInfo.Commits, err = headGitRepo.ShowPrettyFormatLogToList(ctx, compareInfo.BaseCommitID+compareInfo.CompareSeparator+compareInfo.HeadCommitID)
87+
// In git log/rev-list, the "..." syntax represents the symmetric difference between two references,
88+
// which is different from the meaning of "..." in git diff (where it implies diffing from the merge base).
89+
// For listing PR commits, we must use merge-base..head to include only the commits introduced by the head branch.
90+
// Otherwise, commits newly pushed to the base branch would also be included, which is incorrect.
91+
compareInfo.Commits, err = headGitRepo.ShowPrettyFormatLogToList(ctx, compareInfo.MergeBase+".."+compareInfo.HeadCommitID)
8892
if err != nil {
8993
return nil, fmt.Errorf("ShowPrettyFormatLogToList: %w", err)
9094
}

0 commit comments

Comments
 (0)