Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Santi Béjar, based on t4013 by Junio C Hamano |
| 4 | # |
| 5 | # |
| 6 | |
| 7 | test_description='Merge logic in fetch' |
| 8 | |
Jonathan Tan | d790ee1 | 2019-02-25 13:54:12 -0800 | [diff] [blame] | 9 | # NEEDSWORK: If the overspecification of the expected result is reduced, we |
| 10 | # might be able to run this test in all protocol versions. |
Jonathan Nieder | 8a1b097 | 2019-12-23 17:01:10 -0800 | [diff] [blame] | 11 | GIT_TEST_PROTOCOL_VERSION=0 |
| 12 | export GIT_TEST_PROTOCOL_VERSION |
Jonathan Tan | d790ee1 | 2019-02-25 13:54:12 -0800 | [diff] [blame] | 13 | |
Johannes Schindelin | f74e3f7 | 2020-11-02 23:55:07 +0000 | [diff] [blame] | 14 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 62e7daa | 2020-11-02 23:55:04 +0000 | [diff] [blame] | 15 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 16 | |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 17 | . ./test-lib.sh |
| 18 | |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 19 | build_script () { |
| 20 | script="$1" && |
Johannes Schindelin | 62e7daa | 2020-11-02 23:55:04 +0000 | [diff] [blame] | 21 | for i in one three_file main topic_2 one_tree three two two2 three2 |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 22 | do |
| 23 | echo "s/$(test_oid --hash=sha1 "$i")/$(test_oid "$i")/g" >>"$script" |
| 24 | done |
| 25 | } |
| 26 | |
| 27 | convert_expected () { |
| 28 | file="$1" && |
| 29 | script="$2" && |
| 30 | sed -f "$script" "$file" >"$file.tmp" && |
| 31 | mv "$file.tmp" "$file" |
| 32 | } |
| 33 | |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 34 | test_expect_success setup ' |
| 35 | GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" && |
| 36 | GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" && |
| 37 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && |
| 38 | |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 39 | test_oid_cache <<-EOF && |
| 40 | one sha1:8e32a6d901327a23ef831511badce7bf3bf46689 |
| 41 | one sha256:8739546433ab1ac72ee93088dce611210effee072b2b586ceac6dde43ebec9ce |
| 42 | |
| 43 | three_file sha1:0e3b14047d3ee365f4f2a1b673db059c3972589c |
| 44 | three_file sha256:bc4447d50c07497a8bfe6eef817f2364ecca9d471452e43b52756cc1a908bd32 |
| 45 | |
Johannes Schindelin | 62e7daa | 2020-11-02 23:55:04 +0000 | [diff] [blame] | 46 | main sha1:ecf3b3627b498bdcb735cc4343bf165f76964e9a |
| 47 | main sha256:fff666109892bb4b1c80cd1649d2d8762a0663db8b5d46c8be98360b64fbba5f |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 48 | |
| 49 | one_tree sha1:22feea448b023a2d864ef94b013735af34d238ba |
| 50 | one_tree sha256:6e4743f4ef2356b881dda5e91f5c7cdffe870faf350bf7b312f80a20935f5d83 |
| 51 | |
| 52 | three sha1:c61a82b60967180544e3c19f819ddbd0c9f89899 |
| 53 | three sha256:0cc6d1eda617ded715170786e31ba4e2d0185404ec5a3508dd0d73b324860c6a |
| 54 | |
| 55 | two sha1:525b7fb068d59950d185a8779dc957c77eed73ba |
| 56 | two sha256:3b21de3440cd38c2a9e9b464adb923f7054949ed4c918e1a0ac4c95cd52774db |
| 57 | |
Johannes Schindelin | 62e7daa | 2020-11-02 23:55:04 +0000 | [diff] [blame] | 58 | topic_2 sha1:b4ab76b1a01ea602209932134a44f1e6bd610832 |
| 59 | topic_2 sha256:380ebae0113f877ce46fcdf39d5bc33e4dc0928db5c5a4d5fdc78381c4d55ae3 |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 60 | |
| 61 | two2 sha1:6134ee8f857693b96ff1cc98d3e2fd62b199e5a8 |
| 62 | two2 sha256:87a2d3ee29c83a3dc7afd41c0606b11f67603120b910a7be7840accdc18344d4 |
| 63 | |
| 64 | three2 sha1:0567da4d5edd2ff4bb292a465ba9e64dcad9536b |
| 65 | three2 sha256:cceb3e8eca364fa9a0a39a1efbebecacc664af86cbbd8070571f5faeb5f0e8c3 |
| 66 | EOF |
| 67 | |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 68 | echo >file original && |
| 69 | git add file && |
| 70 | git commit -a -m One && |
| 71 | git tag tag-one && |
| 72 | git tag tag-one-tree HEAD^{tree} && |
| 73 | git branch one && |
| 74 | |
| 75 | echo two >> file && |
| 76 | git commit -a -m Two && |
| 77 | git tag -a -m "Tag Two" tag-two && |
| 78 | git branch two && |
| 79 | |
| 80 | echo three >> file && |
| 81 | git commit -a -m Three && |
| 82 | git tag -a -m "Tag Three" tag-three && |
| 83 | git tag -a -m "Tag Three file" tag-three-file HEAD^{tree}:file && |
| 84 | git branch three && |
| 85 | |
Johannes Schindelin | 62e7daa | 2020-11-02 23:55:04 +0000 | [diff] [blame] | 86 | echo main >> file && |
| 87 | git commit -a -m Main && |
| 88 | git tag -a -m "Tag Main" tag-main && |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 89 | |
| 90 | git checkout three && |
| 91 | |
| 92 | git clone . cloned && |
| 93 | cd cloned && |
| 94 | git config remote.origin.url ../.git/ && |
| 95 | |
| 96 | git config remote.config-explicit.url ../.git/ && |
Johannes Schindelin | 62e7daa | 2020-11-02 23:55:04 +0000 | [diff] [blame] | 97 | git config remote.config-explicit.fetch refs/heads/main:remotes/rem/main && |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 98 | git config --add remote.config-explicit.fetch refs/heads/one:remotes/rem/one && |
| 99 | git config --add remote.config-explicit.fetch two:remotes/rem/two && |
| 100 | git config --add remote.config-explicit.fetch refs/heads/three:remotes/rem/three && |
| 101 | remotes="config-explicit" && |
| 102 | |
| 103 | git config remote.config-glob.url ../.git/ && |
| 104 | git config remote.config-glob.fetch refs/heads/*:refs/remotes/rem/* && |
| 105 | remotes="$remotes config-glob" && |
| 106 | |
Junio C Hamano | 926d18e | 2025-03-11 14:25:02 -0700 | [diff] [blame] | 107 | if ! test_have_prereq WITH_BREAKING_CHANGES |
Patrick Steinhardt | 8ccc75c | 2025-01-22 12:31:33 +0100 | [diff] [blame] | 108 | then |
| 109 | mkdir -p .git/remotes && |
| 110 | cat >.git/remotes/remote-explicit <<-\EOF && |
| 111 | URL: ../.git/ |
| 112 | Pull: refs/heads/main:remotes/rem/main |
| 113 | Pull: refs/heads/one:remotes/rem/one |
| 114 | Pull: two:remotes/rem/two |
| 115 | Pull: refs/heads/three:remotes/rem/three |
| 116 | EOF |
| 117 | remotes="$remotes remote-explicit" && |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 118 | |
Patrick Steinhardt | 8ccc75c | 2025-01-22 12:31:33 +0100 | [diff] [blame] | 119 | cat >.git/remotes/remote-glob <<-\EOF && |
| 120 | URL: ../.git/ |
| 121 | Pull: refs/heads/*:refs/remotes/rem/* |
| 122 | EOF |
| 123 | remotes="$remotes remote-glob" && |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 124 | |
Patrick Steinhardt | 8ccc75c | 2025-01-22 12:31:33 +0100 | [diff] [blame] | 125 | mkdir -p .git/branches && |
| 126 | echo "../.git" > .git/branches/branches-default && |
| 127 | remotes="$remotes branches-default" && |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 128 | |
Patrick Steinhardt | 8ccc75c | 2025-01-22 12:31:33 +0100 | [diff] [blame] | 129 | echo "../.git#one" > .git/branches/branches-one && |
| 130 | remotes="$remotes branches-one" |
| 131 | fi && |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 132 | |
| 133 | for remote in $remotes ; do |
| 134 | git config branch.br-$remote.remote $remote && |
| 135 | git config branch.br-$remote-merge.remote $remote && |
| 136 | git config branch.br-$remote-merge.merge refs/heads/three && |
| 137 | git config branch.br-$remote-octopus.remote $remote && |
| 138 | git config branch.br-$remote-octopus.merge refs/heads/one && |
Eric Sunshine | d0fd993 | 2021-12-09 00:11:14 -0500 | [diff] [blame] | 139 | git config --add branch.br-$remote-octopus.merge two || return 1 |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 140 | done && |
| 141 | build_script sed_script |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 142 | ' |
| 143 | |
| 144 | # Merge logic depends on branch properties and Pull: or .fetch lines |
| 145 | for remote in $remotes ; do |
| 146 | for branch in "" "-merge" "-octopus" ; do |
| 147 | cat <<EOF |
| 148 | br-$remote$branch |
| 149 | br-$remote$branch $remote |
| 150 | EOF |
| 151 | done |
| 152 | done > tests |
| 153 | |
| 154 | # Merge logic does not depend on branch properties, |
| 155 | # but does depend on Pull: or fetch lines. |
| 156 | # Use two branches completely unrelated from the arguments, |
| 157 | # the clone default and one without branch properties |
Johannes Schindelin | 62e7daa | 2020-11-02 23:55:04 +0000 | [diff] [blame] | 158 | for branch in main br-unconfig ; do |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 159 | echo $branch |
| 160 | for remote in $remotes ; do |
| 161 | echo $branch $remote |
| 162 | done |
| 163 | done >> tests |
| 164 | |
| 165 | # Merge logic does not depend on branch properties |
| 166 | # neither in the Pull: or .fetch config |
Johannes Schindelin | 62e7daa | 2020-11-02 23:55:04 +0000 | [diff] [blame] | 167 | for branch in main br-unconfig ; do |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 168 | cat <<EOF |
Santi B,Ai(Bjar | e3d842c | 2007-03-07 13:18:59 +0100 | [diff] [blame] | 169 | $branch ../.git |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 170 | $branch ../.git one |
| 171 | $branch ../.git one two |
| 172 | $branch --tags ../.git |
| 173 | $branch ../.git tag tag-one tag tag-three |
| 174 | $branch ../.git tag tag-one-tree tag tag-three-file |
| 175 | $branch ../.git one tag tag-one tag tag-three-file |
| 176 | EOF |
| 177 | done >> tests |
| 178 | |
| 179 | while read cmd |
| 180 | do |
| 181 | case "$cmd" in |
| 182 | '' | '#'*) continue ;; |
| 183 | esac |
Elia Pinto | 28666e5 | 2015-12-23 14:45:56 +0100 | [diff] [blame] | 184 | test=$(echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g') |
| 185 | pfx=$(printf "%04d" $test_count) |
Junio C Hamano | bfdbee9 | 2008-08-08 02:26:28 -0700 | [diff] [blame] | 186 | expect_f="$TEST_DIRECTORY/t5515/fetch.$test" |
Junio C Hamano | a466637 | 2008-03-26 01:17:07 -0700 | [diff] [blame] | 187 | actual_f="$pfx-fetch.$test" |
Junio C Hamano | bfdbee9 | 2008-08-08 02:26:28 -0700 | [diff] [blame] | 188 | expect_r="$TEST_DIRECTORY/t5515/refs.$test" |
Junio C Hamano | a466637 | 2008-03-26 01:17:07 -0700 | [diff] [blame] | 189 | actual_r="$pfx-refs.$test" |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 190 | |
| 191 | test_expect_success "$cmd" ' |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 192 | cp "$expect_f" expect_f && |
| 193 | convert_expected expect_f sed_script && |
| 194 | cp "$expect_r" expect_r && |
| 195 | convert_expected expect_r sed_script && |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 196 | { |
Eric Sunshine | 7abcbcb | 2021-12-09 00:11:08 -0500 | [diff] [blame] | 197 | echo "# $cmd" && |
| 198 | set x $cmd && shift && |
| 199 | git symbolic-ref HEAD refs/heads/$1 && shift && |
| 200 | rm -f .git/FETCH_HEAD && |
Johan Herland | d0d12b4 | 2008-06-16 01:16:53 +0200 | [diff] [blame] | 201 | git for-each-ref \ |
| 202 | refs/heads refs/remotes/rem refs/tags | |
| 203 | while read val type refname |
| 204 | do |
Eric Sunshine | d0fd993 | 2021-12-09 00:11:14 -0500 | [diff] [blame] | 205 | git update-ref -d "$refname" "$val" || return 1 |
Eric Sunshine | 7abcbcb | 2021-12-09 00:11:08 -0500 | [diff] [blame] | 206 | done && |
| 207 | git fetch "$@" >/dev/null && |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 208 | cat .git/FETCH_HEAD |
Junio C Hamano | a466637 | 2008-03-26 01:17:07 -0700 | [diff] [blame] | 209 | } >"$actual_f" && |
| 210 | git show-ref >"$actual_r" && |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 211 | if test -f "expect_f" |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 212 | then |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 213 | test_cmp "expect_f" "$actual_f" && |
Junio C Hamano | a466637 | 2008-03-26 01:17:07 -0700 | [diff] [blame] | 214 | rm -f "$actual_f" |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 215 | else |
| 216 | # this is to help developing new tests. |
Junio C Hamano | a466637 | 2008-03-26 01:17:07 -0700 | [diff] [blame] | 217 | cp "$actual_f" "$expect_f" |
| 218 | false |
| 219 | fi && |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 220 | if test -f "expect_r" |
Junio C Hamano | a466637 | 2008-03-26 01:17:07 -0700 | [diff] [blame] | 221 | then |
brian m. carlson | f7ae8e6 | 2020-02-07 00:52:48 +0000 | [diff] [blame] | 222 | test_cmp "expect_r" "$actual_r" && |
Junio C Hamano | a466637 | 2008-03-26 01:17:07 -0700 | [diff] [blame] | 223 | rm -f "$actual_r" |
| 224 | else |
| 225 | # this is to help developing new tests. |
| 226 | cp "$actual_r" "$expect_r" |
Santi Béjar | ac3ec0d | 2007-03-05 09:09:39 +0100 | [diff] [blame] | 227 | false |
| 228 | fi |
| 229 | ' |
| 230 | done < tests |
| 231 | |
| 232 | test_done |