Skip to content

Commit 96e050e

Browse files
committed
Fix bugs
1 parent 91f972c commit 96e050e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

services/repository/files/tree.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,15 @@ func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, treePa
425425
}
426426
dir = treePath
427427
if lastDirEntry.IsRegular() {
428-
dir = path.Dir(treePath)
429-
lastDirEntry, err = commit.GetTreeEntryByPath(dir)
430-
if err != nil {
431-
return nil, err
428+
// path.Dir cannot correctly handle .xxx file
429+
dir, _ = path.Split(treePath)
430+
if dir == "" {
431+
lastDirEntry = rootEntry
432+
} else {
433+
lastDirEntry, err = commit.GetTreeEntryByPath(dir)
434+
if err != nil {
435+
return nil, err
436+
}
432437
}
433438
}
434439
}
@@ -448,6 +453,7 @@ func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, treePa
448453
}
449454
}
450455

456+
sortTreeEntries(treeList)
451457
if dir == "" || parentEntry == nil {
452458
return treeList, nil
453459
}
@@ -475,7 +481,6 @@ func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, treePa
475481
Path: path.Join(dir, entry.Name()),
476482
})
477483
}
478-
sortTreeEntries(treeList)
479484
sortTreeEntries(parentEntry.Children)
480485
return treeList, nil
481486
}

0 commit comments

Comments
 (0)