improve the compare page (#36261)
- The compare page head title should be `compare` but not `new pull request`. - Use `UnstableGuessRefByShortName` instead of duplicated functions calls. - Direct-compare, tags, commits compare will not display `New Pull Request` button any more. The new screenshot <img width="1459" height="391" alt="image" src="https://github.com/user-attachments/assets/64e9b070-9c0b-41d1-b4b8-233b96270e1b" /> --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
98981eb749
commit
8373f7deb3
@ -220,3 +220,14 @@ func (ref RefName) RefWebLinkPath() string {
|
|||||||
}
|
}
|
||||||
return string(refType) + "/" + util.PathEscapeSegments(ref.ShortName())
|
return string(refType) + "/" + util.PathEscapeSegments(ref.ShortName())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseRefSuffix(ref string) (string, string) {
|
||||||
|
// Partially support https://git-scm.com/docs/gitrevisions
|
||||||
|
if idx := strings.Index(ref, "@{"); idx != -1 {
|
||||||
|
return ref[:idx], ref[idx:]
|
||||||
|
}
|
||||||
|
if idx := strings.Index(ref, "^"); idx != -1 {
|
||||||
|
return ref[:idx], ref[idx:]
|
||||||
|
}
|
||||||
|
return ref, ""
|
||||||
|
}
|
||||||
|
|||||||
@ -1736,8 +1736,11 @@
|
|||||||
"repo.issues.reference_link": "Reference: %s",
|
"repo.issues.reference_link": "Reference: %s",
|
||||||
"repo.compare.compare_base": "base",
|
"repo.compare.compare_base": "base",
|
||||||
"repo.compare.compare_head": "compare",
|
"repo.compare.compare_head": "compare",
|
||||||
|
"repo.compare.title": "Comparing changes",
|
||||||
|
"repo.compare.description": "Choose two branches or tags to see what’s changed or to start a new pull request.",
|
||||||
"repo.pulls.desc": "Enable pull requests and code reviews.",
|
"repo.pulls.desc": "Enable pull requests and code reviews.",
|
||||||
"repo.pulls.new": "New Pull Request",
|
"repo.pulls.new": "New Pull Request",
|
||||||
|
"repo.pulls.new.description": "Discuss and review the changes in this comparison with others.",
|
||||||
"repo.pulls.new.blocked_user": "Cannot create pull request because you are blocked by the repository owner.",
|
"repo.pulls.new.blocked_user": "Cannot create pull request because you are blocked by the repository owner.",
|
||||||
"repo.pulls.new.must_collaborator": "You must be a collaborator to create pull request.",
|
"repo.pulls.new.must_collaborator": "You must be a collaborator to create pull request.",
|
||||||
"repo.pulls.new.already_existed": "A pull request between these branches already exists",
|
"repo.pulls.new.already_existed": "A pull request between these branches already exists",
|
||||||
@ -1747,7 +1750,6 @@
|
|||||||
"repo.pulls.allow_edits_from_maintainers": "Allow edits from maintainers",
|
"repo.pulls.allow_edits_from_maintainers": "Allow edits from maintainers",
|
||||||
"repo.pulls.allow_edits_from_maintainers_desc": "Users with write access to the base branch can also push to this branch",
|
"repo.pulls.allow_edits_from_maintainers_desc": "Users with write access to the base branch can also push to this branch",
|
||||||
"repo.pulls.allow_edits_from_maintainers_err": "Updating failed",
|
"repo.pulls.allow_edits_from_maintainers_err": "Updating failed",
|
||||||
"repo.pulls.compare_changes_desc": "Select the branch to merge into and the branch to pull from.",
|
|
||||||
"repo.pulls.has_viewed_file": "Viewed",
|
"repo.pulls.has_viewed_file": "Viewed",
|
||||||
"repo.pulls.has_changed_since_last_review": "Changed since your last review",
|
"repo.pulls.has_changed_since_last_review": "Changed since your last review",
|
||||||
"repo.pulls.viewed_files_label": "%[1]d / %[2]d files viewed",
|
"repo.pulls.viewed_files_label": "%[1]d / %[2]d files viewed",
|
||||||
|
|||||||
@ -1062,19 +1062,11 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||||||
// parseCompareInfo returns non-nil if it succeeds, it always writes to the context and returns nil if it fails
|
// parseCompareInfo returns non-nil if it succeeds, it always writes to the context and returns nil if it fails
|
||||||
func parseCompareInfo(ctx *context.APIContext, compareParam string) (result *git_service.CompareInfo, closer func()) {
|
func parseCompareInfo(ctx *context.APIContext, compareParam string) (result *git_service.CompareInfo, closer func()) {
|
||||||
baseRepo := ctx.Repo.Repository
|
baseRepo := ctx.Repo.Repository
|
||||||
compareReq, err := common.ParseCompareRouterParam(compareParam)
|
compareReq := common.ParseCompareRouterParam(compareParam)
|
||||||
switch {
|
|
||||||
case errors.Is(err, util.ErrInvalidArgument):
|
|
||||||
ctx.APIError(http.StatusBadRequest, err.Error())
|
|
||||||
return nil, nil
|
|
||||||
case err != nil:
|
|
||||||
ctx.APIErrorInternal(err)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove the check when we support compare with carets
|
// remove the check when we support compare with carets
|
||||||
if compareReq.CaretTimes > 0 {
|
if compareReq.BaseOriRefSuffix != "" {
|
||||||
ctx.APIError(http.StatusBadRequest, "Unsupported compare syntax with carets")
|
ctx.APIError(http.StatusBadRequest, "Unsupported comparison syntax: ref with suffix")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,31 +9,28 @@ import (
|
|||||||
|
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CompareRouterReq struct {
|
type CompareRouterReq struct {
|
||||||
BaseOriRef string
|
BaseOriRef string
|
||||||
|
BaseOriRefSuffix string
|
||||||
|
|
||||||
|
CompareSeparator string
|
||||||
|
|
||||||
HeadOwner string
|
HeadOwner string
|
||||||
HeadRepoName string
|
HeadRepoName string
|
||||||
HeadOriRef string
|
HeadOriRef string
|
||||||
CaretTimes int // ^ times after base ref
|
|
||||||
DotTimes int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *CompareRouterReq) DirectComparison() bool {
|
func (cr *CompareRouterReq) DirectComparison() bool {
|
||||||
return cr.DotTimes == 2 || cr.DotTimes == 0
|
// FIXME: the design of "DirectComparison" is wrong, it loses the information of `^`
|
||||||
|
// To correctly handle the comparison, developers should use `ci.CompareSeparator` directly, all "DirectComparison" related code should be rewritten.
|
||||||
|
return cr.CompareSeparator == ".."
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseBase(base string) (string, int) {
|
func parseHead(head string) (headOwnerName, headRepoName, headRef string) {
|
||||||
parts := strings.SplitN(base, "^", 2)
|
|
||||||
if len(parts) == 1 {
|
|
||||||
return base, 0
|
|
||||||
}
|
|
||||||
return parts[0], len(parts[1]) + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseHead(head string) (string, string, string) {
|
|
||||||
paths := strings.SplitN(head, ":", 2)
|
paths := strings.SplitN(head, ":", 2)
|
||||||
if len(paths) == 1 {
|
if len(paths) == 1 {
|
||||||
return "", "", paths[0]
|
return "", "", paths[0]
|
||||||
@ -48,6 +45,7 @@ func parseHead(head string) (string, string, string) {
|
|||||||
// ParseCompareRouterParam Get compare information from the router parameter.
|
// ParseCompareRouterParam Get compare information from the router parameter.
|
||||||
// A full compare url is of the form:
|
// A full compare url is of the form:
|
||||||
//
|
//
|
||||||
|
// 0. /{:baseOwner}/{:baseRepoName}/compare
|
||||||
// 1. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headBranch}
|
// 1. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headBranch}
|
||||||
// 2. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}:{:headBranch}
|
// 2. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}:{:headBranch}
|
||||||
// 3. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}/{:headRepoName}:{:headBranch}
|
// 3. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}/{:headRepoName}:{:headBranch}
|
||||||
@ -70,45 +68,31 @@ func parseHead(head string) (string, string, string) {
|
|||||||
// format: <base branch>...[<head repo>:]<head branch>
|
// format: <base branch>...[<head repo>:]<head branch>
|
||||||
// base<-head: master...head:feature
|
// base<-head: master...head:feature
|
||||||
// same repo: master...feature
|
// same repo: master...feature
|
||||||
func ParseCompareRouterParam(routerParam string) (*CompareRouterReq, error) {
|
func ParseCompareRouterParam(routerParam string) *CompareRouterReq {
|
||||||
if routerParam == "" {
|
if routerParam == "" {
|
||||||
return &CompareRouterReq{}, nil
|
return &CompareRouterReq{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var basePart, headPart string
|
sep := "..."
|
||||||
dotTimes := 3
|
basePart, headPart, ok := strings.Cut(routerParam, sep)
|
||||||
parts := strings.Split(routerParam, "...")
|
if !ok {
|
||||||
if len(parts) > 2 {
|
sep = ".."
|
||||||
return nil, util.NewInvalidArgumentErrorf("invalid compare router: %s", routerParam)
|
basePart, headPart, ok = strings.Cut(routerParam, sep)
|
||||||
}
|
if !ok {
|
||||||
if len(parts) != 2 {
|
|
||||||
parts = strings.Split(routerParam, "..")
|
|
||||||
if len(parts) == 1 {
|
|
||||||
headOwnerName, headRepoName, headRef := parseHead(routerParam)
|
headOwnerName, headRepoName, headRef := parseHead(routerParam)
|
||||||
return &CompareRouterReq{
|
return &CompareRouterReq{
|
||||||
HeadOriRef: headRef,
|
HeadOriRef: headRef,
|
||||||
HeadOwner: headOwnerName,
|
HeadOwner: headOwnerName,
|
||||||
HeadRepoName: headRepoName,
|
HeadRepoName: headRepoName,
|
||||||
DotTimes: dotTimes,
|
CompareSeparator: "...",
|
||||||
}, nil
|
}
|
||||||
} else if len(parts) > 2 {
|
|
||||||
return nil, util.NewInvalidArgumentErrorf("invalid compare router: %s", routerParam)
|
|
||||||
}
|
}
|
||||||
dotTimes = 2
|
|
||||||
}
|
}
|
||||||
basePart, headPart = parts[0], parts[1]
|
|
||||||
|
|
||||||
baseRef, caretTimes := parseBase(basePart)
|
ci := &CompareRouterReq{CompareSeparator: sep}
|
||||||
headOwnerName, headRepoName, headRef := parseHead(headPart)
|
ci.BaseOriRef, ci.BaseOriRefSuffix = git.ParseRefSuffix(basePart)
|
||||||
|
ci.HeadOwner, ci.HeadRepoName, ci.HeadOriRef = parseHead(headPart)
|
||||||
return &CompareRouterReq{
|
return ci
|
||||||
BaseOriRef: baseRef,
|
|
||||||
HeadOriRef: headRef,
|
|
||||||
HeadOwner: headOwnerName,
|
|
||||||
HeadRepoName: headRepoName,
|
|
||||||
CaretTimes: caretTimes,
|
|
||||||
DotTimes: dotTimes,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// maxForkTraverseLevel defines the maximum levels to traverse when searching for the head repository.
|
// maxForkTraverseLevel defines the maximum levels to traverse when searching for the head repository.
|
||||||
|
|||||||
@ -6,146 +6,100 @@ package common
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/unittest"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCompareRouterReq(t *testing.T) {
|
func TestCompareRouterReq(t *testing.T) {
|
||||||
unittest.PrepareTestEnv(t)
|
cases := []struct {
|
||||||
|
input string
|
||||||
kases := []struct {
|
|
||||||
router string
|
|
||||||
CompareRouterReq *CompareRouterReq
|
CompareRouterReq *CompareRouterReq
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
router: "",
|
input: "",
|
||||||
|
CompareRouterReq: &CompareRouterReq{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "v1.0...v1.1",
|
||||||
CompareRouterReq: &CompareRouterReq{
|
CompareRouterReq: &CompareRouterReq{
|
||||||
BaseOriRef: "",
|
BaseOriRef: "v1.0",
|
||||||
HeadOriRef: "",
|
CompareSeparator: "...",
|
||||||
DotTimes: 0,
|
HeadOriRef: "v1.1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
router: "main...develop",
|
input: "main..develop",
|
||||||
CompareRouterReq: &CompareRouterReq{
|
CompareRouterReq: &CompareRouterReq{
|
||||||
BaseOriRef: "main",
|
BaseOriRef: "main",
|
||||||
HeadOriRef: "develop",
|
CompareSeparator: "..",
|
||||||
DotTimes: 3,
|
HeadOriRef: "develop",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
router: "main..develop",
|
input: "main^...develop",
|
||||||
CompareRouterReq: &CompareRouterReq{
|
CompareRouterReq: &CompareRouterReq{
|
||||||
BaseOriRef: "main",
|
BaseOriRef: "main",
|
||||||
HeadOriRef: "develop",
|
BaseOriRefSuffix: "^",
|
||||||
DotTimes: 2,
|
CompareSeparator: "...",
|
||||||
|
HeadOriRef: "develop",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
router: "main^...develop",
|
input: "main^^^^^...develop",
|
||||||
CompareRouterReq: &CompareRouterReq{
|
CompareRouterReq: &CompareRouterReq{
|
||||||
BaseOriRef: "main",
|
BaseOriRef: "main",
|
||||||
HeadOriRef: "develop",
|
BaseOriRefSuffix: "^^^^^",
|
||||||
CaretTimes: 1,
|
CompareSeparator: "...",
|
||||||
DotTimes: 3,
|
HeadOriRef: "develop",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
router: "main^^^^^...develop",
|
input: "develop",
|
||||||
CompareRouterReq: &CompareRouterReq{
|
CompareRouterReq: &CompareRouterReq{
|
||||||
BaseOriRef: "main",
|
CompareSeparator: "...",
|
||||||
HeadOriRef: "develop",
|
HeadOriRef: "develop",
|
||||||
CaretTimes: 5,
|
|
||||||
DotTimes: 3,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
router: "develop",
|
input: "teabot:feature1",
|
||||||
CompareRouterReq: &CompareRouterReq{
|
CompareRouterReq: &CompareRouterReq{
|
||||||
HeadOriRef: "develop",
|
CompareSeparator: "...",
|
||||||
DotTimes: 3,
|
HeadOwner: "teabot",
|
||||||
|
HeadOriRef: "feature1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
router: "lunny/forked_repo:develop",
|
input: "lunny/forked_repo:develop",
|
||||||
CompareRouterReq: &CompareRouterReq{
|
CompareRouterReq: &CompareRouterReq{
|
||||||
HeadOwner: "lunny",
|
CompareSeparator: "...",
|
||||||
HeadRepoName: "forked_repo",
|
HeadOwner: "lunny",
|
||||||
HeadOriRef: "develop",
|
HeadRepoName: "forked_repo",
|
||||||
DotTimes: 3,
|
HeadOriRef: "develop",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
router: "main...lunny/forked_repo:develop",
|
input: "main...lunny/forked_repo:develop",
|
||||||
CompareRouterReq: &CompareRouterReq{
|
CompareRouterReq: &CompareRouterReq{
|
||||||
BaseOriRef: "main",
|
BaseOriRef: "main",
|
||||||
HeadOwner: "lunny",
|
CompareSeparator: "...",
|
||||||
HeadRepoName: "forked_repo",
|
HeadOwner: "lunny",
|
||||||
HeadOriRef: "develop",
|
HeadRepoName: "forked_repo",
|
||||||
DotTimes: 3,
|
HeadOriRef: "develop",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
router: "main...lunny/forked_repo:develop",
|
input: "main^...lunny/forked_repo:develop",
|
||||||
CompareRouterReq: &CompareRouterReq{
|
CompareRouterReq: &CompareRouterReq{
|
||||||
BaseOriRef: "main",
|
BaseOriRef: "main",
|
||||||
HeadOwner: "lunny",
|
BaseOriRefSuffix: "^",
|
||||||
HeadRepoName: "forked_repo",
|
CompareSeparator: "...",
|
||||||
HeadOriRef: "develop",
|
HeadOwner: "lunny",
|
||||||
DotTimes: 3,
|
HeadRepoName: "forked_repo",
|
||||||
},
|
HeadOriRef: "develop",
|
||||||
},
|
|
||||||
{
|
|
||||||
router: "main^...lunny/forked_repo:develop",
|
|
||||||
CompareRouterReq: &CompareRouterReq{
|
|
||||||
BaseOriRef: "main",
|
|
||||||
HeadOwner: "lunny",
|
|
||||||
HeadRepoName: "forked_repo",
|
|
||||||
HeadOriRef: "develop",
|
|
||||||
DotTimes: 3,
|
|
||||||
CaretTimes: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
router: "v1.0...v1.1",
|
|
||||||
CompareRouterReq: &CompareRouterReq{
|
|
||||||
BaseOriRef: "v1.0",
|
|
||||||
HeadOriRef: "v1.1",
|
|
||||||
DotTimes: 3,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
router: "teabot-patch-1...v0.0.1",
|
|
||||||
CompareRouterReq: &CompareRouterReq{
|
|
||||||
BaseOriRef: "teabot-patch-1",
|
|
||||||
HeadOriRef: "v0.0.1",
|
|
||||||
DotTimes: 3,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
router: "teabot:feature1",
|
|
||||||
CompareRouterReq: &CompareRouterReq{
|
|
||||||
HeadOwner: "teabot",
|
|
||||||
HeadOriRef: "feature1",
|
|
||||||
DotTimes: 3,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
router: "8eb19a5ae19abae15c0666d4ab98906139a7f439...283c030497b455ecfa759d4649f9f8b45158742e",
|
|
||||||
CompareRouterReq: &CompareRouterReq{
|
|
||||||
BaseOriRef: "8eb19a5ae19abae15c0666d4ab98906139a7f439",
|
|
||||||
HeadOriRef: "283c030497b455ecfa759d4649f9f8b45158742e",
|
|
||||||
DotTimes: 3,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, kase := range kases {
|
for _, c := range cases {
|
||||||
t.Run(kase.router, func(t *testing.T) {
|
assert.Equal(t, c.CompareRouterReq, ParseCompareRouterParam(c.input), "input: %s", c.input)
|
||||||
r, err := ParseCompareRouterParam(kase.router)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, kase.CompareRouterReq, r)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -196,21 +196,16 @@ func ParseCompareInfo(ctx *context.Context) *git_service.CompareInfo {
|
|||||||
baseRepo := ctx.Repo.Repository
|
baseRepo := ctx.Repo.Repository
|
||||||
fileOnly := ctx.FormBool("file-only")
|
fileOnly := ctx.FormBool("file-only")
|
||||||
|
|
||||||
compareReq, err := common.ParseCompareRouterParam(ctx.PathParam("*"))
|
// 1 Parse compare router param
|
||||||
switch {
|
compareReq := common.ParseCompareRouterParam(ctx.PathParam("*"))
|
||||||
case errors.Is(err, util.ErrInvalidArgument):
|
|
||||||
ctx.HTTPError(http.StatusBadRequest, err.Error())
|
|
||||||
return nil
|
|
||||||
case err != nil:
|
|
||||||
ctx.ServerError("ParseCompareRouterParam", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// remove the check when we support compare with carets
|
// remove the check when we support compare with carets
|
||||||
if compareReq.CaretTimes > 0 {
|
if compareReq.BaseOriRefSuffix != "" {
|
||||||
ctx.HTTPError(http.StatusBadRequest, "Unsupported compare syntax with carets")
|
ctx.HTTPError(http.StatusBadRequest, "Unsupported comparison syntax: ref with suffix")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2 get repository and owner for head
|
||||||
headOwner, headRepo, err := common.GetHeadOwnerAndRepo(ctx, baseRepo, compareReq)
|
headOwner, headRepo, err := common.GetHeadOwnerAndRepo(ctx, baseRepo, compareReq)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, util.ErrInvalidArgument):
|
case errors.Is(err, util.ErrInvalidArgument):
|
||||||
@ -224,45 +219,66 @@ func ParseCompareInfo(ctx *context.Context) *git_service.CompareInfo {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
baseBranch := util.IfZero(compareReq.BaseOriRef, baseRepo.DefaultBranch)
|
|
||||||
headBranch := util.IfZero(compareReq.HeadOriRef, headRepo.DefaultBranch)
|
|
||||||
isSameRepo := baseRepo.ID == headRepo.ID
|
isSameRepo := baseRepo.ID == headRepo.ID
|
||||||
|
|
||||||
ctx.Data["BaseName"] = baseRepo.OwnerName
|
// 3 permission check
|
||||||
ctx.Data["BaseBranch"] = baseBranch
|
// base repository's code unit read permission check has been done on web.go
|
||||||
ctx.Data["HeadUser"] = headOwner
|
permBase := ctx.Repo.Permission
|
||||||
ctx.Data["HeadBranch"] = headBranch
|
|
||||||
ctx.Repo.PullRequest.SameRepo = isSameRepo
|
|
||||||
|
|
||||||
// Check if base branch is valid.
|
// If we're not merging from the same repo:
|
||||||
baseIsCommit := ctx.Repo.GitRepo.IsCommitExist(baseBranch)
|
if !isSameRepo {
|
||||||
baseIsBranch, _ := git_model.IsBranchExist(ctx, ctx.Repo.Repository.ID, baseBranch)
|
// Assert ctx.Doer has permission to read headRepo's codes
|
||||||
baseIsTag := gitrepo.IsTagExist(ctx, ctx.Repo.Repository, baseBranch)
|
permHead, err := access_model.GetUserRepoPermission(ctx, headRepo, ctx.Doer)
|
||||||
|
if err != nil {
|
||||||
if !baseIsCommit && !baseIsBranch && !baseIsTag {
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
// Check if baseBranch is short sha commit hash
|
|
||||||
if baseCommit, _ := ctx.Repo.GitRepo.GetCommit(baseBranch); baseCommit != nil {
|
|
||||||
baseBranch = baseCommit.ID.String()
|
|
||||||
ctx.Data["BaseBranch"] = baseBranch
|
|
||||||
baseIsCommit = true
|
|
||||||
} else if baseBranch == ctx.Repo.GetObjectFormat().EmptyObjectID().String() {
|
|
||||||
if isSameRepo {
|
|
||||||
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + util.PathEscapeSegments(headBranch))
|
|
||||||
} else {
|
|
||||||
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + util.PathEscapeSegments(headRepo.FullName()) + ":" + util.PathEscapeSegments(headBranch))
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
} else {
|
}
|
||||||
|
if !permHead.CanRead(unit.TypeCode) {
|
||||||
|
if log.IsTrace() {
|
||||||
|
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v",
|
||||||
|
ctx.Doer,
|
||||||
|
headRepo,
|
||||||
|
permHead)
|
||||||
|
}
|
||||||
ctx.NotFound(nil)
|
ctx.NotFound(nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
ctx.Data["CanWriteToHeadRepo"] = permHead.CanWrite(unit.TypeCode)
|
||||||
}
|
}
|
||||||
ctx.Data["BaseIsCommit"] = baseIsCommit
|
|
||||||
ctx.Data["BaseIsBranch"] = baseIsBranch
|
|
||||||
ctx.Data["BaseIsTag"] = baseIsTag
|
|
||||||
ctx.Data["IsPull"] = true
|
|
||||||
|
|
||||||
// Now we have the repository that represents the base
|
// 4 get base and head refs
|
||||||
|
baseRefName := util.IfZero(compareReq.BaseOriRef, baseRepo.DefaultBranch)
|
||||||
|
headRefName := util.IfZero(compareReq.HeadOriRef, headRepo.DefaultBranch)
|
||||||
|
|
||||||
|
baseRef := ctx.Repo.GitRepo.UnstableGuessRefByShortName(baseRefName)
|
||||||
|
if baseRef == "" {
|
||||||
|
ctx.NotFound(nil)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var headGitRepo *git.Repository
|
||||||
|
if isSameRepo {
|
||||||
|
headGitRepo = ctx.Repo.GitRepo
|
||||||
|
} else {
|
||||||
|
headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo)
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("OpenRepository", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer headGitRepo.Close()
|
||||||
|
}
|
||||||
|
headRef := headGitRepo.UnstableGuessRefByShortName(headRefName)
|
||||||
|
if headRef == "" {
|
||||||
|
ctx.NotFound(nil)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Data["BaseName"] = baseRepo.OwnerName
|
||||||
|
ctx.Data["BaseBranch"] = baseRef.ShortName() // for legacy templates
|
||||||
|
ctx.Data["HeadUser"] = headOwner
|
||||||
|
ctx.Data["HeadBranch"] = headRef.ShortName() // for legacy templates
|
||||||
|
ctx.Repo.PullRequest.SameRepo = isSameRepo
|
||||||
|
|
||||||
|
ctx.Data["IsPull"] = true
|
||||||
|
|
||||||
// The current base and head repositories and branches may not
|
// The current base and head repositories and branches may not
|
||||||
// actually be the intended branches that the user wants to
|
// actually be the intended branches that the user wants to
|
||||||
@ -331,64 +347,9 @@ func ParseCompareInfo(ctx *context.Context) *git_service.CompareInfo {
|
|||||||
ctx.Data["PageIsComparePull"] = false
|
ctx.Data["PageIsComparePull"] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. Finally open the git repo
|
|
||||||
var headGitRepo *git.Repository
|
|
||||||
if isSameRepo {
|
|
||||||
headGitRepo = ctx.Repo.GitRepo
|
|
||||||
} else if has {
|
|
||||||
headGitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, headRepo)
|
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("RepositoryFromRequestContextOrOpen", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ctx.NotFound(nil)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Data["HeadRepo"] = headRepo
|
ctx.Data["HeadRepo"] = headRepo
|
||||||
ctx.Data["BaseCompareRepo"] = ctx.Repo.Repository
|
ctx.Data["BaseCompareRepo"] = ctx.Repo.Repository
|
||||||
|
|
||||||
// Now we need to assert that the ctx.Doer has permission to read
|
|
||||||
// the baseRepo's code and pulls
|
|
||||||
// (NOT headRepo's)
|
|
||||||
permBase, err := access_model.GetUserRepoPermission(ctx, baseRepo, ctx.Doer)
|
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if !permBase.CanRead(unit.TypeCode) {
|
|
||||||
if log.IsTrace() {
|
|
||||||
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in baseRepo has Permissions: %-+v",
|
|
||||||
ctx.Doer,
|
|
||||||
baseRepo,
|
|
||||||
permBase)
|
|
||||||
}
|
|
||||||
ctx.NotFound(nil)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're not merging from the same repo:
|
|
||||||
if !isSameRepo {
|
|
||||||
// Assert ctx.Doer has permission to read headRepo's codes
|
|
||||||
permHead, err := access_model.GetUserRepoPermission(ctx, headRepo, ctx.Doer)
|
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if !permHead.CanRead(unit.TypeCode) {
|
|
||||||
if log.IsTrace() {
|
|
||||||
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v",
|
|
||||||
ctx.Doer,
|
|
||||||
headRepo,
|
|
||||||
permHead)
|
|
||||||
}
|
|
||||||
ctx.NotFound(nil)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
ctx.Data["CanWriteToHeadRepo"] = permHead.CanWrite(unit.TypeCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have a rootRepo and it's different from:
|
// If we have a rootRepo and it's different from:
|
||||||
// 1. the computed base
|
// 1. the computed base
|
||||||
// 2. the computed head
|
// 2. the computed head
|
||||||
@ -436,28 +397,9 @@ func ParseCompareInfo(ctx *context.Context) *git_service.CompareInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if head branch is valid.
|
|
||||||
headIsCommit := headGitRepo.IsCommitExist(headBranch)
|
|
||||||
headIsBranch, _ := git_model.IsBranchExist(ctx, headRepo.ID, headBranch)
|
|
||||||
headIsTag := gitrepo.IsTagExist(ctx, headRepo, headBranch)
|
|
||||||
if !headIsCommit && !headIsBranch && !headIsTag {
|
|
||||||
// Check if headBranch is short sha commit hash
|
|
||||||
if headCommit, _ := headGitRepo.GetCommit(headBranch); headCommit != nil {
|
|
||||||
headBranch = headCommit.ID.String()
|
|
||||||
ctx.Data["HeadBranch"] = headBranch
|
|
||||||
headIsCommit = true
|
|
||||||
} else {
|
|
||||||
ctx.NotFound(nil)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ctx.Data["HeadIsCommit"] = headIsCommit
|
|
||||||
ctx.Data["HeadIsBranch"] = headIsBranch
|
|
||||||
ctx.Data["HeadIsTag"] = headIsTag
|
|
||||||
|
|
||||||
// Treat as pull request if both references are branches
|
// Treat as pull request if both references are branches
|
||||||
if ctx.Data["PageIsComparePull"] == nil {
|
if ctx.Data["PageIsComparePull"] == nil {
|
||||||
ctx.Data["PageIsComparePull"] = headIsBranch && baseIsBranch && permBase.CanReadIssuesOrPulls(true)
|
ctx.Data["PageIsComparePull"] = baseRef.IsBranch() && headRef.IsBranch() && permBase.CanReadIssuesOrPulls(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Data["PageIsComparePull"] == true && !permBase.CanReadIssuesOrPulls(true) {
|
if ctx.Data["PageIsComparePull"] == true && !permBase.CanReadIssuesOrPulls(true) {
|
||||||
@ -471,20 +413,7 @@ func ParseCompareInfo(ctx *context.Context) *git_service.CompareInfo {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
baseBranchRef := git.RefName(baseBranch)
|
compareInfo, err := git_service.GetCompareInfo(ctx, baseRepo, headRepo, headGitRepo, baseRef, headRef, compareReq.DirectComparison(), fileOnly)
|
||||||
if baseIsBranch {
|
|
||||||
baseBranchRef = git.RefNameFromBranch(baseBranch)
|
|
||||||
} else if baseIsTag {
|
|
||||||
baseBranchRef = git.RefNameFromTag(baseBranch)
|
|
||||||
}
|
|
||||||
headBranchRef := git.RefName(headBranch)
|
|
||||||
if headIsBranch {
|
|
||||||
headBranchRef = git.RefNameFromBranch(headBranch)
|
|
||||||
} else if headIsTag {
|
|
||||||
headBranchRef = git.RefNameFromTag(headBranch)
|
|
||||||
}
|
|
||||||
|
|
||||||
compareInfo, err := git_service.GetCompareInfo(ctx, baseRepo, headRepo, headGitRepo, baseBranchRef, headBranchRef, compareReq.DirectComparison(), fileOnly)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetCompareInfo", err)
|
ctx.ServerError("GetCompareInfo", err)
|
||||||
return nil
|
return nil
|
||||||
@ -517,7 +446,7 @@ func PrepareCompareDiff(
|
|||||||
ctx.Data["TitleQuery"] = newPrFormTitle
|
ctx.Data["TitleQuery"] = newPrFormTitle
|
||||||
ctx.Data["BodyQuery"] = newPrFormBody
|
ctx.Data["BodyQuery"] = newPrFormBody
|
||||||
|
|
||||||
if (headCommitID == ci.MergeBase && !ci.DirectComparison) ||
|
if (headCommitID == ci.MergeBase && !ci.DirectComparison()) ||
|
||||||
headCommitID == ci.BaseCommitID {
|
headCommitID == ci.BaseCommitID {
|
||||||
ctx.Data["IsNothingToCompare"] = true
|
ctx.Data["IsNothingToCompare"] = true
|
||||||
if unit, err := repo.GetUnit(ctx, unit.TypePullRequests); err == nil {
|
if unit, err := repo.GetUnit(ctx, unit.TypePullRequests); err == nil {
|
||||||
@ -534,7 +463,7 @@ func PrepareCompareDiff(
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeCommitID := ci.MergeBase
|
beforeCommitID := ci.MergeBase
|
||||||
if ci.DirectComparison {
|
if ci.DirectComparison() {
|
||||||
beforeCommitID = ci.BaseCommitID
|
beforeCommitID = ci.BaseCommitID
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,7 +484,7 @@ func PrepareCompareDiff(
|
|||||||
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
|
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
|
||||||
MaxFiles: maxFiles,
|
MaxFiles: maxFiles,
|
||||||
WhitespaceBehavior: whitespaceBehavior,
|
WhitespaceBehavior: whitespaceBehavior,
|
||||||
DirectComparison: ci.DirectComparison,
|
DirectComparison: ci.DirectComparison(),
|
||||||
}, ctx.FormStrings("files")...)
|
}, ctx.FormStrings("files")...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetDiff", err)
|
ctx.ServerError("GetDiff", err)
|
||||||
@ -668,13 +597,7 @@ func CompareDiff(ctx *context.Context) {
|
|||||||
|
|
||||||
ctx.Data["PageIsViewCode"] = true
|
ctx.Data["PageIsViewCode"] = true
|
||||||
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
||||||
ctx.Data["DirectComparison"] = ci.DirectComparison
|
ctx.Data["CompareInfo"] = ci
|
||||||
ctx.Data["OtherCompareSeparator"] = ".."
|
|
||||||
ctx.Data["CompareSeparator"] = "..."
|
|
||||||
if ci.DirectComparison {
|
|
||||||
ctx.Data["CompareSeparator"] = ".."
|
|
||||||
ctx.Data["OtherCompareSeparator"] = "..."
|
|
||||||
}
|
|
||||||
|
|
||||||
nothingToCompare := PrepareCompareDiff(ctx, ci, gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)))
|
nothingToCompare := PrepareCompareDiff(ctx, ci, gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)))
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
@ -751,11 +674,7 @@ func CompareDiff(ctx *context.Context) {
|
|||||||
beforeCommitID := ctx.Data["BeforeCommitID"].(string)
|
beforeCommitID := ctx.Data["BeforeCommitID"].(string)
|
||||||
afterCommitID := ctx.Data["AfterCommitID"].(string)
|
afterCommitID := ctx.Data["AfterCommitID"].(string)
|
||||||
|
|
||||||
separator := "..."
|
ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + ci.CompareSeparator + base.ShortSha(afterCommitID)
|
||||||
if ci.DirectComparison {
|
|
||||||
separator = ".."
|
|
||||||
}
|
|
||||||
ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + separator + base.ShortSha(afterCommitID)
|
|
||||||
|
|
||||||
ctx.Data["IsDiffCompare"] = true
|
ctx.Data["IsDiffCompare"] = true
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/gitrepo"
|
"code.gitea.io/gitea/modules/gitrepo"
|
||||||
"code.gitea.io/gitea/modules/graceful"
|
"code.gitea.io/gitea/modules/graceful"
|
||||||
logger "code.gitea.io/gitea/modules/log"
|
logger "code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CompareInfo represents needed information for comparing references.
|
// CompareInfo represents needed information for comparing references.
|
||||||
@ -25,7 +26,7 @@ type CompareInfo struct {
|
|||||||
HeadGitRepo *git.Repository
|
HeadGitRepo *git.Repository
|
||||||
HeadRef git.RefName
|
HeadRef git.RefName
|
||||||
HeadCommitID string
|
HeadCommitID string
|
||||||
DirectComparison bool
|
CompareSeparator string
|
||||||
MergeBase string
|
MergeBase string
|
||||||
Commits []*git.Commit
|
Commits []*git.Commit
|
||||||
NumFiles int
|
NumFiles int
|
||||||
@ -39,6 +40,12 @@ func (ci *CompareInfo) IsSameRef() bool {
|
|||||||
return ci.IsSameRepository() && ci.BaseRef == ci.HeadRef
|
return ci.IsSameRepository() && ci.BaseRef == ci.HeadRef
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ci *CompareInfo) DirectComparison() bool {
|
||||||
|
// FIXME: the design of "DirectComparison" is wrong, it loses the information of `^`
|
||||||
|
// To correctly handle the comparison, developers should use `ci.CompareSeparator` directly, all "DirectComparison" related code should be rewritten.
|
||||||
|
return ci.CompareSeparator == ".."
|
||||||
|
}
|
||||||
|
|
||||||
// GetCompareInfo generates and returns compare information between base and head branches of repositories.
|
// GetCompareInfo generates and returns compare information between base and head branches of repositories.
|
||||||
func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Repository, headGitRepo *git.Repository, baseRef, headRef git.RefName, directComparison, fileOnly bool) (_ *CompareInfo, err error) {
|
func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Repository, headGitRepo *git.Repository, baseRef, headRef git.RefName, directComparison, fileOnly bool) (_ *CompareInfo, err error) {
|
||||||
var (
|
var (
|
||||||
@ -66,7 +73,7 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
|
|||||||
HeadRepo: headRepo,
|
HeadRepo: headRepo,
|
||||||
HeadGitRepo: headGitRepo,
|
HeadGitRepo: headGitRepo,
|
||||||
HeadRef: headRef,
|
HeadRef: headRef,
|
||||||
DirectComparison: directComparison,
|
CompareSeparator: util.Iif(directComparison, "..", "..."),
|
||||||
}
|
}
|
||||||
|
|
||||||
compareInfo.HeadCommitID, err = gitrepo.GetFullCommitID(ctx, headRepo, headRef.String())
|
compareInfo.HeadCommitID, err = gitrepo.GetFullCommitID(ctx, headRepo, headRef.String())
|
||||||
|
|||||||
9
templates/repo/commits_ref_name.tmpl
Normal file
9
templates/repo/commits_ref_name.tmpl
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{{- /* Template Argument: git.RefName */ -}}
|
||||||
|
{{- $refName := . -}}
|
||||||
|
{{- if $refName.IsBranch -}}
|
||||||
|
{{svg "octicon-git-branch"}} {{$refName.ShortName}}
|
||||||
|
{{- else if $refName.IsTag -}}
|
||||||
|
{{svg "octicon-tag"}} {{$refName.ShortName}}
|
||||||
|
{{- else -}}
|
||||||
|
{{ShortSha $refName.ShortName}}
|
||||||
|
{{- end -}}
|
||||||
@ -10,9 +10,9 @@
|
|||||||
</div>
|
</div>
|
||||||
{{if .IsDiffCompare}}
|
{{if .IsDiffCompare}}
|
||||||
<div class="commits-table-right tw-whitespace-nowrap">
|
<div class="commits-table-right tw-whitespace-nowrap">
|
||||||
<a href="{{$.CommitRepoLink}}/commit/{{.BeforeCommitID | PathEscape}}" class="ui green sha label tw-mx-0">{{if not .BaseIsCommit}}{{if .BaseIsBranch}}{{svg "octicon-git-branch"}}{{else if .BaseIsTag}}{{svg "octicon-tag"}}{{end}}{{.BaseBranch}}{{else}}{{ShortSha .BaseBranch}}{{end}}</a>
|
<a href="{{$.CommitRepoLink}}/commit/{{.BeforeCommitID | PathEscape}}" class="ui green sha label tw-mx-0">{{template "repo/commits_ref_name" .CompareInfo.BaseRef}}</a>
|
||||||
...
|
{{$.CompareInfo.CompareSeparator}}
|
||||||
<a href="{{$.CommitRepoLink}}/commit/{{.AfterCommitID | PathEscape}}" class="ui green sha label tw-mx-0">{{if not .HeadIsCommit}}{{if .HeadIsBranch}}{{svg "octicon-git-branch"}}{{else if .HeadIsTag}}{{svg "octicon-tag"}}{{end}}{{.HeadBranch}}{{else}}{{ShortSha .HeadBranch}}{{end}}</a>
|
<a href="{{$.CommitRepoLink}}/commit/{{.AfterCommitID | PathEscape}}" class="ui green sha label tw-mx-0">{{template "repo/commits_ref_name" .CompareInfo.HeadRef}}</a>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</h4>
|
</h4>
|
||||||
|
|||||||
@ -2,11 +2,13 @@
|
|||||||
<div role="main" aria-label="{{.Title}}" class="page-content repository diff {{if .PageIsComparePull}}compare pull{{end}}">
|
<div role="main" aria-label="{{.Title}}" class="page-content repository diff {{if .PageIsComparePull}}compare pull{{end}}">
|
||||||
{{template "repo/header" .}}
|
{{template "repo/header" .}}
|
||||||
|
|
||||||
|
{{$compareSeparator := $.CompareInfo.CompareSeparator}}
|
||||||
|
{{$compareSeparatorSwitch := Iif $.CompareInfo.DirectComparison "..." ".."}}
|
||||||
<div class="ui container fluid padded">
|
<div class="ui container fluid padded">
|
||||||
<h2 class="ui header">
|
<h2 class="ui header">
|
||||||
{{if and $.PageIsComparePull $.IsSigned (not .Repository.IsArchived)}}
|
{{if and $.PageIsComparePull $.IsSigned (not .Repository.IsArchived)}}
|
||||||
{{ctx.Locale.Tr "repo.pulls.compare_changes"}}
|
{{ctx.Locale.Tr "repo.compare.title"}}
|
||||||
<div class="sub header">{{ctx.Locale.Tr "repo.pulls.compare_changes_desc"}}</div>
|
<div class="sub header">{{ctx.Locale.Tr "repo.compare.description"}}</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{ctx.Locale.Tr "action.compare_commits_general"}}
|
{{ctx.Locale.Tr "action.compare_commits_general"}}
|
||||||
{{end}}
|
{{end}}
|
||||||
@ -29,7 +31,7 @@
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
<div class="ui segment choose branch">
|
<div class="ui segment choose branch">
|
||||||
<a class="tw-mr-2" href="{{$.HeadRepo.Link}}/compare/{{PathEscapeSegments $.HeadBranch}}{{$.CompareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.BaseName}}/{{PathEscape $.Repository.Name}}:{{end}}{{PathEscapeSegments $.BaseBranch}}" title="{{ctx.Locale.Tr "repo.pulls.switch_head_and_base"}}">{{svg "octicon-git-compare"}}</a>
|
<a class="tw-mr-2" href="{{$.HeadRepo.Link}}/compare/{{PathEscapeSegments $.HeadBranch}}{{$compareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.BaseName}}/{{PathEscape $.Repository.Name}}:{{end}}{{PathEscapeSegments $.BaseBranch}}" title="{{ctx.Locale.Tr "repo.pulls.switch_head_and_base"}}">{{svg "octicon-git-compare"}}</a>
|
||||||
<div class="ui dropdown jump select-branch">
|
<div class="ui dropdown jump select-branch">
|
||||||
<div class="ui basic small button">
|
<div class="ui basic small button">
|
||||||
<span class="text">{{if $.PageIsComparePull}}{{ctx.Locale.Tr "repo.pulls.compare_base"}}{{else}}{{ctx.Locale.Tr "repo.compare.compare_base"}}{{end}}: <strong>{{$BaseCompareName}}:{{$.BaseBranch}}</strong></span>
|
<span class="text">{{if $.PageIsComparePull}}{{ctx.Locale.Tr "repo.pulls.compare_base"}}{{else}}{{ctx.Locale.Tr "repo.compare.compare_base"}}{{end}}: <strong>{{$BaseCompareName}}:{{$.BaseBranch}}</strong></span>
|
||||||
@ -58,48 +60,48 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="scrolling menu reference-list-menu base-branch-list">
|
<div class="scrolling menu reference-list-menu base-branch-list">
|
||||||
{{range .Branches}}
|
{{range .Branches}}
|
||||||
<a class="item {{if eq $.BaseBranch .}}selected{{end}}" href="{{$.RepoLink}}/compare/{{PathEscapeSegments .}}{{$.CompareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{end}}{{PathEscapeSegments $.HeadBranch}}">{{$BaseCompareName}}:{{.}}</a>
|
<a class="item {{if eq $.BaseBranch .}}selected{{end}}" href="{{$.RepoLink}}/compare/{{PathEscapeSegments .}}{{$compareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{end}}{{PathEscapeSegments $.HeadBranch}}">{{$BaseCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if not .PullRequestCtx.SameRepo}}
|
{{if not .PullRequestCtx.SameRepo}}
|
||||||
{{range .HeadBranches}}
|
{{range .HeadBranches}}
|
||||||
<a class="item" href="{{$.HeadRepo.Link}}/compare/{{PathEscapeSegments .}}{{$.CompareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$HeadCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.HeadRepo.Link}}/compare/{{PathEscapeSegments .}}{{$compareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$HeadCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .OwnForkRepo}}
|
{{if .OwnForkRepo}}
|
||||||
{{range .OwnForkRepoBranches}}
|
{{range .OwnForkRepoBranches}}
|
||||||
<a class="item" href="{{$.OwnForkRepo.Link}}/compare/{{PathEscapeSegments .}}{{$.CompareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$OwnForkCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.OwnForkRepo.Link}}/compare/{{PathEscapeSegments .}}{{$compareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$OwnForkCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if and .RootRepo (.RootRepo.AllowsPulls ctx)}}
|
{{if and .RootRepo (.RootRepo.AllowsPulls ctx)}}
|
||||||
{{range .RootRepoBranches}}
|
{{range .RootRepoBranches}}
|
||||||
<a class="item" href="{{$.RootRepo.Link}}/compare/{{PathEscapeSegments .}}{{$.CompareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$RootRepoCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.RootRepo.Link}}/compare/{{PathEscapeSegments .}}{{$compareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$RootRepoCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div class="scrolling menu reference-list-menu base-tag-list tw-hidden">
|
<div class="scrolling menu reference-list-menu base-tag-list tw-hidden">
|
||||||
{{range .Tags}}
|
{{range .Tags}}
|
||||||
<a class="item {{if eq $.BaseBranch .}}selected{{end}}" href="{{$.RepoLink}}/compare/{{PathEscapeSegments .}}{{$.CompareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{end}}{{PathEscapeSegments $.HeadBranch}}">{{$BaseCompareName}}:{{.}}</a>
|
<a class="item {{if eq $.BaseBranch .}}selected{{end}}" href="{{$.RepoLink}}/compare/{{PathEscapeSegments .}}{{$compareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{end}}{{PathEscapeSegments $.HeadBranch}}">{{$BaseCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if not .PullRequestCtx.SameRepo}}
|
{{if not .PullRequestCtx.SameRepo}}
|
||||||
{{range .HeadTags}}
|
{{range .HeadTags}}
|
||||||
<a class="item" href="{{$.HeadRepo.Link}}/compare/{{PathEscapeSegments .}}{{$.CompareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$HeadCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.HeadRepo.Link}}/compare/{{PathEscapeSegments .}}{{$compareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$HeadCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .OwnForkRepo}}
|
{{if .OwnForkRepo}}
|
||||||
{{range .OwnForkRepoTags}}
|
{{range .OwnForkRepoTags}}
|
||||||
<a class="item" href="{{$.OwnForkRepo.Link}}/compare/{{PathEscapeSegments .}}{{$.CompareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$OwnForkCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.OwnForkRepo.Link}}/compare/{{PathEscapeSegments .}}{{$compareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$OwnForkCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .RootRepo}}
|
{{if .RootRepo}}
|
||||||
{{range .RootRepoTags}}
|
{{range .RootRepoTags}}
|
||||||
<a class="item" href="{{$.RootRepo.Link}}/compare/{{PathEscapeSegments .}}{{$.CompareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$RootRepoCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.RootRepo.Link}}/compare/{{PathEscapeSegments .}}{{$compareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$RootRepoCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a href="{{.RepoLink}}/compare/{{PathEscapeSegments .BaseBranch}}{{.OtherCompareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{end}}{{PathEscapeSegments $.HeadBranch}}" title="{{ctx.Locale.Tr "repo.pulls.switch_comparison_type"}}">{{svg "octicon-arrow-left" 16}}<div class="compare-separator">{{.CompareSeparator}}</div></a>
|
<a href="{{.RepoLink}}/compare/{{PathEscapeSegments .BaseBranch}}{{$compareSeparatorSwitch}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{end}}{{PathEscapeSegments $.HeadBranch}}" title="{{ctx.Locale.Tr "repo.pulls.switch_comparison_type"}}">{{svg "octicon-arrow-left" 16}}<div class="compare-separator">{{$compareSeparator}}</div></a>
|
||||||
|
|
||||||
<div class="ui dropdown jump select-branch">
|
<div class="ui dropdown jump select-branch">
|
||||||
<div class="ui basic small button">
|
<div class="ui basic small button">
|
||||||
@ -129,41 +131,41 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="scrolling menu reference-list-menu head-branch-list">
|
<div class="scrolling menu reference-list-menu head-branch-list">
|
||||||
{{range .HeadBranches}}
|
{{range .HeadBranches}}
|
||||||
<a class="{{if eq $.HeadBranch .}}selected{{end}} item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$.CompareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{end}}{{PathEscapeSegments .}}">{{$HeadCompareName}}:{{.}}</a>
|
<a class="{{if eq $.HeadBranch .}}selected{{end}} item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$compareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{end}}{{PathEscapeSegments .}}">{{$HeadCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if not .PullRequestCtx.SameRepo}}
|
{{if not .PullRequestCtx.SameRepo}}
|
||||||
{{range .Branches}}
|
{{range .Branches}}
|
||||||
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$.CompareSeparator}}{{PathEscape $.BaseName}}/{{PathEscape $.Repository.Name}}:{{PathEscapeSegments .}}">{{$BaseCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$compareSeparator}}{{PathEscape $.BaseName}}/{{PathEscape $.Repository.Name}}:{{PathEscapeSegments .}}">{{$BaseCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .OwnForkRepo}}
|
{{if .OwnForkRepo}}
|
||||||
{{range .OwnForkRepoBranches}}
|
{{range .OwnForkRepoBranches}}
|
||||||
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$.CompareSeparator}}{{PathEscape $.OwnForkRepo.OwnerName}}/{{PathEscape $.OwnForkRepo.Name}}:{{PathEscapeSegments .}}">{{$OwnForkCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$compareSeparator}}{{PathEscape $.OwnForkRepo.OwnerName}}/{{PathEscape $.OwnForkRepo.Name}}:{{PathEscapeSegments .}}">{{$OwnForkCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .RootRepo}}
|
{{if .RootRepo}}
|
||||||
{{range .RootRepoBranches}}
|
{{range .RootRepoBranches}}
|
||||||
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$.CompareSeparator}}{{PathEscape $.RootRepo.OwnerName}}/{{PathEscape $.RootRepo.Name}}:{{PathEscapeSegments .}}">{{$RootRepoCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$compareSeparator}}{{PathEscape $.RootRepo.OwnerName}}/{{PathEscape $.RootRepo.Name}}:{{PathEscapeSegments .}}">{{$RootRepoCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div class="scrolling menu reference-list-menu head-tag-list tw-hidden">
|
<div class="scrolling menu reference-list-menu head-tag-list tw-hidden">
|
||||||
{{range .HeadTags}}
|
{{range .HeadTags}}
|
||||||
<a class="{{if eq $.HeadBranch .}}selected{{end}} item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$.CompareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{end}}{{PathEscapeSegments .}}">{{$HeadCompareName}}:{{.}}</a>
|
<a class="{{if eq $.HeadBranch .}}selected{{end}} item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$compareSeparator}}{{if not $.PullRequestCtx.SameRepo}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{end}}{{PathEscapeSegments .}}">{{$HeadCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if not .PullRequestCtx.SameRepo}}
|
{{if not .PullRequestCtx.SameRepo}}
|
||||||
{{range .Tags}}
|
{{range .Tags}}
|
||||||
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$.CompareSeparator}}{{PathEscape $.BaseName}}/{{PathEscape $.Repository.Name}}:{{PathEscapeSegments .}}">{{$BaseCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$compareSeparator}}{{PathEscape $.BaseName}}/{{PathEscape $.Repository.Name}}:{{PathEscapeSegments .}}">{{$BaseCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .OwnForkRepo}}
|
{{if .OwnForkRepo}}
|
||||||
{{range .OwnForkRepoTags}}
|
{{range .OwnForkRepoTags}}
|
||||||
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$.CompareSeparator}}{{PathEscape $.OwnForkRepo.OwnerName}}/{{PathEscape $.OwnForkRepo.Name}}:{{PathEscapeSegments .}}">{{$OwnForkCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$compareSeparator}}{{PathEscape $.OwnForkRepo.OwnerName}}/{{PathEscape $.OwnForkRepo.Name}}:{{PathEscapeSegments .}}">{{$OwnForkCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .RootRepo}}
|
{{if .RootRepo}}
|
||||||
{{range .RootRepoTags}}
|
{{range .RootRepoTags}}
|
||||||
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$.CompareSeparator}}{{PathEscape $.RootRepo.OwnerName}}/{{PathEscape $.RootRepo.Name}}:{{PathEscapeSegments .}}">{{$RootRepoCompareName}}:{{.}}</a>
|
<a class="item" href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.BaseBranch}}{{$compareSeparator}}{{PathEscape $.RootRepo.OwnerName}}/{{PathEscape $.RootRepo.Name}}:{{PathEscapeSegments .}}">{{$RootRepoCompareName}}:{{.}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
@ -173,12 +175,12 @@
|
|||||||
|
|
||||||
{{$showDiffBox := and .CommitCount (not .IsNothingToCompare)}}
|
{{$showDiffBox := and .CommitCount (not .IsNothingToCompare)}}
|
||||||
{{if and .IsSigned .PageIsComparePull}}
|
{{if and .IsSigned .PageIsComparePull}}
|
||||||
{{$allowCreatePR := or $.AllowEmptyPr (not .IsNothingToCompare)}}
|
{{$allowCreatePR := and ($.CompareInfo.BaseRef.IsBranch) ($.CompareInfo.HeadRef.IsBranch) (not $.CompareInfo.DirectComparison) (or $.AllowEmptyPr (not .IsNothingToCompare))}}
|
||||||
{{if .IsNothingToCompare}}
|
{{if .IsNothingToCompare}}
|
||||||
<div class="ui segment">
|
<div class="ui segment">
|
||||||
{{if $allowCreatePR}}
|
{{if $allowCreatePR}}
|
||||||
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_and_allow_empty_pr"}}
|
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_and_allow_empty_pr"}}
|
||||||
{{else if and .HeadIsBranch .BaseIsBranch}}
|
{{else if and $.CompareInfo.BaseRef.IsBranch $.CompareInfo.HeadRef.IsBranch}}
|
||||||
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare"}}
|
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare"}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_have_tag"}}
|
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_have_tag"}}
|
||||||
@ -205,8 +207,9 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{else if $allowCreatePR}}
|
{{else if $allowCreatePR}}
|
||||||
<div class="ui info message pullrequest-form-toggle {{if .ExpandNewPrForm}}tw-hidden{{end}}">
|
<div class="ui info message flex-text-block pullrequest-form-toggle {{if .ExpandNewPrForm}}tw-hidden{{end}}">
|
||||||
<button class="ui button primary show-panel toggle" data-panel=".pullrequest-form-toggle, .pullrequest-form">{{ctx.Locale.Tr "repo.pulls.new"}}</button>
|
<span class="tw-flex-1">{{ctx.Locale.Tr "repo.pulls.new.description"}}</span>
|
||||||
|
<a class="ui button primary show-panel toggle" data-panel=".pullrequest-form-toggle, .pullrequest-form">{{ctx.Locale.Tr "repo.pulls.new"}}</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="pullrequest-form {{if not .ExpandNewPrForm}}tw-hidden{{end}}">
|
<div class="pullrequest-form {{if not .ExpandNewPrForm}}tw-hidden{{end}}">
|
||||||
{{template "repo/issue/new_form" .}}
|
{{template "repo/issue/new_form" .}}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user