(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestMergeWithStrategy(t *testing.T) { |
| 17 | t.Run("theirs: successful merge without conflicts", func(t *testing.T) { |
| 18 | tempDir := setupTestRepository(t) |
| 19 | |
| 20 | // Create a feature branch |
| 21 | cmd := exec.Command("git", "-C", tempDir, "checkout", "-b", "feature") |
| 22 | output, err := cmd.CombinedOutput() |
| 23 | if err != nil { |
| 24 | t.Logf("Git checkout -b output: %s", string(output)) |
| 25 | } |
| 26 | require.NoError(t, err, "failed to create feature branch") |
| 27 | |
| 28 | // Add a file in the feature branch |
| 29 | createCommit(t, tempDir, "feature.txt", "feature content", "add feature file") |
| 30 | |
| 31 | // Switch back to main and add a different file |
| 32 | cmd = exec.Command("git", "-C", tempDir, "checkout", "main") |
| 33 | output, err = cmd.CombinedOutput() |
| 34 | require.NoError(t, err, "failed to switch to main branch ", string(output)) |
| 35 | |
| 36 | createCommit(t, tempDir, "main.txt", "main content", "add main file") |
| 37 | |
| 38 | // Test merging feature branch using theirs strategy |
| 39 | err = MergeWithStrategy(tempDir, "feature", "theirs") |
| 40 | require.NoError(t, err, "MergeWithStrategy(theirs) should succeed without conflicts") |
| 41 | |
| 42 | // Verify both files exist |
| 43 | featureFile := filepath.Join(tempDir, "feature.txt") |
| 44 | mainFile := filepath.Join(tempDir, "main.txt") |
| 45 | require.FileExists(t, featureFile, "feature file should exist after merge") |
| 46 | require.FileExists(t, mainFile, "main file should exist after merge") |
| 47 | }) |
| 48 | |
| 49 | t.Run("theirs: merge with conflicts resolved using theirs strategy", func(t *testing.T) { |
| 50 | tempDir := setupTestRepository(t) |
| 51 | |
| 52 | // Create a feature branch |
| 53 | cmd := exec.Command("git", "-C", tempDir, "checkout", "-b", "feature") |
| 54 | output, err := cmd.CombinedOutput() |
| 55 | require.NoError(t, err, "failed to create feature branch ", string(output)) |
| 56 | |
| 57 | // Modify the same file in feature branch |
| 58 | createCommit(t, tempDir, "test1.txt", "feature version", "modify test1 in feature") |
| 59 | |
| 60 | // Switch back to main and modify the same file differently |
| 61 | cmd = exec.Command("git", "-C", tempDir, "checkout", "main") |
| 62 | err = cmd.Run() |
| 63 | require.NoError(t, err, "failed to switch to main branch") |
| 64 | |
| 65 | createCommit(t, tempDir, "test1.txt", "main version", "modify test1 in main") |
| 66 | |
| 67 | // Test merging feature branch with conflicts using theirs strategy |
| 68 | err = MergeWithStrategy(tempDir, "feature", "theirs") |
| 69 | require.NoError(t, err, "MergeWithStrategy(theirs) should resolve conflicts using theirs strategy") |
| 70 | |
| 71 | // Verify the file has the feature branch content (theirs) |
| 72 | content, err := os.ReadFile(filepath.Join(tempDir, "test1.txt")) |
| 73 | require.NoError(t, err, "failed to read merged file") |
nothing calls this directly
no test coverage detected