diff --git a/AGENTS.md b/AGENTS.md
index 0fa26ab3f..275625b03 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -28,4 +28,5 @@ This applies to all texts, including but not limited to UI, documentation, code
## Source code control
- When pushing changes to a pull request from a fork, use SSH address and do not add remote.
-- Never automatically executes commands that touches Git history even if the session does not require approvals, including but not limited to `rebase`, `commit`, `push`, `pull`. One-time execution is only allowed when being explicitly asked to do so.
+- Never automatically executes commands that touches Git history even if the session does not require approvals, including but not limited to `rebase`, `commit`, `push`, `pull`, `reset`, `amend`. Exceptions are only allowed case-by-case.
+- Do not amend commits unless being explicitly asked to do so.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c88584b86..ae4a5144d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ All notable changes to Gogs are documented in this file.
### Added
+- Support comparing tags in addition to branches. [#6141](https://github.com/gogs/gogs/issues/6141)
- Show file name in browser tab title when viewing files. [#5896](https://github.com/gogs/gogs/pull/5896)
- Support using TLS for Redis session provider using `[session] PROVIDER_CONFIG = ...,tls=true`. [#7860](https://github.com/gogs/gogs/pull/7860)
- Support expanading values in `app.ini` from environment variables, e.g. `[database] PASSWORD = ${DATABASE_PASSWORD}`. [#8057](https://github.com/gogs/gogs/pull/8057)
diff --git a/internal/route/repo/pull.go b/internal/route/repo/pull.go
index d86effb93..1616e790c 100644
--- a/internal/route/repo/pull.go
+++ b/internal/route/repo/pull.go
@@ -433,23 +433,23 @@ func MergePullRequest(c *context.Context) {
func ParseCompareInfo(c *context.Context) (*database.User, *database.Repository, *git.Repository, *gitutil.PullRequestMeta, string, string) {
baseRepo := c.Repo.Repository
- // Get compared branches information
- // format: ...[
:]
+ // Get compared refs information
+ // format: ...[:]
// base<-head: master...head:feature
// same repo: master...feature
infos := strings.Split(c.Params("*"), "...")
if len(infos) != 2 {
- log.Trace("ParseCompareInfo[%d]: not enough compared branches information %s", baseRepo.ID, infos)
+ log.Trace("ParseCompareInfo[%d]: not enough compared refs information %s", baseRepo.ID, infos)
c.NotFound()
return nil, nil, nil, nil, "", ""
}
- baseBranch := infos[0]
- c.Data["BaseBranch"] = baseBranch
+ baseRef := infos[0]
+ c.Data["BaseBranch"] = baseRef
var (
headUser *database.User
- headBranch string
+ headRef string
isSameRepo bool
err error
)
@@ -459,7 +459,7 @@ func ParseCompareInfo(c *context.Context) (*database.User, *database.Repository,
if len(headInfos) == 1 {
isSameRepo = true
headUser = c.Repo.Owner
- headBranch = headInfos[0]
+ headRef = headInfos[0]
} else if len(headInfos) == 2 {
headUser, err = database.Handle.Users().GetByUsername(c.Req.Context(), headInfos[0])
@@ -467,7 +467,7 @@ func ParseCompareInfo(c *context.Context) (*database.User, *database.Repository,
c.NotFoundOrError(err, "get user by name")
return nil, nil, nil, nil, "", ""
}
- headBranch = headInfos[1]
+ headRef = headInfos[1]
isSameRepo = headUser.ID == baseRepo.OwnerID
} else {
@@ -475,11 +475,11 @@ func ParseCompareInfo(c *context.Context) (*database.User, *database.Repository,
return nil, nil, nil, nil, "", ""
}
c.Data["HeadUser"] = headUser
- c.Data["HeadBranch"] = headBranch
+ c.Data["HeadBranch"] = headRef
c.Repo.PullRequest.SameRepo = isSameRepo
- // Check if base branch is valid.
- if !c.Repo.GitRepo.HasBranch(baseBranch) {
+ // Check if base ref is valid.
+ if _, err := c.Repo.GitRepo.RevParse(baseRef); err != nil {
c.NotFound()
return nil, nil, nil, nil, "", ""
}
@@ -528,8 +528,8 @@ func ParseCompareInfo(c *context.Context) (*database.User, *database.Repository,
return nil, nil, nil, nil, "", ""
}
- // Check if head branch is valid.
- if !headGitRepo.HasBranch(headBranch) {
+ // Check if head ref is valid.
+ if _, err := headGitRepo.RevParse(headRef); err != nil {
c.NotFound()
return nil, nil, nil, nil, "", ""
}
@@ -542,7 +542,7 @@ func ParseCompareInfo(c *context.Context) (*database.User, *database.Repository,
c.Data["HeadBranches"] = headBranches
baseRepoPath := database.RepoPath(baseRepo.Owner.Name, baseRepo.Name)
- meta, err := gitutil.Module.PullRequestMeta(headGitRepo.Path(), baseRepoPath, headBranch, baseBranch)
+ meta, err := gitutil.Module.PullRequestMeta(headGitRepo.Path(), baseRepoPath, headRef, baseRef)
if err != nil {
if gitutil.IsErrNoMergeBase(err) {
c.Data["IsNoMergeBase"] = true
@@ -554,7 +554,7 @@ func ParseCompareInfo(c *context.Context) (*database.User, *database.Repository,
}
c.Data["BeforeCommitID"] = meta.MergeBase
- return headUser, headRepo, headGitRepo, meta, baseBranch, headBranch
+ return headUser, headRepo, headGitRepo, meta, baseRef, headRef
}
func PrepareCompareDiff(
@@ -563,7 +563,7 @@ func PrepareCompareDiff(
headRepo *database.Repository,
headGitRepo *git.Repository,
meta *gitutil.PullRequestMeta,
- headBranch string,
+ headRef string,
) bool {
var (
repo = c.Repo.Repository
@@ -573,9 +573,9 @@ func PrepareCompareDiff(
// Get diff information.
c.Data["CommitRepoLink"] = headRepo.Link()
- headCommitID, err := headGitRepo.BranchCommitID(headBranch)
+ headCommitID, err := headGitRepo.RevParse(headRef)
if err != nil {
- c.Error(err, "get head branch commit ID")
+ c.Error(err, "get head commit ID")
return false
}
c.Data["AfterCommitID"] = headCommitID
@@ -625,12 +625,12 @@ func CompareAndPullRequest(c *context.Context) {
setTemplateIfExists(c, PullRequestTemplateKey, PullRequestTemplateCandidates)
renderAttachmentSettings(c)
- headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(c)
+ headUser, headRepo, headGitRepo, prInfo, baseRef, headRef := ParseCompareInfo(c)
if c.Written() {
return
}
- pr, err := database.GetUnmergedPullRequest(headRepo.ID, c.Repo.Repository.ID, headBranch, baseBranch)
+ pr, err := database.GetUnmergedPullRequest(headRepo.ID, c.Repo.Repository.ID, headRef, baseRef)
if err != nil {
if !database.IsErrPullRequestNotExist(err) {
c.Error(err, "get unmerged pull request")
@@ -643,7 +643,7 @@ func CompareAndPullRequest(c *context.Context) {
return
}
- nothingToCompare := PrepareCompareDiff(c, headUser, headRepo, headGitRepo, prInfo, headBranch)
+ nothingToCompare := PrepareCompareDiff(c, headUser, headRepo, headGitRepo, prInfo, headRef)
if c.Written() {
return
}
@@ -666,7 +666,7 @@ func CompareAndPullRequest(c *context.Context) {
if c.Data[PullRequestTitleTemplateKey] != nil {
customTitle := c.Data[PullRequestTitleTemplateKey].(string)
- r := strings.NewReplacer("{{headBranch}}", headBranch, "{{baseBranch}}", baseBranch)
+ r := strings.NewReplacer("{{headBranch}}", headRef, "{{baseBranch}}", baseRef)
c.Data["title"] = r.Replace(customTitle)
}
@@ -685,7 +685,7 @@ func CompareAndPullRequestPost(c *context.Context, f form.NewIssue) {
attachments []string
)
- headUser, headRepo, headGitRepo, meta, baseBranch, headBranch := ParseCompareInfo(c)
+ headUser, headRepo, headGitRepo, meta, baseRef, headRef := ParseCompareInfo(c)
if c.Written() {
return
}
@@ -704,7 +704,7 @@ func CompareAndPullRequestPost(c *context.Context, f form.NewIssue) {
// This stage is already stop creating new pull request, so it does not matter if it has
// something to compare or not.
- PrepareCompareDiff(c, headUser, headRepo, headGitRepo, meta, headBranch)
+ PrepareCompareDiff(c, headUser, headRepo, headGitRepo, meta, headRef)
if c.Written() {
return
}
@@ -713,7 +713,7 @@ func CompareAndPullRequestPost(c *context.Context, f form.NewIssue) {
return
}
- patch, err := headGitRepo.DiffBinary(meta.MergeBase, headBranch)
+ patch, err := headGitRepo.DiffBinary(meta.MergeBase, headRef)
if err != nil {
c.Error(err, "get patch")
return
@@ -734,8 +734,8 @@ func CompareAndPullRequestPost(c *context.Context, f form.NewIssue) {
HeadRepoID: headRepo.ID,
BaseRepoID: repo.ID,
HeadUserName: headUser.Name,
- HeadBranch: headBranch,
- BaseBranch: baseBranch,
+ HeadBranch: headRef,
+ BaseBranch: baseRef,
HeadRepo: headRepo,
BaseRepo: repo,
MergeBase: meta.MergeBase,