mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 21:05:18 +02:00
Fix bug
This commit is contained in:
parent
fe63c5fbc1
commit
09000c4ce9
@ -56,7 +56,7 @@ func isExcludedEntry(entry *git.TreeEntry) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Tree(ctx *context.Context) {
|
func Tree(ctx *context.Context) {
|
||||||
dir := ctx.PathParam("*")
|
treePath := ctx.PathParam("*")
|
||||||
ref := ctx.FormTrim("ref")
|
ref := ctx.FormTrim("ref")
|
||||||
recursive := ctx.FormBool("recursive")
|
recursive := ctx.FormBool("recursive")
|
||||||
|
|
||||||
@ -70,9 +70,9 @@ func Tree(ctx *context.Context) {
|
|||||||
refName := gitRepo.UnstableGuessRefByShortName(ref)
|
refName := gitRepo.UnstableGuessRefByShortName(ref)
|
||||||
var results []*files_service.TreeEntry
|
var results []*files_service.TreeEntry
|
||||||
if !recursive {
|
if !recursive {
|
||||||
results, err = files_service.GetTreeList(ctx, ctx.Repo.Repository, dir, refName, false)
|
results, err = files_service.GetTreeList(ctx, ctx.Repo.Repository, treePath, refName, false)
|
||||||
} else {
|
} else {
|
||||||
results, err = files_service.GetTreeInformation(ctx, ctx.Repo.Repository, dir, refName)
|
results, err = files_service.GetTreeInformation(ctx, ctx.Repo.Repository, treePath, refName)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetTreeInformation", err)
|
ctx.ServerError("GetTreeInformation", err)
|
||||||
|
@ -416,14 +416,19 @@ func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, treePa
|
|||||||
var treeList []*TreeEntry
|
var treeList []*TreeEntry
|
||||||
var parentEntry *TreeEntry
|
var parentEntry *TreeEntry
|
||||||
fields := strings.SplitN(treePath, "/", 2)
|
fields := strings.SplitN(treePath, "/", 2)
|
||||||
for _, rootEntry := range rootEntries {
|
for _, entry := range rootEntries {
|
||||||
treeEntry := &TreeEntry{
|
treeEntry := &TreeEntry{
|
||||||
Name: rootEntry.Name(),
|
Name: entry.Name(),
|
||||||
IsFile: rootEntry.Mode() != git.EntryModeTree,
|
IsFile: entry.Mode() != git.EntryModeTree,
|
||||||
Path: rootEntry.Name(),
|
Path: entry.Name(),
|
||||||
}
|
}
|
||||||
treeList = append(treeList, treeEntry)
|
treeList = append(treeList, treeEntry)
|
||||||
if fields[0] == rootEntry.Name() {
|
if fields[0] == entry.Name() {
|
||||||
|
if len(fields) == 1 {
|
||||||
|
if treeEntry.IsFile {
|
||||||
|
return treeList, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
parentEntry = treeEntry
|
parentEntry = treeEntry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,14 @@ func Test_GetTreeInformation(t *testing.T) {
|
|||||||
assert.True(t, treeList[0].IsFile)
|
assert.True(t, treeList[0].IsFile)
|
||||||
assert.Empty(t, treeList[0].Children)
|
assert.Empty(t, treeList[0].Children)
|
||||||
|
|
||||||
|
treeList, err = GetTreeInformation(ctx1, ctx1.Repo.Repository, "README.md", refName)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, treeList, 1)
|
||||||
|
assert.EqualValues(t, "README.md", treeList[0].Name)
|
||||||
|
assert.EqualValues(t, "README.md", treeList[0].Path)
|
||||||
|
assert.True(t, treeList[0].IsFile)
|
||||||
|
assert.Empty(t, treeList[0].Children)
|
||||||
|
|
||||||
ctx2, _ := contexttest.MockContext(t, "org3/repo3")
|
ctx2, _ := contexttest.MockContext(t, "org3/repo3")
|
||||||
contexttest.LoadRepo(t, ctx2, 3)
|
contexttest.LoadRepo(t, ctx2, 3)
|
||||||
contexttest.LoadRepoCommit(t, ctx2)
|
contexttest.LoadRepoCommit(t, ctx2)
|
||||||
@ -143,36 +151,37 @@ func Test_GetTreeInformation(t *testing.T) {
|
|||||||
treeList, err = GetTreeInformation(ctx2, ctx2.Repo.Repository, "doc", refName)
|
treeList, err = GetTreeInformation(ctx2, ctx2.Repo.Repository, "doc", refName)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, treeList, 2)
|
assert.Len(t, treeList, 2)
|
||||||
assert.EqualValues(t, "README.md", treeList[0].Name)
|
assert.EqualValues(t, "doc", treeList[0].Name)
|
||||||
assert.EqualValues(t, "README.md", treeList[0].Path)
|
assert.EqualValues(t, "doc", treeList[0].Path)
|
||||||
assert.True(t, treeList[0].IsFile)
|
assert.False(t, treeList[0].IsFile)
|
||||||
assert.Empty(t, treeList[0].Children)
|
assert.Len(t, treeList[0].Children, 1)
|
||||||
|
|
||||||
assert.EqualValues(t, "doc", treeList[1].Name)
|
assert.EqualValues(t, "doc.md", treeList[0].Children[0].Name)
|
||||||
assert.EqualValues(t, "doc", treeList[1].Path)
|
assert.EqualValues(t, "doc/doc.md", treeList[0].Children[0].Path)
|
||||||
assert.False(t, treeList[1].IsFile)
|
assert.True(t, treeList[0].Children[0].IsFile)
|
||||||
assert.Len(t, treeList[1].Children, 1)
|
assert.Empty(t, treeList[0].Children[0].Children)
|
||||||
|
|
||||||
assert.EqualValues(t, "doc.md", treeList[1].Children[0].Name)
|
assert.EqualValues(t, "README.md", treeList[1].Name)
|
||||||
assert.EqualValues(t, "doc/doc.md", treeList[1].Children[0].Path)
|
assert.EqualValues(t, "README.md", treeList[1].Path)
|
||||||
assert.True(t, treeList[1].Children[0].IsFile)
|
assert.True(t, treeList[1].IsFile)
|
||||||
assert.Empty(t, treeList[1].Children[0].Children)
|
assert.Empty(t, treeList[1].Children)
|
||||||
|
|
||||||
treeList, err = GetTreeInformation(ctx2, ctx2.Repo.Repository, "doc/doc.md", refName)
|
treeList, err = GetTreeInformation(ctx2, ctx2.Repo.Repository, "doc/doc.md", refName)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, treeList, 2)
|
assert.Len(t, treeList, 2)
|
||||||
assert.EqualValues(t, "README.md", treeList[0].Name)
|
|
||||||
assert.EqualValues(t, "README.md", treeList[0].Path)
|
|
||||||
assert.True(t, treeList[0].IsFile)
|
|
||||||
assert.Empty(t, treeList[0].Children)
|
|
||||||
|
|
||||||
assert.EqualValues(t, "doc", treeList[1].Name)
|
assert.EqualValues(t, "doc", treeList[0].Name)
|
||||||
assert.EqualValues(t, "doc", treeList[1].Path)
|
assert.EqualValues(t, "doc", treeList[0].Path)
|
||||||
assert.False(t, treeList[1].IsFile)
|
assert.False(t, treeList[0].IsFile)
|
||||||
assert.Len(t, treeList[1].Children, 1)
|
assert.Len(t, treeList[0].Children, 1)
|
||||||
|
|
||||||
assert.EqualValues(t, "doc.md", treeList[1].Children[0].Name)
|
assert.EqualValues(t, "doc.md", treeList[0].Children[0].Name)
|
||||||
assert.EqualValues(t, "doc/doc.md", treeList[1].Children[0].Path)
|
assert.EqualValues(t, "doc/doc.md", treeList[0].Children[0].Path)
|
||||||
assert.True(t, treeList[1].Children[0].IsFile)
|
assert.True(t, treeList[0].Children[0].IsFile)
|
||||||
assert.Empty(t, treeList[1].Children[0].Children)
|
assert.Empty(t, treeList[0].Children[0].Children)
|
||||||
|
|
||||||
|
assert.EqualValues(t, "README.md", treeList[1].Name)
|
||||||
|
assert.EqualValues(t, "README.md", treeList[1].Path)
|
||||||
|
assert.True(t, treeList[1].IsFile)
|
||||||
|
assert.Empty(t, treeList[1].Children)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user