Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='split index mode tests' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | # We need total control of index splitting here |
| 8 | sane_unset GIT_TEST_SPLIT_INDEX |
Ben Peart | c780b9c | 2018-10-10 11:59:35 -0400 | [diff] [blame] | 9 | |
| 10 | # Testing a hard coded SHA against an index with an extension |
| 11 | # that can vary from run to run is problematic so we disable |
| 12 | # those extensions. |
Ben Peart | 4cb54d0 | 2018-09-18 23:29:35 +0000 | [diff] [blame] | 13 | sane_unset GIT_TEST_FSMONITOR |
Ben Peart | c780b9c | 2018-10-10 11:59:35 -0400 | [diff] [blame] | 14 | sane_unset GIT_TEST_INDEX_THREADS |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 15 | |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 16 | # Create a file named as $1 with content read from stdin. |
| 17 | # Set the file's mtime to a few seconds in the past to avoid racy situations. |
| 18 | create_non_racy_file () { |
| 19 | cat >"$1" && |
| 20 | test-tool chmtime =-5 "$1" |
| 21 | } |
| 22 | |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 23 | test_expect_success 'setup' ' |
| 24 | test_oid_cache <<-EOF |
| 25 | own_v3 sha1:8299b0bcd1ac364e5f1d7768efb62fa2da79a339 |
| 26 | own_v3 sha256:38a6d2925e3eceec33ad7b34cbff4e0086caa0daf28f31e51f5bd94b4a7af86b |
| 27 | |
| 28 | base_v3 sha1:39d890139ee5356c7ef572216cebcd27aa41f9df |
| 29 | base_v3 sha256:c9baeadf905112bf6c17aefbd7d02267afd70ded613c30cafed2d40cb506e1ed |
| 30 | |
| 31 | own_v4 sha1:432ef4b63f32193984f339431fd50ca796493569 |
| 32 | own_v4 sha256:6738ac6319c25b694afa7bcc313deb182d1a59b68bf7a47b4296de83478c0420 |
| 33 | |
| 34 | base_v4 sha1:508851a7f0dfa8691e9f69c7f055865389012491 |
| 35 | base_v4 sha256:3177d4adfdd4b6904f7e921d91d715a471c0dde7cf6a4bba574927f02b699508 |
| 36 | EOF |
| 37 | ' |
| 38 | |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 39 | test_expect_success 'enable split index' ' |
Christian Couder | e6a1dd7 | 2017-02-27 19:00:08 +0100 | [diff] [blame] | 40 | git config splitIndex.maxPercentChange 100 && |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 41 | git update-index --split-index && |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 42 | test-tool dump-split-index .git/index >actual && |
Nguyễn Thái Ngọc Duy | cc6f663 | 2018-03-24 08:44:44 +0100 | [diff] [blame] | 43 | indexversion=$(test-tool index-version <.git/index) && |
Jonathan Nieder | d846550 | 2018-11-19 22:11:47 -0800 | [diff] [blame] | 44 | |
| 45 | # NEEDSWORK: Stop hard-coding checksums. |
Thomas Gummerer | e869c5e | 2015-03-20 19:20:30 +0100 | [diff] [blame] | 46 | if test "$indexversion" = "4" |
| 47 | then |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 48 | own=$(test_oid own_v4) |
| 49 | base=$(test_oid base_v4) |
Thomas Gummerer | e869c5e | 2015-03-20 19:20:30 +0100 | [diff] [blame] | 50 | else |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 51 | own=$(test_oid own_v3) |
| 52 | base=$(test_oid base_v3) |
Thomas Gummerer | e869c5e | 2015-03-20 19:20:30 +0100 | [diff] [blame] | 53 | fi && |
Jonathan Nieder | d846550 | 2018-11-19 22:11:47 -0800 | [diff] [blame] | 54 | |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 55 | cat >expect <<-EOF && |
| 56 | own $own |
| 57 | base $base |
| 58 | replacements: |
| 59 | deletions: |
| 60 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 61 | test_cmp expect actual |
| 62 | ' |
| 63 | |
| 64 | test_expect_success 'add one file' ' |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 65 | create_non_racy_file one && |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 66 | git update-index --add one && |
| 67 | git ls-files --stage >ls-files.actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 68 | cat >ls-files.expect <<-EOF && |
| 69 | 100644 $EMPTY_BLOB 0 one |
| 70 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 71 | test_cmp ls-files.expect ls-files.actual && |
| 72 | |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 73 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 74 | cat >expect <<-EOF && |
| 75 | base $base |
| 76 | 100644 $EMPTY_BLOB 0 one |
| 77 | replacements: |
| 78 | deletions: |
| 79 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 80 | test_cmp expect actual |
| 81 | ' |
| 82 | |
| 83 | test_expect_success 'disable split index' ' |
| 84 | git update-index --no-split-index && |
| 85 | git ls-files --stage >ls-files.actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 86 | cat >ls-files.expect <<-EOF && |
| 87 | 100644 $EMPTY_BLOB 0 one |
| 88 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 89 | test_cmp ls-files.expect ls-files.actual && |
| 90 | |
SZEDER Gábor | acdee9e | 2018-09-06 04:48:06 +0200 | [diff] [blame] | 91 | BASE=$(test-tool dump-split-index .git/index | sed -n "s/^own/base/p") && |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 92 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 93 | cat >expect <<-EOF && |
| 94 | not a split index |
| 95 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 96 | test_cmp expect actual |
| 97 | ' |
| 98 | |
| 99 | test_expect_success 'enable split index again, "one" now belongs to base index"' ' |
| 100 | git update-index --split-index && |
| 101 | git ls-files --stage >ls-files.actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 102 | cat >ls-files.expect <<-EOF && |
| 103 | 100644 $EMPTY_BLOB 0 one |
| 104 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 105 | test_cmp ls-files.expect ls-files.actual && |
| 106 | |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 107 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 108 | cat >expect <<-EOF && |
| 109 | $BASE |
| 110 | replacements: |
| 111 | deletions: |
| 112 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 113 | test_cmp expect actual |
| 114 | ' |
| 115 | |
| 116 | test_expect_success 'modify original file, base index untouched' ' |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 117 | echo modified | create_non_racy_file one && |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 118 | file1_blob=$(git hash-object one) && |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 119 | git update-index one && |
| 120 | git ls-files --stage >ls-files.actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 121 | cat >ls-files.expect <<-EOF && |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 122 | 100644 $file1_blob 0 one |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 123 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 124 | test_cmp ls-files.expect ls-files.actual && |
| 125 | |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 126 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 127 | q_to_tab >expect <<-EOF && |
| 128 | $BASE |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 129 | 100644 $file1_blob 0Q |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 130 | replacements: 0 |
| 131 | deletions: |
| 132 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 133 | test_cmp expect actual |
| 134 | ' |
| 135 | |
| 136 | test_expect_success 'add another file, which stays index' ' |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 137 | create_non_racy_file two && |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 138 | git update-index --add two && |
| 139 | git ls-files --stage >ls-files.actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 140 | cat >ls-files.expect <<-EOF && |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 141 | 100644 $file1_blob 0 one |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 142 | 100644 $EMPTY_BLOB 0 two |
| 143 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 144 | test_cmp ls-files.expect ls-files.actual && |
| 145 | |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 146 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 147 | q_to_tab >expect <<-EOF && |
| 148 | $BASE |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 149 | 100644 $file1_blob 0Q |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 150 | 100644 $EMPTY_BLOB 0 two |
| 151 | replacements: 0 |
| 152 | deletions: |
| 153 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 154 | test_cmp expect actual |
| 155 | ' |
| 156 | |
| 157 | test_expect_success 'remove file not in base index' ' |
| 158 | git update-index --force-remove two && |
| 159 | git ls-files --stage >ls-files.actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 160 | cat >ls-files.expect <<-EOF && |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 161 | 100644 $file1_blob 0 one |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 162 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 163 | test_cmp ls-files.expect ls-files.actual && |
| 164 | |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 165 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 166 | q_to_tab >expect <<-EOF && |
| 167 | $BASE |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 168 | 100644 $file1_blob 0Q |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 169 | replacements: 0 |
| 170 | deletions: |
| 171 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 172 | test_cmp expect actual |
| 173 | ' |
| 174 | |
| 175 | test_expect_success 'remove file in base index' ' |
| 176 | git update-index --force-remove one && |
| 177 | git ls-files --stage >ls-files.actual && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 178 | test_must_be_empty ls-files.actual && |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 179 | |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 180 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 181 | cat >expect <<-EOF && |
| 182 | $BASE |
| 183 | replacements: |
| 184 | deletions: 0 |
| 185 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 186 | test_cmp expect actual |
| 187 | ' |
| 188 | |
| 189 | test_expect_success 'add original file back' ' |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 190 | create_non_racy_file one && |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 191 | git update-index --add one && |
| 192 | git ls-files --stage >ls-files.actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 193 | cat >ls-files.expect <<-EOF && |
| 194 | 100644 $EMPTY_BLOB 0 one |
| 195 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 196 | test_cmp ls-files.expect ls-files.actual && |
| 197 | |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 198 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 199 | cat >expect <<-EOF && |
| 200 | $BASE |
| 201 | 100644 $EMPTY_BLOB 0 one |
| 202 | replacements: |
| 203 | deletions: 0 |
| 204 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 205 | test_cmp expect actual |
| 206 | ' |
| 207 | |
| 208 | test_expect_success 'add new file' ' |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 209 | create_non_racy_file two && |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 210 | git update-index --add two && |
| 211 | git ls-files --stage >actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 212 | cat >expect <<-EOF && |
| 213 | 100644 $EMPTY_BLOB 0 one |
| 214 | 100644 $EMPTY_BLOB 0 two |
| 215 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 216 | test_cmp expect actual |
| 217 | ' |
| 218 | |
| 219 | test_expect_success 'unify index, two files remain' ' |
| 220 | git update-index --no-split-index && |
| 221 | git ls-files --stage >ls-files.actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 222 | cat >ls-files.expect <<-EOF && |
| 223 | 100644 $EMPTY_BLOB 0 one |
| 224 | 100644 $EMPTY_BLOB 0 two |
| 225 | EOF |
Jeff King | 8fb2687 | 2015-03-20 06:06:15 -0400 | [diff] [blame] | 226 | test_cmp ls-files.expect ls-files.actual && |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 227 | |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 228 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | 5662176 | 2017-02-27 18:59:59 +0100 | [diff] [blame] | 229 | cat >expect <<-EOF && |
| 230 | not a split index |
| 231 | EOF |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 232 | test_cmp expect actual |
| 233 | ' |
| 234 | |
Johannes Schindelin | 098aa86 | 2017-02-17 17:59:06 +0100 | [diff] [blame] | 235 | test_expect_success 'rev-parse --shared-index-path' ' |
Michael Rappazzo | 5de8a54 | 2017-02-17 17:59:02 +0100 | [diff] [blame] | 236 | test_create_repo split-index && |
| 237 | ( |
| 238 | cd split-index && |
| 239 | git update-index --split-index && |
| 240 | echo .git/sharedindex* >expect && |
| 241 | git rev-parse --shared-index-path >actual && |
| 242 | test_cmp expect actual && |
| 243 | mkdir subdirectory && |
| 244 | cd subdirectory && |
| 245 | echo ../.git/sharedindex* >expect && |
| 246 | git rev-parse --shared-index-path >actual && |
| 247 | test_cmp expect actual |
| 248 | ) |
| 249 | ' |
| 250 | |
Christian Couder | b8923bf | 2017-02-27 19:00:04 +0100 | [diff] [blame] | 251 | test_expect_success 'set core.splitIndex config variable to true' ' |
| 252 | git config core.splitIndex true && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 253 | create_non_racy_file three && |
Christian Couder | b8923bf | 2017-02-27 19:00:04 +0100 | [diff] [blame] | 254 | git update-index --add three && |
| 255 | git ls-files --stage >ls-files.actual && |
| 256 | cat >ls-files.expect <<-EOF && |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 257 | 100644 $EMPTY_BLOB 0 one |
| 258 | 100644 $EMPTY_BLOB 0 three |
| 259 | 100644 $EMPTY_BLOB 0 two |
Christian Couder | b8923bf | 2017-02-27 19:00:04 +0100 | [diff] [blame] | 260 | EOF |
| 261 | test_cmp ls-files.expect ls-files.actual && |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 262 | BASE=$(test-tool dump-split-index .git/index | grep "^base") && |
| 263 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | b8923bf | 2017-02-27 19:00:04 +0100 | [diff] [blame] | 264 | cat >expect <<-EOF && |
| 265 | $BASE |
| 266 | replacements: |
| 267 | deletions: |
| 268 | EOF |
| 269 | test_cmp expect actual |
| 270 | ' |
| 271 | |
| 272 | test_expect_success 'set core.splitIndex config variable to false' ' |
| 273 | git config core.splitIndex false && |
| 274 | git update-index --force-remove three && |
| 275 | git ls-files --stage >ls-files.actual && |
| 276 | cat >ls-files.expect <<-EOF && |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 277 | 100644 $EMPTY_BLOB 0 one |
| 278 | 100644 $EMPTY_BLOB 0 two |
Christian Couder | b8923bf | 2017-02-27 19:00:04 +0100 | [diff] [blame] | 279 | EOF |
| 280 | test_cmp ls-files.expect ls-files.actual && |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 281 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | b8923bf | 2017-02-27 19:00:04 +0100 | [diff] [blame] | 282 | cat >expect <<-EOF && |
| 283 | not a split index |
| 284 | EOF |
| 285 | test_cmp expect actual |
| 286 | ' |
| 287 | |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 288 | test_expect_success 'set core.splitIndex config variable back to true' ' |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 289 | git config core.splitIndex true && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 290 | create_non_racy_file three && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 291 | git update-index --add three && |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 292 | BASE=$(test-tool dump-split-index .git/index | grep "^base") && |
| 293 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 294 | cat >expect <<-EOF && |
| 295 | $BASE |
| 296 | replacements: |
| 297 | deletions: |
| 298 | EOF |
| 299 | test_cmp expect actual && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 300 | create_non_racy_file four && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 301 | git update-index --add four && |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 302 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 303 | cat >expect <<-EOF && |
| 304 | $BASE |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 305 | 100644 $EMPTY_BLOB 0 four |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 306 | replacements: |
| 307 | deletions: |
| 308 | EOF |
| 309 | test_cmp expect actual |
| 310 | ' |
| 311 | |
| 312 | test_expect_success 'check behavior with splitIndex.maxPercentChange unset' ' |
| 313 | git config --unset splitIndex.maxPercentChange && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 314 | create_non_racy_file five && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 315 | git update-index --add five && |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 316 | BASE=$(test-tool dump-split-index .git/index | grep "^base") && |
| 317 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 318 | cat >expect <<-EOF && |
| 319 | $BASE |
| 320 | replacements: |
| 321 | deletions: |
| 322 | EOF |
| 323 | test_cmp expect actual && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 324 | create_non_racy_file six && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 325 | git update-index --add six && |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 326 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 327 | cat >expect <<-EOF && |
| 328 | $BASE |
brian m. carlson | bfefd52 | 2019-06-28 22:59:27 +0000 | [diff] [blame] | 329 | 100644 $EMPTY_BLOB 0 six |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 330 | replacements: |
| 331 | deletions: |
| 332 | EOF |
| 333 | test_cmp expect actual |
| 334 | ' |
| 335 | |
| 336 | test_expect_success 'check splitIndex.maxPercentChange set to 0' ' |
| 337 | git config splitIndex.maxPercentChange 0 && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 338 | create_non_racy_file seven && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 339 | git update-index --add seven && |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 340 | BASE=$(test-tool dump-split-index .git/index | grep "^base") && |
| 341 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 342 | cat >expect <<-EOF && |
| 343 | $BASE |
| 344 | replacements: |
| 345 | deletions: |
| 346 | EOF |
| 347 | test_cmp expect actual && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 348 | create_non_racy_file eight && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 349 | git update-index --add eight && |
Nguyễn Thái Ngọc Duy | 8133061 | 2018-03-24 08:44:40 +0100 | [diff] [blame] | 350 | BASE=$(test-tool dump-split-index .git/index | grep "^base") && |
| 351 | test-tool dump-split-index .git/index | sed "/^own/d" >actual && |
Christian Couder | fcdbd95 | 2017-02-27 19:00:09 +0100 | [diff] [blame] | 352 | cat >expect <<-EOF && |
| 353 | $BASE |
| 354 | replacements: |
| 355 | deletions: |
| 356 | EOF |
| 357 | test_cmp expect actual |
| 358 | ' |
| 359 | |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 360 | test_expect_success 'shared index files expire after 2 weeks by default' ' |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 361 | create_non_racy_file ten && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 362 | git update-index --add ten && |
Christian Couder | c3a0082 | 2017-03-06 10:42:01 +0100 | [diff] [blame] | 363 | test $(ls .git/sharedindex.* | wc -l) -gt 2 && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 364 | just_under_2_weeks_ago=$((5-14*86400)) && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 365 | test-tool chmtime =$just_under_2_weeks_ago .git/sharedindex.* && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 366 | create_non_racy_file eleven && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 367 | git update-index --add eleven && |
Christian Couder | c3a0082 | 2017-03-06 10:42:01 +0100 | [diff] [blame] | 368 | test $(ls .git/sharedindex.* | wc -l) -gt 2 && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 369 | just_over_2_weeks_ago=$((-1-14*86400)) && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 370 | test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 371 | create_non_racy_file twelve && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 372 | git update-index --add twelve && |
Christian Couder | c3a0082 | 2017-03-06 10:42:01 +0100 | [diff] [blame] | 373 | test $(ls .git/sharedindex.* | wc -l) -le 2 |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 374 | ' |
| 375 | |
| 376 | test_expect_success 'check splitIndex.sharedIndexExpire set to 16 days' ' |
| 377 | git config splitIndex.sharedIndexExpire "16.days.ago" && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 378 | test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 379 | create_non_racy_file thirteen && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 380 | git update-index --add thirteen && |
Christian Couder | c3a0082 | 2017-03-06 10:42:01 +0100 | [diff] [blame] | 381 | test $(ls .git/sharedindex.* | wc -l) -gt 2 && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 382 | just_over_16_days_ago=$((-1-16*86400)) && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 383 | test-tool chmtime =$just_over_16_days_ago .git/sharedindex.* && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 384 | create_non_racy_file fourteen && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 385 | git update-index --add fourteen && |
Christian Couder | c3a0082 | 2017-03-06 10:42:01 +0100 | [diff] [blame] | 386 | test $(ls .git/sharedindex.* | wc -l) -le 2 |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 387 | ' |
| 388 | |
| 389 | test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"' ' |
| 390 | git config splitIndex.sharedIndexExpire never && |
| 391 | just_10_years_ago=$((-365*10*86400)) && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 392 | test-tool chmtime =$just_10_years_ago .git/sharedindex.* && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 393 | create_non_racy_file fifteen && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 394 | git update-index --add fifteen && |
Christian Couder | c3a0082 | 2017-03-06 10:42:01 +0100 | [diff] [blame] | 395 | test $(ls .git/sharedindex.* | wc -l) -gt 2 && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 396 | git config splitIndex.sharedIndexExpire now && |
| 397 | just_1_second_ago=-1 && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 398 | test-tool chmtime =$just_1_second_ago .git/sharedindex.* && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 399 | create_non_racy_file sixteen && |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 400 | git update-index --add sixteen && |
Christian Couder | c3a0082 | 2017-03-06 10:42:01 +0100 | [diff] [blame] | 401 | test $(ls .git/sharedindex.* | wc -l) -le 2 |
Christian Couder | c0441f7 | 2017-03-06 10:41:59 +0100 | [diff] [blame] | 402 | ' |
| 403 | |
Ævar Arnfjörð Bjarmason | c9d6c78 | 2018-11-18 19:04:29 +0000 | [diff] [blame] | 404 | test_expect_success POSIXPERM 'same mode for index & split index' ' |
| 405 | git init same-mode && |
| 406 | ( |
| 407 | cd same-mode && |
| 408 | test_commit A && |
| 409 | test_modebits .git/index >index_mode && |
| 410 | test_must_fail git config core.sharedRepository && |
| 411 | git -c core.splitIndex=true status && |
| 412 | shared=$(ls .git/sharedindex.*) && |
| 413 | case "$shared" in |
| 414 | *" "*) |
| 415 | # we have more than one??? |
| 416 | false ;; |
| 417 | *) |
| 418 | test_modebits "$shared" >split_index_mode && |
| 419 | test_cmp index_mode split_index_mode ;; |
| 420 | esac |
| 421 | ) |
| 422 | ' |
| 423 | |
Christian Couder | 3ee83f4 | 2017-06-25 06:34:29 +0200 | [diff] [blame] | 424 | while read -r mode modebits |
| 425 | do |
| 426 | test_expect_success POSIXPERM "split index respects core.sharedrepository $mode" ' |
| 427 | # Remove existing shared index files |
| 428 | git config core.splitIndex false && |
| 429 | git update-index --force-remove one && |
| 430 | rm -f .git/sharedindex.* && |
| 431 | # Create one new shared index file |
| 432 | git config core.sharedrepository "$mode" && |
| 433 | git config core.splitIndex true && |
SZEDER Gábor | c6e5607 | 2018-10-11 11:43:06 +0200 | [diff] [blame] | 434 | create_non_racy_file one && |
Christian Couder | 3ee83f4 | 2017-06-25 06:34:29 +0200 | [diff] [blame] | 435 | git update-index --add one && |
| 436 | echo "$modebits" >expect && |
| 437 | test_modebits .git/index >actual && |
| 438 | test_cmp expect actual && |
| 439 | shared=$(ls .git/sharedindex.*) && |
| 440 | case "$shared" in |
| 441 | *" "*) |
| 442 | # we have more than one??? |
| 443 | false ;; |
| 444 | *) |
| 445 | test_modebits "$shared" >actual && |
| 446 | test_cmp expect actual ;; |
| 447 | esac |
| 448 | ' |
| 449 | done <<\EOF |
| 450 | 0666 -rw-rw-rw- |
| 451 | 0642 -rw-r---w- |
| 452 | EOF |
| 453 | |
Nguyễn Thái Ngọc Duy | ef5b3a6 | 2018-01-24 16:38:29 +0700 | [diff] [blame] | 454 | test_expect_success POSIXPERM,SANITY 'graceful handling when splitting index is not allowed' ' |
| 455 | test_create_repo ro && |
| 456 | ( |
| 457 | cd ro && |
| 458 | test_commit initial && |
| 459 | git update-index --split-index && |
| 460 | test -f .git/sharedindex.* |
| 461 | ) && |
| 462 | cp ro/.git/index new-index && |
| 463 | test_when_finished "chmod u+w ro/.git" && |
| 464 | chmod u-w ro/.git && |
| 465 | GIT_INDEX_FILE="$(pwd)/new-index" git -C ro update-index --split-index && |
| 466 | chmod u+w ro/.git && |
| 467 | rm ro/.git/sharedindex.* && |
| 468 | GIT_INDEX_FILE=new-index git ls-files >actual && |
| 469 | echo initial.t >expected && |
| 470 | test_cmp expected actual |
| 471 | ' |
| 472 | |
Thomas Gummerer | 4bddd98 | 2018-01-07 22:30:14 +0000 | [diff] [blame] | 473 | test_expect_success 'writing split index with null sha1 does not write cache tree' ' |
| 474 | git config core.splitIndex true && |
| 475 | git config splitIndex.maxPercentChange 0 && |
| 476 | git commit -m "commit" && |
| 477 | { |
| 478 | git ls-tree HEAD && |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 479 | printf "160000 commit $ZERO_OID\\tbroken\\n" |
Thomas Gummerer | 4bddd98 | 2018-01-07 22:30:14 +0000 | [diff] [blame] | 480 | } >broken-tree && |
| 481 | echo "add broken entry" >msg && |
| 482 | |
| 483 | tree=$(git mktree <broken-tree) && |
| 484 | test_tick && |
| 485 | commit=$(git commit-tree $tree -p HEAD <msg) && |
| 486 | git update-ref HEAD "$commit" && |
| 487 | GIT_ALLOW_NULL_SHA1=1 git reset --hard && |
Eric Sunshine | 8327974 | 2018-07-01 20:23:41 -0400 | [diff] [blame] | 488 | test_might_fail test-tool dump-cache-tree >cache-tree.out && |
Thomas Gummerer | 4bddd98 | 2018-01-07 22:30:14 +0000 | [diff] [blame] | 489 | test_line_count = 0 cache-tree.out |
| 490 | ' |
| 491 | |
Nguyễn Thái Ngọc Duy | 6e37c8e | 2019-02-13 16:51:29 +0700 | [diff] [blame] | 492 | test_expect_success 'do not refresh null base index' ' |
| 493 | test_create_repo merge && |
| 494 | ( |
| 495 | cd merge && |
| 496 | test_commit initial && |
| 497 | git checkout -b side-branch && |
| 498 | test_commit extra && |
| 499 | git checkout master && |
| 500 | git update-index --split-index && |
| 501 | test_commit more && |
| 502 | # must not write a new shareindex, or we wont catch the problem |
| 503 | git -c splitIndex.maxPercentChange=100 merge --no-edit side-branch 2>err && |
| 504 | # i.e. do not expect warnings like |
| 505 | # could not freshen shared index .../shareindex.00000... |
| 506 | test_must_be_empty err |
| 507 | ) |
| 508 | ' |
| 509 | |
Nguyễn Thái Ngọc Duy | 3e52f70 | 2014-06-13 19:19:51 +0700 | [diff] [blame] | 510 | test_done |