MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / TestMergeBranch

Function TestMergeBranch

internal/git/worktree_test.go:272–391  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

270}
271
272func TestMergeBranch(t *testing.T) {
273 t.Run("fast-forward merge succeeds", func(t *testing.T) {
274 dir := initTestRepo(t)
275
276 // Create a branch with a commit
277 cmd := exec.Command("git", "checkout", "-b", "feature")
278 cmd.Dir = dir
279 if out, err := cmd.CombinedOutput(); err != nil {
280 t.Fatalf("checkout failed: %s", string(out))
281 }
282
283 featureFile := filepath.Join(dir, "feature.txt")
284 if err := os.WriteFile(featureFile, []byte("feature\n"), 0644); err != nil {
285 t.Fatalf("failed to create feature file: %v", err)
286 }
287 cmd = exec.Command("git", "add", ".")
288 cmd.Dir = dir
289 if out, err := cmd.CombinedOutput(); err != nil {
290 t.Fatalf("git add failed: %s", string(out))
291 }
292 cmd = exec.Command("git", "commit", "-m", "add feature")
293 cmd.Dir = dir
294 if out, err := cmd.CombinedOutput(); err != nil {
295 t.Fatalf("git commit failed: %s", string(out))
296 }
297
298 // Switch back to main and merge
299 cmd = exec.Command("git", "checkout", "main")
300 cmd.Dir = dir
301 if out, err := cmd.CombinedOutput(); err != nil {
302 t.Fatalf("checkout main failed: %s", string(out))
303 }
304
305 conflicts, err := MergeBranch(dir, "feature")
306 if err != nil {
307 t.Fatalf("MergeBranch() error = %v", err)
308 }
309 if len(conflicts) > 0 {
310 t.Errorf("expected no conflicts, got %v", conflicts)
311 }
312
313 // Verify feature file exists on main
314 if _, err := os.Stat(featureFile); err != nil {
315 t.Error("feature.txt not present after merge")
316 }
317 })
318
319 t.Run("merge conflict returns conflicting files", func(t *testing.T) {
320 dir := initTestRepo(t)
321
322 // Create conflicting changes on two branches
323 conflictFile := filepath.Join(dir, "conflict.txt")
324 if err := os.WriteFile(conflictFile, []byte("main content\n"), 0644); err != nil {
325 t.Fatalf("failed to create conflict file: %v", err)
326 }
327 cmd := exec.Command("git", "add", ".")
328 cmd.Dir = dir
329 if out, err := cmd.CombinedOutput(); err != nil {

Callers

nothing calls this directly

Calls 3

initTestRepoFunction · 0.85
MergeBranchFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected