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

Method TestAddAndCommit

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

Source from the content-addressed store, hash-verified

2804}
2805
2806func (s *WorktreeSuite) TestAddAndCommit(c *C) {
2807 expectedFiles := 2
2808
2809 dir, clean := s.TemporalDir()
2810 defer clean()
2811
2812 repo, err := PlainInit(dir, false)
2813 c.Assert(err, IsNil)
2814
2815 w, err := repo.Worktree()
2816 c.Assert(err, IsNil)
2817
2818 os.WriteFile(filepath.Join(dir, "foo"), []byte("bar"), 0o644)
2819 os.WriteFile(filepath.Join(dir, "bar"), []byte("foo"), 0o644)
2820
2821 _, err = w.Add(".")
2822 c.Assert(err, IsNil)
2823
2824 _, err = w.Commit("Test Add And Commit", &CommitOptions{Author: &object.Signature{
2825 Name: "foo",
2826 Email: "foo@foo.foo",
2827 When: time.Now(),
2828 }})
2829 c.Assert(err, IsNil)
2830
2831 iter, err := w.r.Log(&LogOptions{})
2832 c.Assert(err, IsNil)
2833
2834 filesFound := 0
2835 err = iter.ForEach(func(c *object.Commit) error {
2836 files, err := c.Files()
2837 if err != nil {
2838 return err
2839 }
2840
2841 err = files.ForEach(func(f *object.File) error {
2842 filesFound++
2843 return nil
2844 })
2845 return err
2846 })
2847 c.Assert(err, IsNil)
2848 c.Assert(filesFound, Equals, expectedFiles)
2849}
2850
2851func (s *WorktreeSuite) TestAddAndCommitEmpty(c *C) {
2852 dir, clean := s.TemporalDir()

Callers

nothing calls this directly

Calls 9

PlainInitFunction · 0.85
TemporalDirMethod · 0.80
WorktreeMethod · 0.80
JoinMethod · 0.80
LogMethod · 0.80
CommitMethod · 0.65
ForEachMethod · 0.65
FilesMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected