Skip to content

Commit 28265f9

Browse files
authored
Merge branch 'main' into lunny/gitrepo_delete
2 parents 975a06f + 0dfa94e commit 28265f9

File tree

16 files changed

+152
-70
lines changed

16 files changed

+152
-70
lines changed

modules/fileicon/material.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (m *MaterialIconProvider) loadData() {
6262
log.Debug("Loaded material icon rules and SVG images")
6363
}
6464

65-
func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name, svg string) template.HTML {
65+
func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name, svg, extraClass string) template.HTML {
6666
data := ctx.GetData()
6767
renderedSVGs, _ := data["_RenderedSVGs"].(map[string]bool)
6868
if renderedSVGs == nil {
@@ -75,7 +75,7 @@ func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name
7575
panic("Invalid SVG icon")
7676
}
7777
svgID := "svg-mfi-" + name
78-
svgCommonAttrs := `class="svg fileicon" width="16" height="16" aria-hidden="true"`
78+
svgCommonAttrs := `class="svg git-entry-icon ` + extraClass + `" width="16" height="16" aria-hidden="true"`
7979
posOuterBefore := strings.IndexByte(svg, '>')
8080
if renderedSVGs[svgID] && posOuterBefore != -1 {
8181
return template.HTML(`<svg ` + svgCommonAttrs + `><use xlink:href="#` + svgID + `"></use></svg>`)
@@ -92,18 +92,28 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
9292

9393
if entry.IsLink() {
9494
if te, err := entry.FollowLink(); err == nil && te.IsDir() {
95-
return svg.RenderHTML("material-folder-symlink")
95+
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
96+
return svg.RenderHTML("material-folder-symlink", 16, "octicon-file-directory-symlink")
9697
}
9798
return svg.RenderHTML("octicon-file-symlink-file") // TODO: find some better icons for them
9899
}
99100

100101
name := m.findIconNameByGit(entry)
101102
if name == "folder" {
102103
// the material icon pack's "folder" icon doesn't look good, so use our built-in one
103-
return svg.RenderHTML("material-folder-generic")
104+
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
105+
return svg.RenderHTML("material-folder-generic", 16, "octicon-file-directory-fill")
104106
}
105107
if iconSVG, ok := m.svgs[name]; ok && iconSVG != "" {
106-
return m.renderFileIconSVG(ctx, name, iconSVG)
108+
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
109+
extraClass := "octicon-file"
110+
switch {
111+
case entry.IsDir():
112+
extraClass = "octicon-file-directory-fill"
113+
case entry.IsSubModule():
114+
extraClass = "octicon-file-submodule"
115+
}
116+
return m.renderFileIconSVG(ctx, name, iconSVG, extraClass)
107117
}
108118
return svg.RenderHTML("octicon-file")
109119
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,7 @@ commits.signed_by_untrusted_user_unmatched = Signed by untrusted user who does n
14071407
commits.gpg_key_id = GPG Key ID
14081408
commits.ssh_key_fingerprint = SSH Key Fingerprint
14091409
commits.view_path=View at this point in history
1410+
commits.view_file_diff = View changes to this file in this commit
14101411
14111412
commit.operations = Operations
14121413
commit.revert = Revert

routers/web/repo/view_home.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,14 @@ func RedirectRepoTreeToSrc(ctx *context.Context) {
429429
}
430430
ctx.Redirect(redirect)
431431
}
432+
433+
func RedirectRepoBlobToCommit(ctx *context.Context) {
434+
// redirect "/owner/repo/blob/*" requests to "/owner/repo/src/commit/*"
435+
// just like GitHub: browse files of a commit by "https://github/owner/repo/blob/{CommitID}"
436+
// TODO: maybe we could guess more types to redirect to the related pages in the future
437+
redirect := ctx.Repo.RepoLink + "/src/commit/" + ctx.PathParamRaw("*")
438+
if ctx.Req.URL.RawQuery != "" {
439+
redirect += "?" + ctx.Req.URL.RawQuery
440+
}
441+
ctx.Redirect(redirect)
442+
}

routers/web/web.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,8 @@ func registerRoutes(m *web.Router) {
15951595
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.Home)
15961596
m.Get("/*", context.RepoRefByType(""), repo.Home) // "/*" route is deprecated, and kept for backward compatibility
15971597
}, repo.SetEditorconfigIfExists)
1598-
m.Get("/tree/*", repo.RedirectRepoTreeToSrc) // redirect "/owner/repo/tree/*" requests to "/owner/repo/src/*"
1598+
m.Get("/tree/*", repo.RedirectRepoTreeToSrc) // redirect "/owner/repo/tree/*" requests to "/owner/repo/src/*"
1599+
m.Get("/blob/*", repo.RedirectRepoBlobToCommit) // redirect "/owner/repo/blob/*" requests to "/owner/repo/src/commit/*"
15991600

16001601
m.Get("/forks", context.RepoRef(), repo.Forks)
16011602
m.Get("/commit/{sha:([a-f0-9]{7,64})}.{ext:patch|diff}", repo.MustBeNotEmpty, repo.RawDiff)

services/gitdiff/gitdiff.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,10 +1443,8 @@ func GetWhitespaceFlag(whitespaceBehavior string) git.TrustedCmdArgs {
14431443
"ignore-eol": {"--ignore-space-at-eol"},
14441444
"show-all": nil,
14451445
}
1446-
14471446
if flag, ok := whitespaceFlags[whitespaceBehavior]; ok {
14481447
return flag
14491448
}
1450-
log.Warn("unknown whitespace behavior: %q, default to 'show-all'", whitespaceBehavior)
14511449
return nil
14521450
}

services/repository/push.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
repo_module "code.gitea.io/gitea/modules/repository"
2424
"code.gitea.io/gitea/modules/setting"
2525
"code.gitea.io/gitea/modules/timeutil"
26+
"code.gitea.io/gitea/modules/util"
2627
issue_service "code.gitea.io/gitea/services/issue"
2728
notify_service "code.gitea.io/gitea/services/notify"
2829
pull_service "code.gitea.io/gitea/services/pull"
@@ -133,23 +134,26 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
133134
} else { // is new tag
134135
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
135136
if err != nil {
136-
return fmt.Errorf("gitRepo.GetCommit(%s) in %s/%s[%d]: %w", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
137+
// in case there is dirty data, for example, the "github.com/git/git" repository has tags pointing to non-existing commits
138+
if !errors.Is(err, util.ErrNotExist) {
139+
log.Error("Unable to get tag commit: gitRepo.GetCommit(%s) in %s/%s[%d]: %v", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
140+
}
141+
} else {
142+
commits := repo_module.NewPushCommits()
143+
commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
144+
commits.CompareURL = repo.ComposeCompareURL(objectFormat.EmptyObjectID().String(), opts.NewCommitID)
145+
146+
notify_service.PushCommits(
147+
ctx, pusher, repo,
148+
&repo_module.PushUpdateOptions{
149+
RefFullName: opts.RefFullName,
150+
OldCommitID: objectFormat.EmptyObjectID().String(),
151+
NewCommitID: opts.NewCommitID,
152+
}, commits)
153+
154+
addTags = append(addTags, tagName)
155+
notify_service.CreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID)
137156
}
138-
139-
commits := repo_module.NewPushCommits()
140-
commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
141-
commits.CompareURL = repo.ComposeCompareURL(objectFormat.EmptyObjectID().String(), opts.NewCommitID)
142-
143-
notify_service.PushCommits(
144-
ctx, pusher, repo,
145-
&repo_module.PushUpdateOptions{
146-
RefFullName: opts.RefFullName,
147-
OldCommitID: objectFormat.EmptyObjectID().String(),
148-
NewCommitID: opts.NewCommitID,
149-
}, commits)
150-
151-
addTags = append(addTags, tagName)
152-
notify_service.CreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID)
153157
}
154158
} else if opts.RefFullName.IsBranch() {
155159
if pusher == nil || pusher.ID != opts.PusherID {

templates/repo/commits_list.tmpl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,20 @@
6666
<td class="text right aligned">{{DateUtils.TimeSince .Author.When}}</td>
6767
{{end}}
6868
<td class="text right aligned tw-py-0">
69-
<button class="btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "copy_hash"}}" data-clipboard-text="{{.ID}}">{{svg "octicon-copy"}}</button>
70-
{{if not $.PageIsWiki}}{{/* at the moment, wiki doesn't support "view at history point*/}}
69+
<button class="btn interact-bg tw-p-2 copy-commit-id" data-tooltip-content="{{ctx.Locale.Tr "copy_hash"}}" data-clipboard-text="{{.ID}}">{{svg "octicon-copy"}}</button>
70+
{{/* at the moment, wiki doesn't support these "view" links like "view at history point" */}}
71+
{{if not $.PageIsWiki}}
72+
{{/* view single file diff */}}
73+
{{if $.FileName}}
74+
<a class="btn interact-bg tw-p-2 view-single-diff" data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_file_diff"}}"
75+
href="{{$commitRepoLink}}/commit/{{.ID.String}}?files={{$.FileName}}"
76+
>{{svg "octicon-file-diff"}}</a>
77+
{{end}}
78+
79+
{{/* view at history point */}}
7180
{{$viewCommitLink := printf "%s/src/commit/%s" $commitRepoLink (PathEscape .ID.String)}}
7281
{{if $.FileName}}{{$viewCommitLink = printf "%s/%s" $viewCommitLink (PathEscapeSegments $.FileName)}}{{end}}
73-
<a class="btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_path"}}" href="{{$viewCommitLink}}">{{svg "octicon-file-code"}}</a>
82+
<a class="btn interact-bg tw-p-2 view-commit-path" data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_path"}}" href="{{$viewCommitLink}}">{{svg "octicon-file-code"}}</a>
7483
{{end}}
7584
</td>
7685
</tr>

tests/integration/html_helper.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ func (doc *HTMLDoc) GetCSRF() string {
4242
return doc.GetInputValueByName("_csrf")
4343
}
4444

45-
// AssertElement check if element by selector exists or does not exist depending on checkExists
46-
func (doc *HTMLDoc) AssertElement(t testing.TB, selector string, checkExists bool) {
45+
// AssertHTMLElement check if element by selector exists or does not exist depending on checkExists
46+
func AssertHTMLElement[T int | bool](t testing.TB, doc *HTMLDoc, selector string, checkExists T) {
4747
sel := doc.doc.Find(selector)
48-
if checkExists {
49-
assert.Equal(t, 1, sel.Length())
50-
} else {
51-
assert.Equal(t, 0, sel.Length())
48+
switch v := any(checkExists).(type) {
49+
case bool:
50+
assert.Equal(t, v, sel.Length() > 0)
51+
case int:
52+
assert.Equal(t, v, sel.Length())
5253
}
5354
}

tests/integration/links_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestRedirectsNoLogin(t *testing.T) {
5555
{"/user2/repo1/src/master/a%2fb.txt", "/user2/repo1/src/branch/master/a%2fb.txt"},
5656
{"/user2/repo1/src/master/directory/file.txt?a=1", "/user2/repo1/src/branch/master/directory/file.txt?a=1"},
5757
{"/user2/repo1/tree/a%2fb?a=1", "/user2/repo1/src/a%2fb?a=1"},
58+
{"/user2/repo1/blob/123456/%20?a=1", "/user2/repo1/src/commit/123456/%20?a=1"},
5859
{"/user/avatar/GhosT/-1", "/assets/img/avatar_default.png"},
5960
{"/user/avatar/Gitea-ActionS/0", "/assets/img/avatar_default.png"},
6061
{"/api/v1/swagger", "/api/swagger"},

tests/integration/oauth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestAuthorizeShow(t *testing.T) {
7777
resp := ctx.MakeRequest(t, req, http.StatusOK)
7878

7979
htmlDoc := NewHTMLParser(t, resp.Body)
80-
htmlDoc.AssertElement(t, "#authorize-app", true)
80+
AssertHTMLElement(t, htmlDoc, "#authorize-app", true)
8181
htmlDoc.GetCSRF()
8282
}
8383

0 commit comments

Comments
 (0)