MCPcopy
hub / github.com/go-git/go-git / CommitNewFile

Function CommitNewFile

common_test.go:219–250  ·  view source on GitHub ↗
(c *C, repo *Repository, fileName string)

Source from the content-addressed store, hash-verified

217}
218
219func CommitNewFile(c *C, repo *Repository, fileName string) plumbing.Hash {
220 wt, err := repo.Worktree()
221 c.Assert(err, IsNil)
222
223 fd, err := wt.Filesystem.Create(fileName)
224 c.Assert(err, IsNil)
225
226 _, err = fd.Write([]byte("# test file"))
227 c.Assert(err, IsNil)
228
229 err = fd.Close()
230 c.Assert(err, IsNil)
231
232 _, err = wt.Add(fileName)
233 c.Assert(err, IsNil)
234
235 sha, err := wt.Commit("test commit", &CommitOptions{
236 Author: &object.Signature{
237 Name: "test",
238 Email: "test@example.com",
239 When: time.Now(),
240 },
241 Committer: &object.Signature{
242 Name: "test",
243 Email: "test@example.com",
244 When: time.Now(),
245 },
246 })
247 c.Assert(err, IsNil)
248
249 return sha
250}

Calls 6

WorktreeMethod · 0.80
CloseMethod · 0.65
CommitMethod · 0.65
CreateMethod · 0.45
WriteMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…