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

Method TestClean

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

Source from the content-addressed store, hash-verified

2321}
2322
2323func (s *WorktreeSuite) TestClean(c *C) {
2324 fs := fixtures.ByTag("dirty").One().Worktree()
2325
2326 // Open the repo.
2327 fs, err := fs.Chroot("repo")
2328 c.Assert(err, IsNil)
2329 r, err := PlainOpen(fs.Root())
2330 c.Assert(err, IsNil)
2331
2332 wt, err := r.Worktree()
2333 c.Assert(err, IsNil)
2334
2335 // Status before cleaning.
2336 status, err := wt.Status()
2337 c.Assert(err, IsNil)
2338 c.Assert(len(status), Equals, 2)
2339
2340 err = wt.Clean(&CleanOptions{})
2341 c.Assert(err, IsNil)
2342
2343 // Status after cleaning.
2344 status, err = wt.Status()
2345 c.Assert(err, IsNil)
2346
2347 c.Assert(len(status), Equals, 1)
2348
2349 fi, err := fs.Lstat("pkgA")
2350 c.Assert(err, IsNil)
2351 c.Assert(fi.IsDir(), Equals, true)
2352
2353 // Clean with Dir: true.
2354 err = wt.Clean(&CleanOptions{Dir: true})
2355 c.Assert(err, IsNil)
2356
2357 status, err = wt.Status()
2358 c.Assert(err, IsNil)
2359
2360 c.Assert(len(status), Equals, 0)
2361
2362 // An empty dir should be deleted, as well.
2363 _, err = fs.Lstat("pkgA")
2364 c.Assert(err, ErrorMatches, ".*(no such file or directory.*|.*file does not exist)*.")
2365}
2366
2367func (s *WorktreeSuite) TestCleanBare(c *C) {
2368 storer := memory.NewStorage()

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected