5
5
"fmt"
6
6
"io"
7
7
"os"
8
+ "slices"
8
9
"strings"
9
10
"testing"
10
11
@@ -195,7 +196,12 @@ var fixtures = Fixtures{{
195
196
}}
196
197
197
198
func All () Fixtures {
198
- return fixtures
199
+ all := make (Fixtures , 0 , len (fixtures ))
200
+ for _ , f := range fixtures {
201
+ all = append (all , f .Clone ())
202
+ }
203
+
204
+ return all
199
205
}
200
206
201
207
func Basic () Fixtures {
@@ -290,6 +296,20 @@ func (f *Fixture) DotGit(opts ...Option) billy.Filesystem {
290
296
return fs
291
297
}
292
298
299
+ func (f * Fixture ) Clone () * Fixture {
300
+ nf := & Fixture {
301
+ URL : f .URL ,
302
+ DotGitHash : f .DotGitHash ,
303
+ Head : f .Head ,
304
+ PackfileHash : f .PackfileHash ,
305
+ WorktreeHash : f .WorktreeHash ,
306
+ ObjectsCount : f .ObjectsCount ,
307
+ }
308
+ nf .Tags = slices .Clone (f .Tags )
309
+
310
+ return nf
311
+ }
312
+
293
313
// EnsureIsBare overrides the config file with one where bare is true.
294
314
func EnsureIsBare (fs billy.Filesystem ) error {
295
315
if _ , err := fs .Stat ("config" ); err != nil {
@@ -359,14 +379,14 @@ func (g Fixtures) One() *Fixture {
359
379
return nil
360
380
}
361
381
362
- return g [0 ]
382
+ return g [0 ]. Clone ()
363
383
}
364
384
365
385
func (g Fixtures ) ByTag (tag string ) Fixtures {
366
386
r := make (Fixtures , 0 , len (g ))
367
387
for _ , f := range g {
368
388
if f .Is (tag ) {
369
- r = append (r , f )
389
+ r = append (r , f . Clone () )
370
390
}
371
391
}
372
392
@@ -377,7 +397,7 @@ func (g Fixtures) ByURL(url string) Fixtures {
377
397
r := make (Fixtures , 0 , len (g ))
378
398
for _ , f := range g {
379
399
if f .URL == url {
380
- r = append (r , f )
400
+ r = append (r , f . Clone () )
381
401
}
382
402
}
383
403
@@ -388,7 +408,7 @@ func (g Fixtures) Exclude(tag string) Fixtures {
388
408
r := make (Fixtures , 0 , len (g ))
389
409
for _ , f := range g {
390
410
if ! f .Is (tag ) {
391
- r = append (r , f )
411
+ r = append (r , f . Clone () )
392
412
}
393
413
}
394
414
0 commit comments