| 212 | } |
| 213 | |
| 214 | func (s *FileSuite) TestFileIter(c *C) { |
| 215 | hash := plumbing.NewHash("1669dce138d9b841a518c64b10914d88f5e488ea") |
| 216 | commit, err := GetCommit(s.Storer, hash) |
| 217 | c.Assert(err, IsNil) |
| 218 | |
| 219 | tree, err := commit.Tree() |
| 220 | c.Assert(err, IsNil) |
| 221 | |
| 222 | expected := []string{ |
| 223 | ".gitignore", |
| 224 | "CHANGELOG", |
| 225 | "LICENSE", |
| 226 | "binary.jpg", |
| 227 | } |
| 228 | |
| 229 | var count int |
| 230 | i := tree.Files() |
| 231 | i.ForEach(func(f *File) error { |
| 232 | c.Assert(f.Name, Equals, expected[count]) |
| 233 | count++ |
| 234 | return nil |
| 235 | }) |
| 236 | |
| 237 | c.Assert(count, Equals, 4) |
| 238 | |
| 239 | count = 0 |
| 240 | i = tree.Files() |
| 241 | i.ForEach(func(f *File) error { |
| 242 | count++ |
| 243 | return storer.ErrStop |
| 244 | }) |
| 245 | |
| 246 | c.Assert(count, Equals, 1) |
| 247 | } |
| 248 | |
| 249 | func (s *FileSuite) TestFileIterSubmodule(c *C) { |
| 250 | dotgit := fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One().DotGit() |