mirror of https://github.com/go-gitea/gitea.git
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 <art27@cantab.net>pull/14696/head
parent
ebddee8d2b
commit
66a148e398
|
@ -20,9 +20,11 @@ import (
|
||||||
|
|
||||||
// CompareInfo represents needed information for comparing references.
|
// CompareInfo represents needed information for comparing references.
|
||||||
type CompareInfo struct {
|
type CompareInfo struct {
|
||||||
MergeBase string
|
MergeBase string
|
||||||
Commits *list.List
|
BaseCommitID string
|
||||||
NumFiles int
|
HeadCommitID string
|
||||||
|
Commits *list.List
|
||||||
|
NumFiles int
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMergeBase checks and returns merge base of two branches and the reference used as base.
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
compareInfo := new(CompareInfo)
|
compareInfo := new(CompareInfo)
|
||||||
|
|
||||||
|
compareInfo.HeadCommitID, err = GetFullCommitID(repo.Path, headBranch)
|
||||||
|
if err != nil {
|
||||||
|
compareInfo.HeadCommitID = headBranch
|
||||||
|
}
|
||||||
|
|
||||||
compareInfo.MergeBase, remoteBranch, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch)
|
compareInfo.MergeBase, remoteBranch, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
compareInfo.BaseCommitID, err = GetFullCommitID(repo.Path, remoteBranch)
|
||||||
|
if err != nil {
|
||||||
|
compareInfo.BaseCommitID = remoteBranch
|
||||||
|
}
|
||||||
// We have a common base - therefore we know that ... should work
|
// We have a common base - therefore we know that ... should work
|
||||||
logs, err := NewCommand("log", compareInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
|
logs, err := NewCommand("log", compareInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -83,6 +95,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
compareInfo.MergeBase = remoteBranch
|
compareInfo.MergeBase = remoteBranch
|
||||||
}
|
}
|
||||||
|
compareInfo.BaseCommitID = compareInfo.MergeBase
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count number of changed files.
|
// Count number of changed files.
|
||||||
|
|
|
@ -423,18 +423,7 @@ func PrepareCompareDiff(
|
||||||
// Get diff information.
|
// Get diff information.
|
||||||
ctx.Data["CommitRepoLink"] = headRepo.Link()
|
ctx.Data["CommitRepoLink"] = headRepo.Link()
|
||||||
|
|
||||||
headCommitID := headBranch
|
headCommitID := compareInfo.HeadCommitID
|
||||||
if ctx.Data["HeadIsCommit"] == false {
|
|
||||||
if ctx.Data["HeadIsTag"] == true {
|
|
||||||
headCommitID, err = headGitRepo.GetTagCommitID(headBranch)
|
|
||||||
} else {
|
|
||||||
headCommitID, err = headGitRepo.GetBranchCommitID(headBranch)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("GetRefCommitID", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Data["AfterCommitID"] = headCommitID
|
ctx.Data["AfterCommitID"] = headCommitID
|
||||||
|
|
||||||
|
@ -460,18 +449,7 @@ func PrepareCompareDiff(
|
||||||
}
|
}
|
||||||
|
|
||||||
baseGitRepo := ctx.Repo.GitRepo
|
baseGitRepo := ctx.Repo.GitRepo
|
||||||
baseCommitID := baseBranch
|
baseCommitID := compareInfo.BaseCommitID
|
||||||
if ctx.Data["BaseIsCommit"] == false {
|
|
||||||
if ctx.Data["BaseIsTag"] == true {
|
|
||||||
baseCommitID, err = baseGitRepo.GetTagCommitID(baseBranch)
|
|
||||||
} else {
|
|
||||||
baseCommitID, err = baseGitRepo.GetBranchCommitID(baseBranch)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("GetRefCommitID", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
baseCommit, err := baseGitRepo.GetCommit(baseCommitID)
|
baseCommit, err := baseGitRepo.GetCommit(baseCommitID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue