Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='"git merge" top-level frontend' |
| 4 | |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Jeff King | 716a6b2 | 2023-10-03 16:27:24 -0400 | [diff] [blame] | 8 | TEST_PASSES_SANITIZE_LEAK=true |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 9 | . ./test-lib.sh |
| 10 | |
| 11 | t3033_reset () { |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 12 | git checkout -B main two && |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 13 | git branch -f left three && |
| 14 | git branch -f right four |
| 15 | } |
| 16 | |
| 17 | test_expect_success setup ' |
| 18 | test_commit one && |
| 19 | git branch left && |
| 20 | git branch right && |
| 21 | test_commit two && |
| 22 | git checkout left && |
| 23 | test_commit three && |
| 24 | git checkout right && |
| 25 | test_commit four && |
Junio C Hamano | de22496 | 2016-04-21 11:52:33 -0700 | [diff] [blame] | 26 | git checkout --orphan newroot && |
Junio C Hamano | e379fdf | 2016-03-18 13:21:09 -0700 | [diff] [blame] | 27 | test_commit five && |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 28 | git checkout main |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 29 | ' |
| 30 | |
| 31 | # Local branches |
| 32 | |
| 33 | test_expect_success 'merge an octopus into void' ' |
| 34 | t3033_reset && |
| 35 | git checkout --orphan test && |
| 36 | git rm -fr . && |
| 37 | test_must_fail git merge left right && |
| 38 | test_must_fail git rev-parse --verify HEAD && |
| 39 | git diff --quiet && |
| 40 | test_must_fail git rev-parse HEAD |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'merge an octopus, fast-forward (ff)' ' |
| 44 | t3033_reset && |
| 45 | git reset --hard one && |
| 46 | git merge left right && |
| 47 | # one is ancestor of three (left) and four (right) |
| 48 | test_must_fail git rev-parse --verify HEAD^3 && |
| 49 | git rev-parse HEAD^1 HEAD^2 | sort >actual && |
| 50 | git rev-parse three four | sort >expect && |
| 51 | test_cmp expect actual |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'merge octopus, non-fast-forward (ff)' ' |
| 55 | t3033_reset && |
| 56 | git reset --hard one && |
| 57 | git merge --no-ff left right && |
| 58 | # one is ancestor of three (left) and four (right) |
| 59 | test_must_fail git rev-parse --verify HEAD^4 && |
| 60 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && |
| 61 | git rev-parse one three four | sort >expect && |
| 62 | test_cmp expect actual |
| 63 | ' |
| 64 | |
| 65 | test_expect_success 'merge octopus, fast-forward (does not ff)' ' |
| 66 | t3033_reset && |
| 67 | git merge left right && |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 68 | # two (main) is not an ancestor of three (left) and four (right) |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 69 | test_must_fail git rev-parse --verify HEAD^4 && |
| 70 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && |
| 71 | git rev-parse two three four | sort >expect && |
| 72 | test_cmp expect actual |
| 73 | ' |
| 74 | |
| 75 | test_expect_success 'merge octopus, non-fast-forward' ' |
| 76 | t3033_reset && |
| 77 | git merge --no-ff left right && |
| 78 | test_must_fail git rev-parse --verify HEAD^4 && |
| 79 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && |
| 80 | git rev-parse two three four | sort >expect && |
| 81 | test_cmp expect actual |
| 82 | ' |
| 83 | |
| 84 | # The same set with FETCH_HEAD |
| 85 | |
Junio C Hamano | 74e8bc5 | 2015-04-25 18:47:21 -0700 | [diff] [blame] | 86 | test_expect_success 'merge FETCH_HEAD octopus into void' ' |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 87 | t3033_reset && |
| 88 | git checkout --orphan test && |
| 89 | git rm -fr . && |
| 90 | git fetch . left right && |
| 91 | test_must_fail git merge FETCH_HEAD && |
| 92 | test_must_fail git rev-parse --verify HEAD && |
| 93 | git diff --quiet && |
| 94 | test_must_fail git rev-parse HEAD |
| 95 | ' |
| 96 | |
Junio C Hamano | 74e8bc5 | 2015-04-25 18:47:21 -0700 | [diff] [blame] | 97 | test_expect_success 'merge FETCH_HEAD octopus fast-forward (ff)' ' |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 98 | t3033_reset && |
| 99 | git reset --hard one && |
| 100 | git fetch . left right && |
| 101 | git merge FETCH_HEAD && |
| 102 | # one is ancestor of three (left) and four (right) |
| 103 | test_must_fail git rev-parse --verify HEAD^3 && |
| 104 | git rev-parse HEAD^1 HEAD^2 | sort >actual && |
| 105 | git rev-parse three four | sort >expect && |
| 106 | test_cmp expect actual |
| 107 | ' |
| 108 | |
Junio C Hamano | 74e8bc5 | 2015-04-25 18:47:21 -0700 | [diff] [blame] | 109 | test_expect_success 'merge FETCH_HEAD octopus non-fast-forward (ff)' ' |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 110 | t3033_reset && |
| 111 | git reset --hard one && |
| 112 | git fetch . left right && |
| 113 | git merge --no-ff FETCH_HEAD && |
| 114 | # one is ancestor of three (left) and four (right) |
| 115 | test_must_fail git rev-parse --verify HEAD^4 && |
| 116 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && |
| 117 | git rev-parse one three four | sort >expect && |
| 118 | test_cmp expect actual |
| 119 | ' |
| 120 | |
Junio C Hamano | 74e8bc5 | 2015-04-25 18:47:21 -0700 | [diff] [blame] | 121 | test_expect_success 'merge FETCH_HEAD octopus fast-forward (does not ff)' ' |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 122 | t3033_reset && |
| 123 | git fetch . left right && |
| 124 | git merge FETCH_HEAD && |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 125 | # two (main) is not an ancestor of three (left) and four (right) |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 126 | test_must_fail git rev-parse --verify HEAD^4 && |
| 127 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && |
| 128 | git rev-parse two three four | sort >expect && |
| 129 | test_cmp expect actual |
| 130 | ' |
| 131 | |
Junio C Hamano | 74e8bc5 | 2015-04-25 18:47:21 -0700 | [diff] [blame] | 132 | test_expect_success 'merge FETCH_HEAD octopus non-fast-forward' ' |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 133 | t3033_reset && |
| 134 | git fetch . left right && |
| 135 | git merge --no-ff FETCH_HEAD && |
| 136 | test_must_fail git rev-parse --verify HEAD^4 && |
| 137 | git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual && |
| 138 | git rev-parse two three four | sort >expect && |
| 139 | test_cmp expect actual |
| 140 | ' |
| 141 | |
Junio C Hamano | e379fdf | 2016-03-18 13:21:09 -0700 | [diff] [blame] | 142 | # two-project merge |
| 143 | test_expect_success 'refuse two-project merge by default' ' |
| 144 | t3033_reset && |
| 145 | git reset --hard four && |
| 146 | test_must_fail git merge five |
| 147 | ' |
| 148 | |
Denton Liu | a03b555 | 2020-04-07 10:28:07 -0400 | [diff] [blame] | 149 | test_expect_success 'refuse two-project merge by default, quit before --autostash happens' ' |
| 150 | t3033_reset && |
| 151 | git reset --hard four && |
| 152 | echo change >>one.t && |
| 153 | git diff >expect && |
| 154 | test_must_fail git merge --autostash five 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 155 | test_grep ! "stash" err && |
Denton Liu | a03b555 | 2020-04-07 10:28:07 -0400 | [diff] [blame] | 156 | git diff >actual && |
| 157 | test_cmp expect actual |
| 158 | ' |
| 159 | |
Junio C Hamano | e379fdf | 2016-03-18 13:21:09 -0700 | [diff] [blame] | 160 | test_expect_success 'two-project merge with --allow-unrelated-histories' ' |
| 161 | t3033_reset && |
| 162 | git reset --hard four && |
| 163 | git merge --allow-unrelated-histories five && |
| 164 | git diff --exit-code five |
| 165 | ' |
| 166 | |
Denton Liu | a03b555 | 2020-04-07 10:28:07 -0400 | [diff] [blame] | 167 | test_expect_success 'two-project merge with --allow-unrelated-histories with --autostash' ' |
| 168 | t3033_reset && |
| 169 | git reset --hard four && |
| 170 | echo change >>one.t && |
| 171 | git diff one.t >expect && |
| 172 | git merge --allow-unrelated-histories --autostash five 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 173 | test_grep "Applied autostash." err && |
Denton Liu | a03b555 | 2020-04-07 10:28:07 -0400 | [diff] [blame] | 174 | git diff one.t >actual && |
| 175 | test_cmp expect actual |
| 176 | ' |
| 177 | |
Junio C Hamano | 9e62316 | 2015-04-29 13:14:50 -0700 | [diff] [blame] | 178 | test_done |