MCPcopy Index your code
hub / github.com/go-git/go-git / TestAddAndCommit

Method TestAddAndCommit

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

Source from the content-addressed store, hash-verified

3058}
3059
3060func (s *WorktreeSuite) TestAddAndCommit(c *C) {
3061 expectedFiles := 2
3062
3063 dir := c.MkDir()
3064
3065 repo, err := PlainInit(dir, false)
3066 c.Assert(err, IsNil)
3067
3068 w, err := repo.Worktree()
3069 c.Assert(err, IsNil)
3070
3071 os.WriteFile(filepath.Join(dir, "foo"), []byte("bar"), 0o644)
3072 os.WriteFile(filepath.Join(dir, "bar"), []byte("foo"), 0o644)
3073
3074 _, err = w.Add(".")
3075 c.Assert(err, IsNil)
3076
3077 _, err = w.Commit("Test Add And Commit", &CommitOptions{Author: &object.Signature{
3078 Name: "foo",
3079 Email: "foo@foo.foo",
3080 When: time.Now(),
3081 }})
3082 c.Assert(err, IsNil)
3083
3084 iter, err := w.r.Log(&LogOptions{})
3085 c.Assert(err, IsNil)
3086
3087 filesFound := 0
3088 err = iter.ForEach(func(c *object.Commit) error {
3089 files, err := c.Files()
3090 if err != nil {
3091 return err
3092 }
3093
3094 err = files.ForEach(func(f *object.File) error {
3095 filesFound++
3096 return nil
3097 })
3098 return err
3099 })
3100 c.Assert(err, IsNil)
3101 c.Assert(filesFound, Equals, expectedFiles)
3102}
3103
3104func (s *WorktreeSuite) TestAddAndCommitEmpty(c *C) {
3105 dir := c.MkDir()

Callers

nothing calls this directly

Calls 8

PlainInitFunction · 0.85
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