setupMonorepoTestRepository creates a test repository with a monorepo structure It creates two subprojects: subproject1 and subproject2, each with initial files
(t *testing.T)
| 547 | // setupMonorepoTestRepository creates a test repository with a monorepo structure |
| 548 | // It creates two subprojects: subproject1 and subproject2, each with initial files |
| 549 | func setupMonorepoTestRepository(t *testing.T) (string, string) { |
| 550 | tempDir := t.TempDir() |
| 551 | |
| 552 | // Initialize a new git repository in the temp directory |
| 553 | cmd := exec.Command("git", "init", tempDir) |
| 554 | err := cmd.Run() |
| 555 | require.NoError(t, err, "failed to initialize git repository") |
| 556 | setupGitConfig(t, tempDir) |
| 557 | |
| 558 | // Create a remote repository in another temp directory |
| 559 | remoteDir := t.TempDir() |
| 560 | cmd = exec.Command("git", "init", "--bare", remoteDir) |
| 561 | err = cmd.Run() |
| 562 | require.NoError(t, err, "failed to initialize remote git repository") |
| 563 | |
| 564 | // Add the remote to the local repository |
| 565 | cmd = exec.Command("git", "-C", tempDir, "remote", "add", "origin", remoteDir) |
| 566 | err = cmd.Run() |
| 567 | require.NoError(t, err, "failed to add remote repository") |
| 568 | |
| 569 | // Create monorepo structure with multiple subprojects |
| 570 | subproject1Path := filepath.Join(tempDir, "subproject1") |
| 571 | subproject2Path := filepath.Join(tempDir, "subproject2") |
| 572 | err = os.MkdirAll(subproject1Path, 0755) |
| 573 | require.NoError(t, err, "failed to create subproject1 directory") |
| 574 | err = os.MkdirAll(subproject2Path, 0755) |
| 575 | require.NoError(t, err, "failed to create subproject2 directory") |
| 576 | |
| 577 | // Create initial files in subproject1 |
| 578 | file1 := filepath.Join(subproject1Path, "file1.txt") |
| 579 | err = os.WriteFile(file1, []byte("content of file1 in subproject1"), 0644) |
| 580 | require.NoError(t, err, "failed to create file1 in subproject1") |
| 581 | |
| 582 | // Create initial files in subproject2 |
| 583 | file2 := filepath.Join(subproject2Path, "file2.txt") |
| 584 | err = os.WriteFile(file2, []byte("content of file2 in subproject2"), 0644) |
| 585 | require.NoError(t, err, "failed to create file2 in subproject2") |
| 586 | |
| 587 | // Add root level README |
| 588 | readmePath := filepath.Join(tempDir, "README.md") |
| 589 | err = os.WriteFile(readmePath, []byte("# Monorepo Test\n"), 0644) |
| 590 | require.NoError(t, err, "failed to create README") |
| 591 | |
| 592 | // Stage all files |
| 593 | cmd = exec.Command("git", "-C", tempDir, "add", ".") |
| 594 | err = cmd.Run() |
| 595 | require.NoError(t, err, "failed to stage files") |
| 596 | |
| 597 | // Commit all files |
| 598 | cmd = exec.Command("git", "-C", tempDir, "commit", "-m", "initial monorepo commit") |
| 599 | _, err = cmd.Output() |
| 600 | if err != nil { |
| 601 | var execErr *exec.ExitError |
| 602 | if errors.As(err, &execErr) { |
| 603 | require.NoError(t, err, "failed to commit files: "+string(execErr.Stderr)) |
| 604 | } |
| 605 | require.NoError(t, err, "failed to commit files") |
| 606 | } |
no test coverage detected