Files
forge/routers/web/repo/view_readme_test.go
zeekayandHanzo Dev aa87442fdd Record upstream authorship centrally in NOTICE instead of in every file header
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the
Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in
NOTICE, alongside LICENSE. The header lint accepts any copyright line above the
SPDX line, so it no longer demands an upstream one.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-10 17:50:35 -07:00

72 lines
2.0 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// SPDX-License-Identifier: MIT
package repo
import (
"fmt"
"path"
"testing"
"github.com/hanzoai/git/modules/git"
"github.com/hanzoai/git/modules/git/gitcmd"
"github.com/hanzoai/git/services/contexttest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFindReadmeFileInEntriesWithSymlinkInSubfolder(t *testing.T) {
for _, subdir := range []string{".github", ".hanzo", "docs"} {
t.Run(subdir, func(t *testing.T) {
repoPath := t.TempDir()
stdin := fmt.Sprintf(`commit refs/heads/master
author Test <[email protected]> 1700000000 +0000
committer Test <[email protected]> 1700000000 +0000
data <<EOT
initial
EOT
M 100644 inline target.md
data <<EOT
target-content
EOT
M 120000 inline %s/README.md
data 12
../target.md
`, subdir)
var err error
err = gitcmd.NewCommand("init", "--bare", ".").WithDir(repoPath).RunWithStderr(t.Context())
require.NoError(t, err)
err = gitcmd.NewCommand("fast-import").WithDir(repoPath).WithStdinBytes([]byte(stdin)).RunWithStderr(t.Context())
require.NoError(t, err)
gitRepo, err := git.OpenRepository(t.Context(), repoPath)
require.NoError(t, err)
defer gitRepo.Close()
commit, err := gitRepo.GetBranchCommit("master")
require.NoError(t, err)
entries, err := commit.Tree().ListEntries(t.Context(), gitRepo)
require.NoError(t, err)
ctx, _ := contexttest.MockContext(t, "/")
ctx.Repo.Commit = commit
ctx.Repo.GitRepo = gitRepo
foundDir, foundReadme, err := findReadmeFileInEntries(ctx, "", entries, true)
require.NoError(t, err)
require.NotNil(t, foundReadme)
assert.Equal(t, subdir, foundDir)
assert.Equal(t, "README.md", foundReadme.Name())
assert.True(t, foundReadme.IsLink())
// Verify that it can follow the link
res, err := git.EntryFollowLinks(t.Context(), gitRepo, commit, path.Join(foundDir, foundReadme.Name()), foundReadme)
require.NoError(t, err)
assert.Equal(t, "target.md", res.TargetFullPath)
})
}
}