#!/bin/sh global test_description := '"merges with unrelated index changes'" source ./test-lib.sh # Testcase for some simple merges # A # o-----o B # \ # \---o C # \ # \-o D # \ # o E # Commit A: some file a # Commit B: adds file b, modifies end of a # Commit C: adds file c # Commit D: adds file d, modifies beginning of a # Commit E: renames a->subdir/a, adds subdir/e test_expect_success 'setup trivial merges' ' test_seq 1 10 >a && git add a && test_tick && git commit -m A && git branch A && git branch B && git branch C && git branch D && git branch E && git checkout B && echo b >b && echo 11 >>a && git add a b && test_tick && git commit -m B && git checkout C && echo c >c && git add c && test_tick && git commit -m C && git checkout D && test_seq 2 10 >a && echo d >d && git add a d && test_tick && git commit -m D && git checkout E && mkdir subdir && git mv a subdir/a && echo e >subdir/e && git add subdir && test_tick && git commit -m E ' test_expect_success 'ff update' ' git reset --hard && git checkout A^0 && touch random_file && git add random_file && git merge E^0 && test_must_fail git rev-parse HEAD:random_file && test "$(git diff --name-only --cached E)" = "random_file" ' test_expect_success 'ff update, important file modified' ' git reset --hard && git checkout A^0 && mkdir subdir && touch subdir/e && git add subdir/e && test_must_fail git merge E^0 ' test_expect_success 'resolve, trivial' ' git reset --hard && git checkout B^0 && touch random_file && git add random_file && test_must_fail git merge -s resolve C^0 ' test_expect_success 'resolve, non-trivial' ' git reset --hard && git checkout B^0 && touch random_file && git add random_file && test_must_fail git merge -s resolve D^0 ' test_expect_success 'recursive' ' git reset --hard && git checkout B^0 && touch random_file && git add random_file && test_must_fail git merge -s recursive C^0 ' test_expect_success 'octopus, unrelated file touched' ' git reset --hard && git checkout B^0 && touch random_file && git add random_file && test_must_fail git merge C^0 D^0 ' test_expect_success 'octopus, related file removed' ' git reset --hard && git checkout B^0 && git rm b && test_must_fail git merge C^0 D^0 ' test_expect_success 'octopus, related file modified' ' git reset --hard && git checkout B^0 && echo 12 >>a && git add a && test_must_fail git merge C^0 D^0 ' test_expect_success 'ours' ' git reset --hard && git checkout B^0 && touch random_file && git add random_file && test_must_fail git merge -s ours C^0 ' test_expect_success 'subtree' ' git reset --hard && git checkout B^0 && touch random_file && git add random_file && test_must_fail git merge -s subtree E^0 ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(DQ ("merges with unrelated index changes"))} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"setup trivial merges">)} { (SQ <"\n"> <"\ttest_seq 1 10 >a &&\n"> <"\tgit add a &&\n"> <"\ttest_tick && git commit -m A &&\n"> <"\n"> <"\tgit branch A &&\n"> <"\tgit branch B &&\n"> <"\tgit branch C &&\n"> <"\tgit branch D &&\n"> <"\tgit branch E &&\n"> <"\n"> <"\tgit checkout B &&\n"> <"\techo b >b &&\n"> <"\techo 11 >>a &&\n"> <"\tgit add a b &&\n"> <"\ttest_tick && git commit -m B &&\n"> <"\n"> <"\tgit checkout C &&\n"> <"\techo c >c &&\n"> <"\tgit add c &&\n"> <"\ttest_tick && git commit -m C &&\n"> <"\n"> <"\tgit checkout D &&\n"> <"\ttest_seq 2 10 >a &&\n"> <"\techo d >d &&\n"> <"\tgit add a d &&\n"> <"\ttest_tick && git commit -m D &&\n"> <"\n"> <"\tgit checkout E &&\n"> <"\tmkdir subdir &&\n"> <"\tgit mv a subdir/a &&\n"> <"\techo e >subdir/e &&\n"> <"\tgit add subdir &&\n"> <"\ttest_tick && git commit -m E\n"> ) } ) (C {(test_expect_success)} {(SQ <"ff update">)} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout A^0 &&\n"> <"\n"> <"\ttouch random_file && git add random_file &&\n"> <"\n"> <"\tgit merge E^0 &&\n"> <"\n"> <"\ttest_must_fail git rev-parse HEAD:random_file &&\n"> <"\ttest \"$(git diff --name-only --cached E)\" = \"random_file\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"ff update, important file modified">)} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout A^0 &&\n"> <"\n"> <"\tmkdir subdir &&\n"> <"\ttouch subdir/e &&\n"> <"\tgit add subdir/e &&\n"> <"\n"> <"\ttest_must_fail git merge E^0\n"> ) } ) (C {(test_expect_success)} {(SQ <"resolve, trivial">)} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout B^0 &&\n"> <"\n"> <"\ttouch random_file && git add random_file &&\n"> <"\n"> <"\ttest_must_fail git merge -s resolve C^0\n"> ) } ) (C {(test_expect_success)} {(SQ <"resolve, non-trivial">)} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout B^0 &&\n"> <"\n"> <"\ttouch random_file && git add random_file &&\n"> <"\n"> <"\ttest_must_fail git merge -s resolve D^0\n"> ) } ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout B^0 &&\n"> <"\n"> <"\ttouch random_file && git add random_file &&\n"> <"\n"> <"\ttest_must_fail git merge -s recursive C^0\n"> ) } ) (C {(test_expect_success)} {(SQ <"octopus, unrelated file touched">)} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout B^0 &&\n"> <"\n"> <"\ttouch random_file && git add random_file &&\n"> <"\n"> <"\ttest_must_fail git merge C^0 D^0\n"> ) } ) (C {(test_expect_success)} {(SQ <"octopus, related file removed">)} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout B^0 &&\n"> <"\n"> <"\tgit rm b &&\n"> <"\n"> <"\ttest_must_fail git merge C^0 D^0\n"> ) } ) (C {(test_expect_success)} {(SQ <"octopus, related file modified">)} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout B^0 &&\n"> <"\n"> <"\techo 12 >>a && git add a &&\n"> <"\n"> <"\ttest_must_fail git merge C^0 D^0\n"> ) } ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout B^0 &&\n"> <"\n"> <"\ttouch random_file && git add random_file &&\n"> <"\n"> <"\ttest_must_fail git merge -s ours C^0\n"> ) } ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout B^0 &&\n"> <"\n"> <"\ttouch random_file && git add random_file &&\n"> <"\n"> <"\ttest_must_fail git merge -s subtree E^0\n"> ) } ) (C {(test_done)}) ] )