MCPcopy
hub / github.com/go-git/go-git / TestCheckoutKeep

Method TestCheckoutKeep

worktree_test.go:407–445  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

405}
406
407func (s *WorktreeSuite) TestCheckoutKeep(c *C) {
408 w := &Worktree{
409 r: s.Repository,
410 Filesystem: memfs.New(),
411 }
412
413 err := w.Checkout(&CheckoutOptions{
414 Force: true,
415 })
416 c.Assert(err, IsNil)
417
418 // Create a new branch and create a new file.
419 err = w.Checkout(&CheckoutOptions{
420 Branch: plumbing.NewBranchReferenceName("new-branch"),
421 Create: true,
422 })
423 c.Assert(err, IsNil)
424
425 w.Filesystem = memfs.New()
426 f, err := w.Filesystem.Create("new-file.txt")
427 c.Assert(err, IsNil)
428 _, err = f.Write([]byte("DUMMY"))
429 c.Assert(err, IsNil)
430 c.Assert(f.Close(), IsNil)
431
432 // Add the file to staging.
433 _, err = w.Add("new-file.txt")
434 c.Assert(err, IsNil)
435
436 // Switch branch to master, and verify that the new file was kept in staging.
437 err = w.Checkout(&CheckoutOptions{
438 Keep: true,
439 })
440 c.Assert(err, IsNil)
441
442 fi, err := w.Filesystem.Stat("new-file.txt")
443 c.Assert(err, IsNil)
444 c.Assert(fi.Size(), Equals, int64(5))
445}
446
447func (s *WorktreeSuite) TestCheckoutSymlink(c *C) {
448 if runtime.GOOS == "windows" {

Callers

nothing calls this directly

Calls 8

CheckoutMethod · 0.95
AddMethod · 0.95
NewBranchReferenceNameFunction · 0.92
CloseMethod · 0.65
StatMethod · 0.65
SizeMethod · 0.65
CreateMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected