mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
123 lines
3.8 KiB
Go
123 lines
3.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package files
|
|
|
|
import (
|
|
"html/template"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/git/models/unittest"
|
|
"github.com/hanzoai/git/modules/fileicon"
|
|
"github.com/hanzoai/git/modules/git"
|
|
api "github.com/hanzoai/git/modules/structs"
|
|
"github.com/hanzoai/git/services/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetTreeBySHA(t *testing.T) {
|
|
unittest.PrepareTestEnv(t)
|
|
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
contexttest.LoadRepoCommit(t, ctx)
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
contexttest.LoadGitRepo(t, ctx)
|
|
defer ctx.Repo.GitRepo.Close()
|
|
|
|
page := 1
|
|
perPage := 10
|
|
ctx.SetPathParam("sha", ctx.Repo.Repository.DefaultBranch)
|
|
|
|
tree, err := GetTreeBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.PathParam("sha"), page, perPage, true)
|
|
assert.NoError(t, err)
|
|
expectedTree := &api.GitTreeResponse{
|
|
SHA: "2a2f1d4670728a2e10049e345bd7a276468beab6",
|
|
URL: "https://try.gitea.io/v1/repos/user2/repo1/git/trees/2a2f1d4670728a2e10049e345bd7a276468beab6",
|
|
Entries: []api.GitEntry{
|
|
{
|
|
Path: "README.md",
|
|
Mode: "100644",
|
|
Type: "blob",
|
|
Size: 30,
|
|
SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f",
|
|
URL: "https://try.gitea.io/v1/repos/user2/repo1/git/blobs/4b4851ad51df6a7d9f25c979345979eaeb5b349f",
|
|
},
|
|
},
|
|
Truncated: false,
|
|
Page: 1,
|
|
TotalCount: 1,
|
|
}
|
|
|
|
assert.Equal(t, expectedTree, tree)
|
|
}
|
|
|
|
func TestGetTreeViewNodes(t *testing.T) {
|
|
unittest.PrepareTestEnv(t)
|
|
|
|
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
|
ctx.Repo.RefFullName = git.RefNameFromBranch("sub-home-md-img-check")
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
contexttest.LoadRepoCommit(t, ctx)
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
contexttest.LoadGitRepo(t, ctx)
|
|
defer ctx.Repo.GitRepo.Close()
|
|
|
|
curRepoLink := "/any/repo-link"
|
|
renderedIconPool := fileicon.NewRenderedIconPool()
|
|
mockIconForFile := func(id string) template.HTML {
|
|
return template.HTML(`<svg class="svg git-entry-icon octicon-file" width="16" height="16" aria-hidden="true"><use href="#` + id + `"></use></svg>`)
|
|
}
|
|
mockIconForFolder := func() template.HTML {
|
|
// With basic theme (default for folders), we get octicon icons without IDs
|
|
return template.HTML(`<span>octicon-file-directory-fill(16/)</span>`)
|
|
}
|
|
mockOpenIconForFolder := func() template.HTML {
|
|
// With basic theme (default for folders), we get octicon icons without IDs
|
|
return template.HTML(`<span>octicon-file-directory-open-fill(16/)</span>`)
|
|
}
|
|
treeNodes, err := GetTreeViewNodes(ctx, curRepoLink, renderedIconPool, ctx.Repo.GitRepo, ctx.Repo.Commit, "", "")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, []*TreeViewNode{
|
|
{
|
|
EntryName: "docs",
|
|
EntryMode: "tree",
|
|
FullPath: "docs",
|
|
EntryIcon: mockIconForFolder(),
|
|
EntryIconOpen: mockOpenIconForFolder(),
|
|
},
|
|
}, treeNodes)
|
|
|
|
treeNodes, err = GetTreeViewNodes(ctx, curRepoLink, renderedIconPool, ctx.Repo.GitRepo, ctx.Repo.Commit, "", "docs/README.md")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, []*TreeViewNode{
|
|
{
|
|
EntryName: "docs",
|
|
EntryMode: "tree",
|
|
FullPath: "docs",
|
|
EntryIcon: mockIconForFolder(),
|
|
EntryIconOpen: mockOpenIconForFolder(),
|
|
Children: []*TreeViewNode{
|
|
{
|
|
EntryName: "README.md",
|
|
EntryMode: "blob",
|
|
FullPath: "docs/README.md",
|
|
EntryIcon: mockIconForFile(`svg-mfi-readme`),
|
|
},
|
|
},
|
|
},
|
|
}, treeNodes)
|
|
|
|
treeNodes, err = GetTreeViewNodes(ctx, curRepoLink, renderedIconPool, ctx.Repo.GitRepo, ctx.Repo.Commit, "docs", "README.md")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, []*TreeViewNode{
|
|
{
|
|
EntryName: "README.md",
|
|
EntryMode: "blob",
|
|
FullPath: "docs/README.md",
|
|
EntryIcon: mockIconForFile(`svg-mfi-readme`),
|
|
},
|
|
}, treeNodes)
|
|
}
|