MCPcopy Create free account
hub / github.com/coder/envbuilder / Commit

Function Commit

testutil/gittest/gittest.go:234–253  ·  view source on GitHub ↗

Commit is a test helper for committing a single file to a repo.

(t *testing.T, path, content, msg string)

Source from the content-addressed store, hash-verified

232
233// Commit is a test helper for committing a single file to a repo.
234func Commit(t *testing.T, path, content, msg string) CommitFunc {
235 return func(fs billy.Filesystem, repo *git.Repository) {
236 t.Helper()
237 tree, err := repo.Worktree()
238 require.NoError(t, err)
239 WriteFile(t, fs, path, content)
240 _, err = tree.Add(path)
241 require.NoError(t, err)
242 commit, err := tree.Commit(msg, &git.CommitOptions{
243 Author: &object.Signature{
244 Name: "Example",
245 Email: "test@example.com",
246 When: time.Now(),
247 },
248 })
249 require.NoError(t, err)
250 _, err = repo.CommitObject(commit)
251 require.NoError(t, err)
252 }
253}
254
255// NewRepo returns a new Git repository.
256func NewRepo(t *testing.T, fs billy.Filesystem, commits ...CommitFunc) *git.Repository {

Callers 5

TestGitSSHAuthFunction · 0.92
TestCloneRepoFunction · 0.92
TestShallowCloneRepoFunction · 0.92
TestCloneRepoSSHFunction · 0.92
CreateGitServerFunction · 0.85

Calls 1

WriteFileFunction · 0.85

Tested by 4

TestGitSSHAuthFunction · 0.74
TestCloneRepoFunction · 0.74
TestShallowCloneRepoFunction · 0.74
TestCloneRepoSSHFunction · 0.74