Elijah Newren | 8ddc20b | 2021-03-20 00:03:49 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description="merge cases" |
| 4 | |
| 5 | # The setup for all of them, pictorially, is: |
| 6 | # |
| 7 | # A |
| 8 | # o |
| 9 | # / \ |
| 10 | # O o ? |
| 11 | # \ / |
| 12 | # o |
| 13 | # B |
| 14 | # |
| 15 | # To help make it easier to follow the flow of tests, they have been |
| 16 | # divided into sections and each test will start with a quick explanation |
| 17 | # of what commits O, A, and B contain. |
| 18 | # |
| 19 | # Notation: |
| 20 | # z/{b,c} means files z/b and z/c both exist |
| 21 | # x/d_1 means file x/d exists with content d1. (Purpose of the |
| 22 | # underscore notation is to differentiate different |
| 23 | # files that might be renamed into each other's paths.) |
| 24 | |
| 25 | . ./test-lib.sh |
| 26 | . "$TEST_DIRECTORY"/lib-merge.sh |
| 27 | |
| 28 | |
| 29 | # Testcase basic, conflicting changes in 'numerals' |
| 30 | |
| 31 | test_setup_numerals () { |
Elijah Newren | 6693fb3 | 2022-08-26 03:49:19 +0000 | [diff] [blame] | 32 | git init numerals_$1 && |
Elijah Newren | 8ddc20b | 2021-03-20 00:03:49 +0000 | [diff] [blame] | 33 | ( |
| 34 | cd numerals_$1 && |
| 35 | |
| 36 | >README && |
| 37 | test_write_lines I II III >numerals && |
| 38 | git add README numerals && |
| 39 | test_tick && |
| 40 | git commit -m "O" && |
| 41 | |
| 42 | git branch O && |
| 43 | git branch A && |
| 44 | git branch B && |
| 45 | |
| 46 | git checkout A && |
| 47 | test_write_lines I II III IIII >numerals && |
| 48 | git add numerals && |
| 49 | test_tick && |
| 50 | git commit -m "A" && |
| 51 | |
| 52 | git checkout B && |
| 53 | test_write_lines I II III IV >numerals && |
| 54 | git add numerals && |
| 55 | test_tick && |
| 56 | git commit -m "B" && |
| 57 | |
| 58 | cat <<-EOF >expected-index && |
| 59 | H README |
| 60 | M numerals |
| 61 | M numerals |
| 62 | M numerals |
| 63 | EOF |
| 64 | |
| 65 | cat <<-EOF >expected-merge |
| 66 | I |
| 67 | II |
| 68 | III |
| 69 | <<<<<<< HEAD |
| 70 | IIII |
| 71 | ======= |
| 72 | IV |
| 73 | >>>>>>> B^0 |
| 74 | EOF |
| 75 | |
| 76 | ) |
| 77 | } |
| 78 | |
Elijah Newren | 66b209b | 2021-03-20 00:03:50 +0000 | [diff] [blame] | 79 | test_expect_success 'conflicting entries written to worktree even if sparse' ' |
Elijah Newren | 8ddc20b | 2021-03-20 00:03:49 +0000 | [diff] [blame] | 80 | test_setup_numerals plain && |
| 81 | ( |
| 82 | cd numerals_plain && |
| 83 | |
| 84 | git checkout A^0 && |
| 85 | |
| 86 | test_path_is_file README && |
| 87 | test_path_is_file numerals && |
| 88 | |
| 89 | git sparse-checkout init && |
Elijah Newren | dde1358 | 2022-04-22 02:32:18 +0000 | [diff] [blame] | 90 | git sparse-checkout set --no-cone README && |
Elijah Newren | 8ddc20b | 2021-03-20 00:03:49 +0000 | [diff] [blame] | 91 | |
| 92 | test_path_is_file README && |
| 93 | test_path_is_missing numerals && |
| 94 | |
| 95 | test_must_fail git merge -s recursive B^0 && |
| 96 | |
| 97 | git ls-files -t >index_files && |
| 98 | test_cmp expected-index index_files && |
| 99 | |
| 100 | test_path_is_file README && |
| 101 | test_path_is_file numerals && |
| 102 | |
| 103 | test_cmp expected-merge numerals && |
| 104 | |
| 105 | # 4 other files: |
| 106 | # * expected-merge |
| 107 | # * expected-index |
| 108 | # * index_files |
| 109 | # * others |
| 110 | git ls-files -o >others && |
| 111 | test_line_count = 4 others |
| 112 | ) |
| 113 | ' |
| 114 | |
Elijah Newren | af6a518 | 2022-01-14 15:59:41 +0000 | [diff] [blame] | 115 | test_expect_success 'present-despite-SKIP_WORKTREE handled reasonably' ' |
Elijah Newren | 8ddc20b | 2021-03-20 00:03:49 +0000 | [diff] [blame] | 116 | test_setup_numerals in_the_way && |
| 117 | ( |
| 118 | cd numerals_in_the_way && |
| 119 | |
| 120 | git checkout A^0 && |
| 121 | |
| 122 | test_path_is_file README && |
| 123 | test_path_is_file numerals && |
| 124 | |
| 125 | git sparse-checkout init && |
Elijah Newren | dde1358 | 2022-04-22 02:32:18 +0000 | [diff] [blame] | 126 | git sparse-checkout set --no-cone README && |
Elijah Newren | 8ddc20b | 2021-03-20 00:03:49 +0000 | [diff] [blame] | 127 | |
| 128 | test_path_is_file README && |
| 129 | test_path_is_missing numerals && |
| 130 | |
| 131 | echo foobar >numerals && |
| 132 | |
| 133 | test_must_fail git merge -s recursive B^0 && |
| 134 | |
Elijah Newren | af6a518 | 2022-01-14 15:59:41 +0000 | [diff] [blame] | 135 | test_path_is_missing .git/MERGE_HEAD && |
Elijah Newren | 8ddc20b | 2021-03-20 00:03:49 +0000 | [diff] [blame] | 136 | |
Elijah Newren | 8ddc20b | 2021-03-20 00:03:49 +0000 | [diff] [blame] | 137 | test_path_is_file numerals && |
| 138 | |
Elijah Newren | af6a518 | 2022-01-14 15:59:41 +0000 | [diff] [blame] | 139 | # numerals should still have "foobar" in it |
| 140 | echo foobar >expect && |
| 141 | test_cmp expect numerals |
Elijah Newren | 8ddc20b | 2021-03-20 00:03:49 +0000 | [diff] [blame] | 142 | ) |
| 143 | ' |
| 144 | |
| 145 | test_done |