@@ -314,6 +314,46 @@ func (s *WorktreeSuite) TestCheckoutForce(c *C) {
314
314
c .Assert (entries , HasLen , 8 )
315
315
}
316
316
317
+ func (s * WorktreeSuite ) TestCheckoutKeep (c * C ) {
318
+ w := & Worktree {
319
+ r : s .Repository ,
320
+ Filesystem : memfs .New (),
321
+ }
322
+
323
+ err := w .Checkout (& CheckoutOptions {
324
+ Force : true ,
325
+ })
326
+ c .Assert (err , IsNil )
327
+
328
+ // Create a new branch and create a new file.
329
+ err = w .Checkout (& CheckoutOptions {
330
+ Branch : plumbing .NewBranchReferenceName ("new-branch" ),
331
+ Create : true ,
332
+ })
333
+ c .Assert (err , IsNil )
334
+
335
+ w .Filesystem = memfs .New ()
336
+ f , err := w .Filesystem .Create ("new-file.txt" )
337
+ c .Assert (err , IsNil )
338
+ _ , err = f .Write ([]byte ("DUMMY" ))
339
+ c .Assert (err , IsNil )
340
+ c .Assert (f .Close (), IsNil )
341
+
342
+ // Add the file to staging.
343
+ _ , err = w .Add ("new-file.txt" )
344
+ c .Assert (err , IsNil )
345
+
346
+ // Switch branch to master, and verify that the new file was kept in staging.
347
+ err = w .Checkout (& CheckoutOptions {
348
+ Keep : true ,
349
+ })
350
+ c .Assert (err , IsNil )
351
+
352
+ fi , err := w .Filesystem .Stat ("new-file.txt" )
353
+ c .Assert (err , IsNil )
354
+ c .Assert (fi .Size (), Equals , int64 (5 ))
355
+ }
356
+
317
357
func (s * WorktreeSuite ) TestCheckoutSymlink (c * C ) {
318
358
if runtime .GOOS == "windows" {
319
359
c .Skip ("git doesn't support symlinks by default in windows" )
0 commit comments