createCommit creates a file and commits it to the repository
(t *testing.T, repoPath, fileName, fileContent, commitMessage string)
| 436 | |
| 437 | // createCommit creates a file and commits it to the repository |
| 438 | func createCommit(t *testing.T, repoPath, fileName, fileContent, commitMessage string) { |
| 439 | filePath := filepath.Join(repoPath, fileName) |
| 440 | err := os.WriteFile(filePath, []byte(fileContent), 0644) |
| 441 | require.NoError(t, err, "failed to create file") |
| 442 | |
| 443 | cmd := exec.Command("git", "-C", repoPath, "add", fileName) |
| 444 | _, err = cmd.Output() |
| 445 | if err != nil { |
| 446 | var execErr *exec.ExitError |
| 447 | if errors.As(err, &execErr) { |
| 448 | require.NoError(t, err, "failed to stage file"+fmt.Sprintf(": %s", execErr.Stderr)) |
| 449 | } |
| 450 | require.NoError(t, err, "failed to stage file") |
| 451 | } |
| 452 | |
| 453 | cmd = exec.Command("git", "-C", repoPath, "commit", "-m", commitMessage) |
| 454 | _, err = cmd.Output() |
| 455 | if err != nil { |
| 456 | var execErr *exec.ExitError |
| 457 | if errors.As(err, &execErr) { |
| 458 | require.NoError(t, err, "failed to commit file"+fmt.Sprintf(": %s", execErr.Stderr)) |
| 459 | } |
| 460 | require.NoError(t, err, "failed to commit file") |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | // setupGitConfig sets up the git configuration for the repository at repoPath |
| 465 | func setupGitConfig(t *testing.T, repoPath string) { |
no outgoing calls
no test coverage detected