@@ -19,6 +19,7 @@ import (
1919
2020 "code.gitea.io/gitea/models"
2121 "code.gitea.io/gitea/modules/git"
22+ "code.gitea.io/gitea/modules/setting"
2223 api "code.gitea.io/gitea/modules/structs"
2324
2425 "github.com/stretchr/testify/assert"
@@ -135,13 +136,33 @@ func standardCommitAndPushTest(t *testing.T, dstPath string) (little, big string
135136func lfsCommitAndPushTest (t * testing.T , dstPath string ) (littleLFS , bigLFS string ) {
136137 t .Run ("LFS" , func (t * testing.T ) {
137138 PrintCurrentTest (t )
139+ setting .CheckLFSVersion ()
140+ if ! setting .LFS .StartServer {
141+ t .Skip ()
142+ return
143+ }
138144 prefix := "lfs-data-file-"
139145 _ , err := git .NewCommand ("lfs" ).AddArguments ("install" ).RunInDir (dstPath )
140146 assert .NoError (t , err )
141147 _ , err = git .NewCommand ("lfs" ).AddArguments ("track" , prefix + "*" ).RunInDir (dstPath )
142148 assert .NoError (t , err )
143149 err = git .AddChanges (dstPath , false , ".gitattributes" )
144150 assert .NoError (t , err )
151+ oldGlobals := allowLFSFilters ()
152+ err = git .CommitChanges (dstPath , git.CommitChangesOptions {
153+ Committer : & git.Signature {
154+ 155+ Name : "User Two" ,
156+ When : time .Now (),
157+ },
158+ Author : & git.Signature {
159+ 160+ Name : "User Two" ,
161+ When : time .Now (),
162+ },
163+ Message : fmt .Sprintf ("Testing commit @ %v" , time .Now ()),
164+ })
165+ git .GlobalCommandArgs = oldGlobals
145166
146167 littleLFS , bigLFS = commitAndPushTest (t , dstPath , prefix )
147168
@@ -185,20 +206,25 @@ func rawTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS s
185206 resp := session .MakeRequest (t , req , http .StatusOK )
186207 assert .Equal (t , littleSize , resp .Body .Len ())
187208
188- req = NewRequest (t , "GET" , path .Join ("/" , username , reponame , "/raw/branch/master/" , littleLFS ))
189- resp = session .MakeRequest (t , req , http .StatusOK )
190- assert .NotEqual (t , littleSize , resp .Body .Len ())
191- assert .Contains (t , resp .Body .String (), models .LFSMetaFileIdentifier )
209+ setting .CheckLFSVersion ()
210+ if setting .LFS .StartServer {
211+ req = NewRequest (t , "GET" , path .Join ("/" , username , reponame , "/raw/branch/master/" , littleLFS ))
212+ resp = session .MakeRequest (t , req , http .StatusOK )
213+ assert .NotEqual (t , littleSize , resp .Body .Len ())
214+ assert .Contains (t , resp .Body .String (), models .LFSMetaFileIdentifier )
215+ }
192216
193217 if ! testing .Short () {
194218 req = NewRequest (t , "GET" , path .Join ("/" , username , reponame , "/raw/branch/master/" , big ))
195219 resp = session .MakeRequest (t , req , http .StatusOK )
196220 assert .Equal (t , bigSize , resp .Body .Len ())
197221
198- req = NewRequest (t , "GET" , path .Join ("/" , username , reponame , "/raw/branch/master/" , bigLFS ))
199- resp = session .MakeRequest (t , req , http .StatusOK )
200- assert .NotEqual (t , bigSize , resp .Body .Len ())
201- assert .Contains (t , resp .Body .String (), models .LFSMetaFileIdentifier )
222+ if setting .LFS .StartServer {
223+ req = NewRequest (t , "GET" , path .Join ("/" , username , reponame , "/raw/branch/master/" , bigLFS ))
224+ resp = session .MakeRequest (t , req , http .StatusOK )
225+ assert .NotEqual (t , bigSize , resp .Body .Len ())
226+ assert .Contains (t , resp .Body .String (), models .LFSMetaFileIdentifier )
227+ }
202228 }
203229 })
204230}
@@ -217,18 +243,23 @@ func mediaTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS
217243 resp := session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
218244 assert .Equal (t , littleSize , resp .Length )
219245
220- req = NewRequest (t , "GET" , path .Join ("/" , username , reponame , "/media/branch/master/" , littleLFS ))
221- resp = session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
222- assert .Equal (t , littleSize , resp .Length )
246+ setting .CheckLFSVersion ()
247+ if setting .LFS .StartServer {
248+ req = NewRequest (t , "GET" , path .Join ("/" , username , reponame , "/media/branch/master/" , littleLFS ))
249+ resp = session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
250+ assert .Equal (t , littleSize , resp .Length )
251+ }
223252
224253 if ! testing .Short () {
225254 req = NewRequest (t , "GET" , path .Join ("/" , username , reponame , "/media/branch/master/" , big ))
226255 resp = session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
227256 assert .Equal (t , bigSize , resp .Length )
228257
229- req = NewRequest (t , "GET" , path .Join ("/" , username , reponame , "/media/branch/master/" , bigLFS ))
230- resp = session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
231- assert .Equal (t , bigSize , resp .Length )
258+ if setting .LFS .StartServer {
259+ req = NewRequest (t , "GET" , path .Join ("/" , username , reponame , "/media/branch/master/" , bigLFS ))
260+ resp = session .MakeRequestNilResponseRecorder (t , req , http .StatusOK )
261+ assert .Equal (t , bigSize , resp .Length )
262+ }
232263 }
233264 })
234265}
@@ -274,6 +305,8 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin
274305 }
275306
276307 //Commit
308+ // Now here we should explicitly allow lfs filters to run
309+ oldGlobals := allowLFSFilters ()
277310 err = git .AddChanges (repoPath , false , filepath .Base (tmpFile .Name ()))
278311 if err != nil {
279312 return "" , err
@@ -291,6 +324,7 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin
291324 },
292325 Message : fmt .Sprintf ("Testing commit @ %v" , time .Now ()),
293326 })
327+ git .GlobalCommandArgs = oldGlobals
294328 return filepath .Base (tmpFile .Name ()), err
295329}
296330
0 commit comments