Commit is a test helper for committing a single file to a repo.
(t *testing.T, path, content, msg string)
| 232 | |
| 233 | // Commit is a test helper for committing a single file to a repo. |
| 234 | func 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. |
| 256 | func NewRepo(t *testing.T, fs billy.Filesystem, commits ...CommitFunc) *git.Repository { |