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

Function TestRunUpstreamMerge

cli/pkg/gitutil/gitcmdwrapper_test.go:404–473  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

402}
403
404func TestRunUpstreamMerge(t *testing.T) {
405 tempDir, remoteDir := setupTestRepository(t)
406
407 // Test case 1: Simple upstream merge without conflicts
408 createRemoteCommit(t, remoteDir, "upstream1.txt", "upstream content 1", "upstream commit 1")
409 require.NoError(t, GitFetch(context.Background(), tempDir, nil), "failed to fetch changes")
410
411 branch := getCurrentBranch(t, tempDir)
412 err := RunUpstreamMerge(context.Background(), "origin", tempDir, branch, false)
413 require.NoError(t, err, "RunUpstreamMerge failed")
414
415 // Verify file exists after merge
416 assertFileExists(t, tempDir, "upstream1.txt")
417
418 // Test case 2: Upstream merge with local commit (no conflict)
419 createCommit(t, tempDir, "local1.txt", "local content 1", "local commit 1")
420 createRemoteCommit(t, remoteDir, "upstream2.txt", "upstream content 2", "upstream commit 2")
421 require.NoError(t, GitFetch(context.Background(), tempDir, nil), "failed to fetch changes")
422
423 err = RunUpstreamMerge(context.Background(), "origin", tempDir, branch, false)
424 require.NoError(t, err, "RunUpstreamMerge failed with local commits")
425
426 // Both files should exist
427 assertFileExists(t, tempDir, "local1.txt")
428 assertFileExists(t, tempDir, "upstream2.txt")
429
430 // Test case 3: Conflicting changes - first try without favourLocal (should fail), then with favourLocal (local wins)
431 createCommit(t, tempDir, "conflict.txt", "local version", "add conflict file locally")
432
433 createRemoteCommit(t, remoteDir, "conflict.txt", "upstream version", "add conflict file upstream")
434 require.NoError(t, GitFetch(context.Background(), tempDir, nil), "failed to fetch changes")
435
436 // First try without favourLocal - should fail
437 err = RunUpstreamMerge(context.Background(), "origin", tempDir, branch, false)
438 require.Error(t, err, "RunUpstreamMerge should fail with conflicts and favourLocal=false")
439 require.Contains(t, err.Error(), "git merge failed", "expected merge failure error")
440
441 // Reset to before the failed merge attempt
442 cmd := exec.Command("git", "-C", tempDir, "merge", "--abort")
443 _ = cmd.Run() // Ignore error if no merge in progress
444
445 // Now try with favourLocal=true - should succeed
446 err = RunUpstreamMerge(context.Background(), "origin", tempDir, branch, true)
447 require.NoError(t, err, "RunUpstreamMerge failed with conflicts and favourLocal=true")
448
449 require.Equal(t, "local version", readFile(t, tempDir, "conflict.txt"), "local version should win with favourLocal=true")
450
451 // Test case 4: Mixed changes - remote changes in A and B, local changes in A and C
452 // Create local changes to file A and C
453 createCommit(t, tempDir, "fileA.txt", "local content A", "add fileA locally")
454 createCommit(t, tempDir, "fileC.txt", "local content C", "add fileC locally")
455
456 // Create remote changes to file A and B
457 createRemoteCommit(t, remoteDir, "fileA.txt", "upstream content A", "add fileA upstream")
458 createRemoteCommit(t, remoteDir, "fileB.txt", "upstream content B", "add fileB upstream")
459 require.NoError(t, GitFetch(context.Background(), tempDir, nil), "failed to fetch changes")
460
461 err = RunUpstreamMerge(context.Background(), "origin", tempDir, branch, true)

Callers

nothing calls this directly

Calls 11

GitFetchFunction · 0.85
RunUpstreamMergeFunction · 0.85
ContainsMethod · 0.80
setupTestRepositoryFunction · 0.70
createRemoteCommitFunction · 0.70
getCurrentBranchFunction · 0.70
assertFileExistsFunction · 0.70
createCommitFunction · 0.70
readFileFunction · 0.70
ErrorMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected