(t *testing.T)
| 397 | } |
| 398 | |
| 399 | func setupTestRepository(t *testing.T) string { |
| 400 | tempDir := t.TempDir() |
| 401 | |
| 402 | // Initialize a new git repository in the temp directory |
| 403 | cmd := exec.Command("git", "init", tempDir) |
| 404 | output, err := cmd.CombinedOutput() |
| 405 | require.NoError(t, err, "failed to initialize git repository ", string(output)) |
| 406 | |
| 407 | // Set the default branch to main |
| 408 | cmd = exec.Command("git", "-C", tempDir, "checkout", "-b", "main") |
| 409 | output, err = cmd.CombinedOutput() |
| 410 | require.NoError(t, err, "failed to create main branch ", string(output)) |
| 411 | |
| 412 | setupGitConfig(t, tempDir) |
| 413 | |
| 414 | // Create and commit multiple files |
| 415 | for i := 1; i <= 3; i++ { |
| 416 | filePath := filepath.Join(tempDir, fmt.Sprintf("test%d.txt", i)) |
| 417 | err = os.WriteFile(filePath, []byte(fmt.Sprintf("content of file %d", i)), 0644) |
| 418 | require.NoError(t, err, "failed to create test file") |
| 419 | |
| 420 | cmd = exec.Command("git", "-C", tempDir, "add", fmt.Sprintf("test%d.txt", i)) |
| 421 | err = cmd.Run() |
| 422 | require.NoError(t, err, "failed to stage file") |
| 423 | } |
| 424 | |
| 425 | cmd = exec.Command("git", "-C", tempDir, "commit", "-m", "initial commit") |
| 426 | _, err = cmd.Output() |
| 427 | if err != nil { |
| 428 | var execErr *exec.ExitError |
| 429 | if errors.As(err, &execErr) { |
| 430 | require.NoError(t, err, "failed to commit files: "+fmt.Sprintf(": %s", execErr.Stderr)) |
| 431 | } |
| 432 | require.NoError(t, err, "failed to commit files") |
| 433 | } |
| 434 | return tempDir |
| 435 | } |
| 436 | |
| 437 | // createCommit creates a file and commits it to the repository |
| 438 | func createCommit(t *testing.T, repoPath, fileName, fileContent, commitMessage string) { |
no test coverage detected