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

Method TestClean

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

Source from the content-addressed store, hash-verified

2578}
2579
2580func (s *WorktreeSuite) TestClean(c *C) {
2581 fs := fixtures.ByTag("dirty").One().Worktree()
2582
2583 // Open the repo.
2584 fs, err := fs.Chroot("repo")
2585 c.Assert(err, IsNil)
2586 r, err := PlainOpen(fs.Root())
2587 c.Assert(err, IsNil)
2588
2589 wt, err := r.Worktree()
2590 c.Assert(err, IsNil)
2591
2592 // Status before cleaning.
2593 status, err := wt.Status()
2594 c.Assert(err, IsNil)
2595 c.Assert(len(status), Equals, 2)
2596
2597 err = wt.Clean(&CleanOptions{})
2598 c.Assert(err, IsNil)
2599
2600 // Status after cleaning.
2601 status, err = wt.Status()
2602 c.Assert(err, IsNil)
2603
2604 c.Assert(len(status), Equals, 1)
2605
2606 fi, err := fs.Lstat("pkgA")
2607 c.Assert(err, IsNil)
2608 c.Assert(fi.IsDir(), Equals, true)
2609
2610 // Clean with Dir: true.
2611 err = wt.Clean(&CleanOptions{Dir: true})
2612 c.Assert(err, IsNil)
2613
2614 status, err = wt.Status()
2615 c.Assert(err, IsNil)
2616
2617 c.Assert(len(status), Equals, 0)
2618
2619 // An empty dir should be deleted, as well.
2620 _, err = fs.Lstat("pkgA")
2621 c.Assert(err, ErrorMatches, ".*(no such file or directory.*|.*file does not exist)*.")
2622}
2623
2624func (s *WorktreeSuite) TestCleanBare(c *C) {
2625 storer := memory.NewStorage()

Callers

nothing calls this directly

Calls 8

PlainOpenFunction · 0.85
WorktreeMethod · 0.80
RootMethod · 0.80
CleanMethod · 0.80
IsDirMethod · 0.65
ChrootMethod · 0.45
StatusMethod · 0.45
LstatMethod · 0.45

Tested by

no test coverage detected