Skip to content

Commit 277bb5d

Browse files
committed
Merge branch 'main' into mainzjj
* main: Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior (go-gitea#37465) Fix compare dropdown for branches without common history (go-gitea#37470) FIX: URL sanitization to handle schemeless credentials (go-gitea#37440) Refactor pull request view (4) (go-gitea#37451) Fix scheduled action panic with null event payload (go-gitea#37459) Fix attachment Content-Security-Policy (go-gitea#37455) [skip ci] Updated translations via Crowdin Rename CurrentRefPath to CurrentRefSubURL (go-gitea#37453) Clean up org pages layout (go-gitea#37445) Fix script error alert (go-gitea#37458) Fix inconsistent disabled styling on logged-out repo header buttons (go-gitea#37406) Add API endpoint to reply to pull request review comments (go-gitea#36683) Add CurrentURL template variable back (go-gitea#37444)
2 parents 29ce2df + 0ba862c commit 277bb5d

66 files changed

Lines changed: 1085 additions & 657 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

custom/conf/app.example.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,11 @@ LEVEL = Info
11691169
;; Retarget child pull requests to the parent pull request branch target on merge of parent pull request. It only works on merged PRs where the head and base branch target the same repo.
11701170
;RETARGET_CHILDREN_ON_MERGE = true
11711171
;;
1172+
;; Default source for the pull request title when opening a new PR.
1173+
;; "first-commit" uses the oldest commit's summary.
1174+
;; "auto" uses commit's summary if the PR only has one commit, normalizes the branch name if multiple commits.
1175+
;DEFAULT_TITLE_SOURCE = first-commit
1176+
;;
11721177
;; Delay mergeable check until page view or API access, for pull requests that have not been updated in the specified days when their base branches get updated.
11731178
;; Use "-1" to always check all pull requests (old behavior). Use "0" to always delay the checks.
11741179
;DELAY_CHECK_FOR_INACTIVE_DAYS = 7

models/renderhelper/repo_comment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (r *RepoComment) ResolveLink(link, preferLinkType string) string {
3434
case markup.LinkTypeRoot:
3535
return r.ctx.ResolveLinkRoot(link)
3636
default:
37-
return r.ctx.ResolveLinkRelative(r.repoLink, r.opts.CurrentRefPath, link)
37+
return r.ctx.ResolveLinkRelative(r.repoLink, r.opts.CurrentRefSubURL, link)
3838
}
3939
}
4040

@@ -43,7 +43,7 @@ var _ markup.RenderHelper = (*RepoComment)(nil)
4343
type RepoCommentOptions struct {
4444
DeprecatedRepoName string // it is only a patch for the non-standard "markup" api
4545
DeprecatedOwnerName string // it is only a patch for the non-standard "markup" api
46-
CurrentRefPath string // eg: "branch/main" or "commit/11223344"
46+
CurrentRefSubURL string // eg: "branch/main" or "commit/11223344"
4747
FootnoteContextID string // the extra context ID for footnotes, used to avoid conflicts with other footnotes in the same page
4848
}
4949

models/renderhelper/repo_comment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func TestRepoComment(t *testing.T) {
5454
`, rendered)
5555
})
5656

57-
t.Run("WithCurrentRefPath", func(t *testing.T) {
58-
rctx := NewRenderContextRepoComment(t.Context(), repo1, RepoCommentOptions{CurrentRefPath: "/commit/1234"}).
57+
t.Run("WithCurrentRefSubURL", func(t *testing.T) {
58+
rctx := NewRenderContextRepoComment(t.Context(), repo1, RepoCommentOptions{CurrentRefSubURL: "/commit/1234"}).
5959
WithMarkupType(markdown.MarkupName)
6060

6161
// the ref path is only used to render commit message: a commit message is rendered at the commit page with its commit ID path

models/renderhelper/repo_file.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ func (r *RepoFile) ResolveLink(link, preferLinkType string) (finalLink string) {
3535
case markup.LinkTypeRoot:
3636
finalLink = r.ctx.ResolveLinkRoot(link)
3737
case markup.LinkTypeRaw:
38-
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "raw", r.opts.CurrentRefPath), r.opts.CurrentTreePath, link)
38+
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "raw", r.opts.CurrentRefSubURL), r.opts.CurrentTreePath, link)
3939
case markup.LinkTypeMedia:
40-
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "media", r.opts.CurrentRefPath), r.opts.CurrentTreePath, link)
40+
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "media", r.opts.CurrentRefSubURL), r.opts.CurrentTreePath, link)
4141
default:
42-
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "src", r.opts.CurrentRefPath), r.opts.CurrentTreePath, link)
42+
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "src", r.opts.CurrentRefSubURL), r.opts.CurrentTreePath, link)
4343
}
4444
return finalLink
4545
}
@@ -50,8 +50,8 @@ type RepoFileOptions struct {
5050
DeprecatedRepoName string // it is only a patch for the non-standard "markup" api
5151
DeprecatedOwnerName string // it is only a patch for the non-standard "markup" api
5252

53-
CurrentRefPath string // eg: "branch/main", it is a sub URL path escaped by callers, TODO: rename to CurrentRefSubURL
54-
CurrentTreePath string // eg: "path/to/file" in the repo, it is the tree path without URL path escaping
53+
CurrentRefSubURL string // eg: "branch/main" or "branch/my%20branch", it is a sub URL path escaped by callers
54+
CurrentTreePath string // eg: "path/to/file" in the repo, it is the tree path without URL path escaping
5555
}
5656

5757
func NewRenderContextRepoFile(ctx context.Context, repo *repo_model.Repository, opts ...RepoFileOptions) *markup.RenderContext {
@@ -71,9 +71,8 @@ func NewRenderContextRepoFile(ctx context.Context, repo *repo_model.Repository,
7171
})
7272
}
7373
// External render's iframe needs this to generate correct links
74-
// TODO: maybe need to make it access "CurrentRefPath" directly (but impossible at the moment due to cycle-import)
75-
// CurrentRefPath is already path-escaped by callers
76-
rctx.RenderOptions.Metas["RefTypeNameSubURL"] = helper.opts.CurrentRefPath
74+
// TODO: maybe need to make it access "CurrentRefSubURL" directly (but impossible at the moment due to cycle-import)
75+
rctx.RenderOptions.Metas["RefTypeNameSubURL"] = helper.opts.CurrentRefSubURL
7776
rctx = rctx.WithHelper(helper).WithEnableHeadingIDGeneration(true)
7877
return rctx
7978
}

models/renderhelper/repo_file_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestRepoFile(t *testing.T) {
3636
})
3737

3838
t.Run("AbsoluteAndRelative", func(t *testing.T) {
39-
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefPath: "branch/main"}).
39+
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefSubURL: "branch/main"}).
4040
WithMarkupType(markdown.MarkupName)
4141
rendered, err := markup.RenderString(rctx, `
4242
[/test](/test)
@@ -53,8 +53,8 @@ func TestRepoFile(t *testing.T) {
5353
`, rendered)
5454
})
5555

56-
t.Run("WithCurrentRefPath", func(t *testing.T) {
57-
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefPath: "/commit/1234"}).
56+
t.Run("WithCurrentRefSubURL", func(t *testing.T) {
57+
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefSubURL: "/commit/1234"}).
5858
WithMarkupType(markdown.MarkupName)
5959
rendered, err := markup.RenderString(rctx, `
6060
[/test](/test)
@@ -66,10 +66,10 @@ func TestRepoFile(t *testing.T) {
6666
`, rendered)
6767
})
6868

69-
t.Run("WithCurrentRefPathByTag", func(t *testing.T) {
69+
t.Run("WithCurrentRefSubURLByTag", func(t *testing.T) {
7070
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{
71-
CurrentRefPath: "/commit/1234",
72-
CurrentTreePath: "my-dir",
71+
CurrentRefSubURL: "/commit/1234",
72+
CurrentTreePath: "my-dir",
7373
}).
7474
WithMarkupType(markdown.MarkupName)
7575
rendered, err := markup.RenderString(rctx, `
@@ -89,8 +89,8 @@ func TestRepoFileOrgMode(t *testing.T) {
8989

9090
t.Run("Links", func(t *testing.T) {
9191
rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{
92-
CurrentRefPath: "/commit/1234",
93-
CurrentTreePath: "my-dir",
92+
CurrentRefSubURL: "/commit/1234",
93+
CurrentTreePath: "my-dir",
9494
}).WithRelativePath("my-dir/a.org")
9595

9696
rendered, err := markup.RenderString(rctx, `

models/renderhelper/repo_wiki.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ func (r *RepoWiki) ResolveLink(link, preferLinkType string) (finalLink string) {
3636
case markup.LinkTypeRoot:
3737
finalLink = r.ctx.ResolveLinkRoot(link)
3838
case markup.LinkTypeMedia, markup.LinkTypeRaw:
39-
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "wiki/raw", r.opts.currentRefPath), r.opts.currentTreePath, link)
39+
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "wiki/raw", r.opts.currentRefSubURL), r.opts.currentTreePath, link)
4040
default:
41-
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "wiki", r.opts.currentRefPath), r.opts.currentTreePath, link)
41+
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "wiki", r.opts.currentRefSubURL), r.opts.currentTreePath, link)
4242
}
4343
return finalLink
4444
}
@@ -50,8 +50,8 @@ type RepoWikiOptions struct {
5050
DeprecatedOwnerName string // it is only a patch for the non-standard "markup" api
5151

5252
// these options are not used at the moment because Wiki doesn't support sub-path, nor branch
53-
currentRefPath string // eg: "branch/main"
54-
currentTreePath string // eg: "path/to/file" in the repo
53+
currentRefSubURL string // eg: "branch/main"
54+
currentTreePath string // eg: "path/to/file" in the repo
5555
}
5656

5757
func NewRenderContextRepoWiki(ctx context.Context, repo *repo_model.Repository, opts ...RepoWikiOptions) *markup.RenderContext {

modules/git/gitcmd/command.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@ type Command struct {
5757
}
5858

5959
func logArgSanitize(arg string) string {
60-
if strings.Contains(arg, "://") && strings.Contains(arg, "@") {
61-
return util.SanitizeCredentialURLs(arg)
62-
} else if filepath.IsAbs(arg) {
60+
if filepath.IsAbs(arg) {
6361
base := filepath.Base(arg)
6462
dir := filepath.Dir(arg)
6563
return ".../" + filepath.Join(filepath.Base(dir), base)
6664
}
67-
return arg
65+
return util.SanitizeCredentialURLs(arg)
6866
}
6967

7068
func (c *Command) LogString() string {

modules/git/gitcmd/command_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ func TestCommandString(t *testing.T) {
109109
assert.Equal(t, cmd.prog+` a "-m msg" "it's a test" "say \"hello\""`, cmd.LogString())
110110

111111
cmd = NewCommand("url: https://a:b@c/", "/root/dir-a/dir-b")
112-
assert.Equal(t, cmd.prog+` "url: https://sanitized-credential@c/" .../dir-a/dir-b`, cmd.LogString())
112+
assert.Equal(t, cmd.prog+` "url: https://(masked)@c/" .../dir-a/dir-b`, cmd.LogString())
113+
114+
cmd = NewCommand("url: a:b@c/", "/root/dir-a/dir-b")
115+
assert.Equal(t, cmd.prog+` "url: (masked)@c/" .../dir-a/dir-b`, cmd.LogString())
113116
}
114117

115118
func TestRunStdError(t *testing.T) {

modules/gitrepo/compare_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
package gitrepo
55

66
import (
7+
"path/filepath"
8+
"strings"
79
"testing"
810

11+
"code.gitea.io/gitea/modules/git/gitcmd"
12+
"code.gitea.io/gitea/modules/util"
13+
914
"github.com/stretchr/testify/assert"
15+
"github.com/stretchr/testify/require"
1016
)
1117

1218
type mockRepository struct {
@@ -17,6 +23,32 @@ func (r *mockRepository) RelativePath() string {
1723
return r.path
1824
}
1925

26+
func TestMergeBaseNoCommonHistory(t *testing.T) {
27+
repoDir := filepath.Join(t.TempDir(), "repo.git")
28+
require.NoError(t, gitcmd.NewCommand("init").AddDynamicArguments(repoDir).Run(t.Context()))
29+
_, _, runErr := gitcmd.NewCommand("fast-import").WithDir(repoDir).WithStdinBytes([]byte(strings.TrimSpace(`
30+
commit refs/heads/branch1
31+
committer User <user@example.com> 1714310400 +0000
32+
data 12
33+
First commit
34+
M 100644 inline file1.txt
35+
data 12
36+
Hello from 1
37+
38+
commit refs/heads/branch2
39+
committer User <user@example.com> 1714310400 +0000
40+
data 13
41+
Second commit
42+
M 100644 inline file2.txt
43+
data 12
44+
Hello from 2
45+
`))).RunStdString(t.Context())
46+
require.NoError(t, runErr)
47+
mergeBase, err := MergeBase(t.Context(), &mockRepository{path: repoDir}, "branch1", "branch2")
48+
assert.Empty(t, mergeBase)
49+
assert.ErrorIs(t, err, util.ErrNotExist)
50+
}
51+
2052
func TestRepoGetDivergingCommits(t *testing.T) {
2153
repo := &mockRepository{path: "repo1_bare"}
2254
do, err := GetDivergingCommits(t.Context(), repo, "master", "branch2")

modules/gitrepo/merge.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ import (
99
"strings"
1010

1111
"code.gitea.io/gitea/modules/git/gitcmd"
12+
"code.gitea.io/gitea/modules/util"
1213
)
1314

1415
// MergeBase checks and returns merge base of two commits.
1516
func MergeBase(ctx context.Context, repo Repository, baseCommitID, headCommitID string) (string, error) {
16-
mergeBase, _, err := RunCmdString(ctx, repo, gitcmd.NewCommand("merge-base").
17+
mergeBase, stderr, err := RunCmdString(ctx, repo, gitcmd.NewCommand("merge-base").
1718
AddDashesAndList(baseCommitID, headCommitID))
1819
if err != nil {
20+
if gitcmd.IsErrorExitCode(err, 1) && strings.TrimSpace(stderr) == "" {
21+
return "", util.NewNotExistErrorf("merge-base for %s and %s doesn't exist", baseCommitID, headCommitID)
22+
}
1923
return "", fmt.Errorf("get merge-base of %s and %s failed: %w", baseCommitID, headCommitID, err)
2024
}
2125
return strings.TrimSpace(mergeBase), nil

0 commit comments

Comments
 (0)