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

Method TestAddSkipStatusWithIgnoredPath

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

Source from the content-addressed store, hash-verified

2039}
2040
2041func (s *WorktreeSuite) TestAddSkipStatusWithIgnoredPath(c *C) {
2042 fs := memfs.New()
2043 w := &Worktree{
2044 r: s.Repository,
2045 Filesystem: fs,
2046 }
2047
2048 err := w.Checkout(&CheckoutOptions{Force: true})
2049 c.Assert(err, IsNil)
2050
2051 idx, err := w.r.Storer.Index()
2052 c.Assert(err, IsNil)
2053 c.Assert(idx.Entries, HasLen, 9)
2054
2055 err = util.WriteFile(fs, ".gitignore", []byte("fileToIgnore\n"), 0755)
2056 c.Assert(err, IsNil)
2057 _, err = w.Add(".gitignore")
2058 c.Assert(err, IsNil)
2059 _, err = w.Commit("Added .gitignore", defaultTestCommitOptions)
2060 c.Assert(err, IsNil)
2061
2062 err = util.WriteFile(fs, "fileToIgnore", []byte("file to ignore"), 0644)
2063 c.Assert(err, IsNil)
2064
2065 status, err := w.Status()
2066 c.Assert(err, IsNil)
2067 c.Assert(status, HasLen, 0)
2068
2069 file := status.File("fileToIgnore")
2070 c.Assert(file.Staging, Equals, Untracked)
2071 c.Assert(file.Worktree, Equals, Untracked)
2072
2073 err = w.AddWithOptions(&AddOptions{Path: "fileToIgnore", SkipStatus: true})
2074 c.Assert(err, IsNil)
2075
2076 idx, err = w.r.Storer.Index()
2077 c.Assert(err, IsNil)
2078 c.Assert(idx.Entries, HasLen, 10)
2079
2080 e, err := idx.Entry("fileToIgnore")
2081 c.Assert(err, IsNil)
2082 c.Assert(e.Mode, Equals, filemode.Regular)
2083
2084 status, err = w.Status()
2085 c.Assert(err, IsNil)
2086 c.Assert(status, HasLen, 1)
2087
2088 file = status.File("fileToIgnore")
2089 c.Assert(file.Staging, Equals, Added)
2090 c.Assert(file.Worktree, Equals, Unmodified)
2091}
2092
2093func (s *WorktreeSuite) TestRemove(c *C) {
2094 fs := memfs.New()

Callers

nothing calls this directly

Calls 8

CheckoutMethod · 0.95
AddMethod · 0.95
CommitMethod · 0.95
StatusMethod · 0.95
AddWithOptionsMethod · 0.95
EntryMethod · 0.80
IndexMethod · 0.65
FileMethod · 0.45

Tested by

no test coverage detected