| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git add --resolved |
| 4 | |
| 5 | Test that "git add --resolved" stages conflict-resolved paths and |
| 6 | refuses to stage when conflict markers remain.' |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success 'setup repo' ' |
| 11 | echo base >file1.txt && |
| 12 | echo base >file2.txt && |
| 13 | echo base >file3.txt && |
| 14 | echo base >file4.txt && |
| 15 | git add file1.txt file2.txt file3.txt file4.txt && |
| 16 | git commit -m initial && |
| 17 | |
| 18 | git branch topic && |
| 19 | echo "ours 1" >file1.txt && |
| 20 | echo "ours 2" >file2.txt && |
| 21 | echo "ours 3" >file3.txt && |
| 22 | git commit -a -m ours && |
| 23 | |
| 24 | git checkout topic && |
| 25 | echo "theirs 1" >file1.txt && |
| 26 | echo "theirs 2" >file2.txt && |
| 27 | echo "theirs 3" >file3.txt && |
| 28 | git commit -a -m theirs && |
| 29 | |
| 30 | git checkout @{-1} |
| 31 | ' |
| 32 | |
| 33 | test_expect_success 'git add --resolved refuses files with conflict markers' ' |
| 34 | test_when_finished "git reset --hard HEAD" && |
| 35 | test_must_fail git merge topic && |
| 36 | echo "resolved 1" >file1.txt && |
| 37 | test_must_fail git add --resolved 2>err && |
| 38 | test_grep "the following paths still have conflict markers:" err && |
| 39 | test_grep "file2.txt" err && |
| 40 | test_grep "file3.txt" err && |
| 41 | # Index should remain unmerged for all files |
| 42 | git ls-files -u file1.txt >unmerged && |
| 43 | test_line_count = 3 unmerged |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'git add --resolved succeeds when all conflict markers are removed' ' |
| 47 | test_when_finished "git reset --hard HEAD" && |
| 48 | test_must_fail git merge topic && |
| 49 | echo "resolved 1" >file1.txt && |
| 50 | echo "resolved 2" >file2.txt && |
| 51 | echo "resolved 3" >file3.txt && |
| 52 | git add --resolved && |
| 53 | git ls-files -u >unmerged && |
| 54 | test_must_be_empty unmerged && |
| 55 | git ls-files -s file1.txt file2.txt file3.txt >staged && |
| 56 | test_line_count = 3 staged |
| 57 | ' |
| 58 | |
| 59 | test_expect_success 'git add --resolved ignores unconflicted modified files' ' |
| 60 | test_when_finished "git reset --hard HEAD" && |
| 61 | echo "unconflicted local change" >>file4.txt && |
| 62 | test_must_fail git merge topic && |
| 63 | echo "resolved 1" >file1.txt && |
| 64 | echo "resolved 2" >file2.txt && |
| 65 | echo "resolved 3" >file3.txt && |
| 66 | git add --resolved && |
| 67 | # file1, file2, file3 should be staged as resolved |
| 68 | git ls-files -u >unmerged && |
| 69 | test_must_be_empty unmerged && |
| 70 | # file4 should remain unstaged in working tree |
| 71 | git diff file4.txt >diff_out && |
| 72 | test_grep "unconflicted local change" diff_out && |
| 73 | git diff --cached file4.txt >cached_out && |
| 74 | test_must_be_empty cached_out |
| 75 | ' |
| 76 | |
| 77 | test_expect_success 'git add --resolved handles file removals' ' |
| 78 | test_when_finished "git reset --hard HEAD" && |
| 79 | test_must_fail git merge topic && |
| 80 | echo "resolved 1" >file1.txt && |
| 81 | rm file2.txt && |
| 82 | echo "resolved 3" >file3.txt && |
| 83 | git add --resolved && |
| 84 | git ls-files -s file2.txt >out && |
| 85 | test_must_be_empty out |
| 86 | ' |
| 87 | |
| 88 | test_expect_success 'git add --resolved honors pathspec' ' |
| 89 | test_when_finished "git reset --hard HEAD" && |
| 90 | test_must_fail git merge topic && |
| 91 | echo "resolved 1" >file1.txt && |
| 92 | # file2.txt and file3.txt still have conflict markers, |
| 93 | # but pathspec targets only file1.txt |
| 94 | git add --resolved file1.txt && |
| 95 | git ls-files -u file1.txt >unmerged1 && |
| 96 | test_must_be_empty unmerged1 && |
| 97 | git ls-files -u file2.txt >unmerged2 && |
| 98 | test_line_count = 3 unmerged2 |
| 99 | ' |
| 100 | |
| 101 | test_expect_success 'git add --resolved incompatibility with -u and -A' ' |
| 102 | test_must_fail git add --resolved -u 2>err1 && |
| 103 | test_grep "cannot be used together" err1 && |
| 104 | test_must_fail git add --resolved -A 2>err2 && |
| 105 | test_grep "cannot be used together" err2 |
| 106 | ' |
| 107 | |
| 108 | test_done |