Skip to content

Commit 66a148e

Browse files
authored
Restore detection of branches are equal on compare page (#14586)
Somehow the test for detecting if branches are equal broke this PR restores this functionality. Fix #14502 Signed-off-by: Andrew Thornton <[email protected]>
1 parent ebddee8 commit 66a148e

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

modules/git/repo_compare.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import (
2020

2121
// CompareInfo represents needed information for comparing references.
2222
type CompareInfo struct {
23-
MergeBase string
24-
Commits *list.List
25-
NumFiles int
23+
MergeBase string
24+
BaseCommitID string
25+
HeadCommitID string
26+
Commits *list.List
27+
NumFiles int
2628
}
2729

2830
// GetMergeBase checks and returns merge base of two branches and the reference used as base.
@@ -66,8 +68,18 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
6668
}
6769

6870
compareInfo := new(CompareInfo)
71+
72+
compareInfo.HeadCommitID, err = GetFullCommitID(repo.Path, headBranch)
73+
if err != nil {
74+
compareInfo.HeadCommitID = headBranch
75+
}
76+
6977
compareInfo.MergeBase, remoteBranch, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch)
7078
if err == nil {
79+
compareInfo.BaseCommitID, err = GetFullCommitID(repo.Path, remoteBranch)
80+
if err != nil {
81+
compareInfo.BaseCommitID = remoteBranch
82+
}
7183
// We have a common base - therefore we know that ... should work
7284
logs, err := NewCommand("log", compareInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
7385
if err != nil {
@@ -83,6 +95,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
8395
if err != nil {
8496
compareInfo.MergeBase = remoteBranch
8597
}
98+
compareInfo.BaseCommitID = compareInfo.MergeBase
8699
}
87100

88101
// Count number of changed files.

routers/repo/compare.go

+2-24
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,7 @@ func PrepareCompareDiff(
423423
// Get diff information.
424424
ctx.Data["CommitRepoLink"] = headRepo.Link()
425425

426-
headCommitID := headBranch
427-
if ctx.Data["HeadIsCommit"] == false {
428-
if ctx.Data["HeadIsTag"] == true {
429-
headCommitID, err = headGitRepo.GetTagCommitID(headBranch)
430-
} else {
431-
headCommitID, err = headGitRepo.GetBranchCommitID(headBranch)
432-
}
433-
if err != nil {
434-
ctx.ServerError("GetRefCommitID", err)
435-
return false
436-
}
437-
}
426+
headCommitID := compareInfo.HeadCommitID
438427

439428
ctx.Data["AfterCommitID"] = headCommitID
440429

@@ -460,18 +449,7 @@ func PrepareCompareDiff(
460449
}
461450

462451
baseGitRepo := ctx.Repo.GitRepo
463-
baseCommitID := baseBranch
464-
if ctx.Data["BaseIsCommit"] == false {
465-
if ctx.Data["BaseIsTag"] == true {
466-
baseCommitID, err = baseGitRepo.GetTagCommitID(baseBranch)
467-
} else {
468-
baseCommitID, err = baseGitRepo.GetBranchCommitID(baseBranch)
469-
}
470-
if err != nil {
471-
ctx.ServerError("GetRefCommitID", err)
472-
return false
473-
}
474-
}
452+
baseCommitID := compareInfo.BaseCommitID
475453

476454
baseCommit, err := baseGitRepo.GetCommit(baseCommitID)
477455
if err != nil {

0 commit comments

Comments
 (0)