MCPcopy Index your code
hub / github.com/rilldata/rill / TestMergeWithStrategy

Function TestMergeWithStrategy

runtime/pkg/gitutil/gitcmdwrapper_test.go:16–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func 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")

Callers

nothing calls this directly

Calls 7

MergeWithStrategyFunction · 0.85
LogfMethod · 0.80
ContainsMethod · 0.80
setupTestRepositoryFunction · 0.70
createCommitFunction · 0.70
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected