@@ -3,9 +3,12 @@ package controller
33import (
44 "context"
55 "encoding/hex"
6+ "errors"
67 "net/http"
78 "strings"
89
10+ "github.com/jiaozifs/jiaozifs/utils/hash"
11+
912 "github.com/jiaozifs/jiaozifs/auth"
1013
1114 "github.com/jiaozifs/jiaozifs/utils"
@@ -42,12 +45,7 @@ func (commitCtl CommitController) GetEntriesInRef(ctx context.Context, w *api.Ji
4245 return
4346 }
4447
45- if operator .Name == ownerName { //todo check permission
46- w .Forbidden ()
47- return
48- }
49-
50- refName := "main"
48+ refName := repository .HEAD
5149 if params .Path != nil {
5250 refName = * params .Ref
5351 }
@@ -58,24 +56,43 @@ func (commitCtl CommitController) GetEntriesInRef(ctx context.Context, w *api.Ji
5856 return
5957 }
6058
61- commit , err := commitCtl .Repo .CommitRepo (repository .ID ).Commit (ctx , ref .CommitHash )
62- if err != nil {
63- w .Error (err )
59+ if operator .Name != ownerName { //todo check permission
60+ w .Forbidden ()
6461 return
6562 }
6663
67- workTree , err := versionmgr .NewWorkTree (ctx , commitCtl .Repo .FileTreeRepo (repository .ID ), models .NewRootTreeEntry (commit .TreeHash ))
64+ treeHash := hash .EmptyHash
65+ if utils .BoolValue (params .IsWip ) {
66+ wip , err := commitCtl .Repo .WipRepo ().Get (ctx , models .NewGetWipParams ().SetCreatorID (operator .ID ).SetRepositoryID (repository .ID ).SetRefID (ref .ID ))
67+ if err != nil {
68+ w .Error (err )
69+ return
70+ }
71+ treeHash = wip .CurrentTree
72+ } else {
73+ if ! ref .CommitHash .IsEmpty () {
74+ commit , err := commitCtl .Repo .CommitRepo (repository .ID ).Commit (ctx , ref .CommitHash )
75+ if err != nil {
76+ w .Error (err )
77+ return
78+ }
79+ treeHash = commit .TreeHash
80+ }
81+ }
82+
83+ workTree , err := versionmgr .NewWorkTree (ctx , commitCtl .Repo .FileTreeRepo (repository .ID ), models .NewRootTreeEntry (treeHash ))
6884 if err != nil {
6985 w .Error (err )
7086 return
7187 }
7288
73- path := ""
74- if params .Path != nil {
75- path = * params .Path
76- }
89+ path := versionmgr .CleanPath (utils .StringValue (params .Path ))
7790 treeEntry , err := workTree .Ls (ctx , path )
7891 if err != nil {
92+ if errors .Is (err , versionmgr .ErrPathNotFound ) {
93+ w .NotFound ()
94+ return
95+ }
7996 w .Error (err )
8097 return
8198 }
@@ -101,7 +118,7 @@ func (commitCtl CommitController) GetCommitDiff(ctx context.Context, w *api.Jiao
101118 return
102119 }
103120
104- if operator .ID = = owner .ID { //todo check permission
121+ if operator .ID ! = owner .ID { //todo check permission
105122 w .Forbidden ()
106123 return
107124 }
@@ -129,11 +146,7 @@ func (commitCtl CommitController) GetCommitDiff(ctx context.Context, w *api.Jiao
129146 return
130147 }
131148
132- path := ""
133- if params .Path != nil {
134- path = * params .Path
135- }
136-
149+ path := versionmgr .CleanPath (utils .StringValue (params .Path ))
137150 commitOp := versionmgr .NewCommitOp (commitCtl .Repo , repository .ID , bashCommit )
138151 changes , err := commitOp .DiffCommit (ctx , toCommitHash )
139152 if err != nil {
@@ -150,7 +163,7 @@ func (commitCtl CommitController) GetCommitDiff(ctx context.Context, w *api.Jiao
150163 fullPath := change .Path ()
151164 if strings .HasPrefix (fullPath , path ) {
152165 apiChange := api.Change {
153- Action : int (action ),
166+ Action : api . ChangeAction (action ),
154167 Path : fullPath ,
155168 }
156169 if change .From () != nil {
0 commit comments