diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 5b8f35f5b1..082716adbc 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -45,10 +45,19 @@ const ( func RefCommits(ctx *context.Context) { switch { case len(ctx.Repo.TreePath) == 0: + ctx.Data["TreeNames"] = []string{} Commits(ctx) case ctx.Repo.TreePath == "search": + ctx.Data["TreeNames"] = []string{} SearchCommits(ctx) default: + treeNames := strings.Split(ctx.Repo.TreePath, "/") + paths := make([]string, len(treeNames)) + for i := range treeNames { + paths[i] = strings.Join(treeNames[:i+1], "/") + } + ctx.Data["TreeNames"] = treeNames + ctx.Data["Paths"] = paths FileHistory(ctx) } } @@ -272,6 +281,9 @@ func FileHistory(ctx *context.Context) { } } + branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL() + ctx.Data["BranchLink"] = branchLink + ctx.Data["Commits"] = git_model.ParseCommitsWithStatus(ctx, commits, ctx.Repo.Repository) ctx.Data["Username"] = ctx.Repo.Owner.Name diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index e6efe1ff54..b9ea9c790a 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -10,6 +10,7 @@ {{svg "octicon-git-branch"}} {{ctx.Locale.Tr "repo.commit_graph"}} + {{template "repo/filepath" .}} {{template "repo/commits_table" .}} diff --git a/templates/repo/filepath.tmpl b/templates/repo/filepath.tmpl new file mode 100644 index 0000000000..6473ffd356 --- /dev/null +++ b/templates/repo/filepath.tmpl @@ -0,0 +1,17 @@ +{{$n := len .TreeNames}} +{{$l := Eval $n "-" 1}} +{{$showFilePath := (gt $n 0)}} +{{if $showFilePath}} + + {{StringUtils.EllipsisString .Repository.Name 30}} + {{- range $i, $v := .TreeNames -}} + / + {{- if eq $i $l -}} + {{$v}} + + {{- else -}} + {{$p := index $.Paths $i}}{{$v}} + {{- end -}} + {{- end -}} + +{{end}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index eb27af5d54..601605ba44 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -102,20 +102,7 @@ {{ctx.Locale.Tr "repo.use_template"}} {{end}} - {{if (not $isHomepage)}} - - {{StringUtils.EllipsisString .Repository.Name 30}} - {{- range $i, $v := .TreeNames -}} - / - {{- if eq $i $l -}} - {{$v}} - - {{- else -}} - {{$p := index $.Paths $i}}{{$v}} - {{- end -}} - {{- end -}} - - {{end}} + {{template "repo/filepath" .}}
diff --git a/tests/integration/repo_commits_search_test.go b/tests/integration/repo_commits_search_test.go index 5d7d215678..30ee0e55ef 100644 --- a/tests/integration/repo_commits_search_test.go +++ b/tests/integration/repo_commits_search_test.go @@ -24,6 +24,7 @@ func testRepoCommitsSearch(t *testing.T, query, commit string) { doc := NewHTMLParser(t, resp.Body) sel := doc.doc.Find("#commits-table tbody tr td.sha a") assert.Equal(t, commit, strings.TrimSpace(sel.Text())) + doc.AssertElement(t, ".repo-path", false) } func TestRepoCommitsSearch(t *testing.T) { diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index d2bb4e8849..26522fe481 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -34,6 +34,7 @@ func TestRepoCommits(t *testing.T) { commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href") assert.True(t, exists) assert.NotEmpty(t, commitURL) + doc.AssertElement(t, ".repo-path", false) } func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) { diff --git a/tests/integration/view_test.go b/tests/integration/view_test.go index bc858e71e8..fee9393409 100644 --- a/tests/integration/view_test.go +++ b/tests/integration/view_test.go @@ -139,7 +139,7 @@ func TestCommitListActions(t *testing.T) { []*files_service.ChangeRepoFile{ { Operation: "create", - TreePath: "test.sh", + TreePath: "test/test.sh", ContentReader: strings.NewReader("Hello there!"), }, }, @@ -162,7 +162,7 @@ func TestCommitListActions(t *testing.T) { htmlDoc.AssertElement(t, fmt.Sprintf(".commit-list a[href^='/%s/src/commit/']", repo.FullName()), false) }) - fileDiffSelector := fmt.Sprintf(".commit-list a[href='/%s/commit/%s?files=test.sh']", repo.FullName(), commitID) + fileDiffSelector := fmt.Sprintf(".commit-list a[href='/%s/commit/%s?files=test/test.sh']", repo.FullName(), commitID) t.Run("Commit list", func(t *testing.T) { defer tests.PrintCurrentTest(t)() @@ -177,12 +177,19 @@ func TestCommitListActions(t *testing.T) { t.Run("File history", func(t *testing.T) { defer tests.PrintCurrentTest(t)() - req := NewRequest(t, "GET", repo.Link()+"/commits/branch/main/test.sh") + req := NewRequest(t, "GET", repo.Link()+"/commits/branch/main/test/test.sh") resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - htmlDoc.AssertElement(t, fmt.Sprintf(".commit-list a[href='/%s/src/commit/%s/test.sh']", repo.FullName(), commitID), true) + htmlDoc.AssertElement(t, fmt.Sprintf(".commit-list a[href='/%s/src/commit/%s/test/test.sh']", repo.FullName(), commitID), true) htmlDoc.AssertElement(t, fileDiffSelector, true) + + htmlDoc.AssertElement(t, ".repo-path", true) + htmlDoc.AssertElement(t, fmt.Sprintf(".repo-path a[href='/%s/src/branch/main'][title='%s']", repo.FullName(), repo.Name), true) + assert.Equal(t, 2, htmlDoc.Find(".repo-path .breadcrumb-divider").Length()) + htmlDoc.AssertElement(t, fmt.Sprintf(".repo-path .section a[href='/%s/src/branch/main/test'][title='test']", repo.FullName()), true) + htmlDoc.AssertElement(t, ".repo-path .active[title='test.sh']", true) + htmlDoc.AssertElement(t, ".repo-path button[data-clipboard-text='test/test.sh']", true) }) }) }