MCPcopy Create free account
hub / github.com/go-git/go-git / TestCheckoutKeep

Method TestCheckoutKeep

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected