@@ -37,29 +37,52 @@ func GetDirInfos(ctx *context.APIContext) {
37
37
ctx .JSON (http .StatusOK , entries )
38
38
}
39
39
40
- func getDirectoryEntries (ctx * context.APIContext , branch , folder string ) ([]structs.GitEntry , error ) {
41
- tree , err := ctx .Repo .Commit .SubTree (folder )
40
+ func getDirectoryEntries (ctx * context.APIContext , branch , path string ) ([]structs.GitEntry , error ) {
41
+ var (
42
+ allEntries git.Entries
43
+ commits []git.CommitInfo
44
+ )
45
+ entry , err := ctx .Repo .Commit .GetTreeEntryByPath (path )
42
46
if err != nil {
43
- return nil , fmt . Errorf ( "failed to exec SubTree, cause:%w" , err )
47
+ return nil , err
44
48
}
45
49
46
- allEntries , err := tree .ListEntries ()
47
- if err != nil {
48
- return nil , fmt .Errorf ("failed to exec ListEntries, cause:%w" , err )
49
- }
50
- allEntries .CustomSort (base .NaturalSortLess )
50
+ if entry .Type () != "tree" {
51
+ allEntries = append (allEntries , entry )
52
+ commit , err := ctx .Repo .Commit .GetCommitByPath (path )
53
+ if err != nil {
54
+ return nil , err
55
+ }
51
56
52
- var commits []git.CommitInfo
53
- commits , _ , err = allEntries .GetCommitsInfo (ctx , ctx .Repo .Commit , folder )
54
- if err != nil {
55
- return nil , fmt .Errorf ("failed to exec GetCommitsInfo, cause:%w" , err )
57
+ commitInfo := git.CommitInfo {
58
+ Entry : entry ,
59
+ Commit : commit ,
60
+ }
61
+ commits = append (commits , commitInfo )
62
+
63
+ } else {
64
+ tree , err := ctx .Repo .Commit .SubTree (path )
65
+ if err != nil {
66
+ return nil , fmt .Errorf ("failed to exec SubTree, cause:%w" , err )
67
+ }
68
+
69
+ allEntries , err := tree .ListEntries ()
70
+ if err != nil {
71
+ return nil , fmt .Errorf ("failed to exec ListEntries, cause:%w" , err )
72
+ }
73
+ allEntries .CustomSort (base .NaturalSortLess )
74
+
75
+ commits , _ , err = allEntries .GetCommitsInfo (ctx , ctx .Repo .Commit , path )
76
+ if err != nil {
77
+ return nil , fmt .Errorf ("failed to exec GetCommitsInfo, cause:%w" , err )
78
+ }
56
79
}
57
80
58
81
var ges = make ([]structs.GitEntry , 0 , len (commits ))
59
82
for _ , c := range commits {
60
83
e := structs.GitEntry {
61
84
Name : c .Entry .Name (),
62
- Path : folder + "/" + c .Entry .Name (),
85
+ Path : path + "/" + c .Entry .Name (),
63
86
Mode : c .Entry .Mode ().String (),
64
87
Type : c .Entry .Type (),
65
88
Size : c .Entry .Size (),
0 commit comments