|
| 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 |
| 9 | + |
| 10 | +test_expect_success 'enable split index' ' |
| 11 | + git update-index --split-index && |
| 12 | + test-dump-split-index .git/index >actual && |
| 13 | + cat >expect <<EOF && |
| 14 | +own 8299b0bcd1ac364e5f1d7768efb62fa2da79a339 |
| 15 | +base 39d890139ee5356c7ef572216cebcd27aa41f9df |
| 16 | +replacements: |
| 17 | +deletions: |
| 18 | +EOF |
| 19 | + test_cmp expect actual |
| 20 | +' |
| 21 | + |
| 22 | +test_expect_success 'add one file' ' |
| 23 | + : >one && |
| 24 | + git update-index --add one && |
| 25 | + git ls-files --stage >ls-files.actual && |
| 26 | + cat >ls-files.expect <<EOF && |
| 27 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one |
| 28 | +EOF |
| 29 | + test_cmp ls-files.expect ls-files.actual && |
| 30 | +
|
| 31 | + test-dump-split-index .git/index | sed "/^own/d" >actual && |
| 32 | + cat >expect <<EOF && |
| 33 | +base 39d890139ee5356c7ef572216cebcd27aa41f9df |
| 34 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one |
| 35 | +replacements: |
| 36 | +deletions: |
| 37 | +EOF |
| 38 | + test_cmp expect actual |
| 39 | +' |
| 40 | + |
| 41 | +test_expect_success 'disable split index' ' |
| 42 | + git update-index --no-split-index && |
| 43 | + git ls-files --stage >ls-files.actual && |
| 44 | + cat >ls-files.expect <<EOF && |
| 45 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one |
| 46 | +EOF |
| 47 | + test_cmp ls-files.expect ls-files.actual && |
| 48 | +
|
| 49 | + BASE=`test-dump-split-index .git/index | grep "^own" | sed "s/own/base/"` && |
| 50 | + test-dump-split-index .git/index | sed "/^own/d" >actual && |
| 51 | + cat >expect <<EOF && |
| 52 | +not a split index |
| 53 | +EOF |
| 54 | + test_cmp expect actual |
| 55 | +' |
| 56 | + |
| 57 | +test_expect_success 'enable split index again, "one" now belongs to base index"' ' |
| 58 | + git update-index --split-index && |
| 59 | + git ls-files --stage >ls-files.actual && |
| 60 | + cat >ls-files.expect <<EOF && |
| 61 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one |
| 62 | +EOF |
| 63 | + test_cmp ls-files.expect ls-files.actual && |
| 64 | +
|
| 65 | + test-dump-split-index .git/index | sed "/^own/d" >actual && |
| 66 | + cat >expect <<EOF && |
| 67 | +$BASE |
| 68 | +replacements: |
| 69 | +deletions: |
| 70 | +EOF |
| 71 | + test_cmp expect actual |
| 72 | +' |
| 73 | + |
| 74 | +test_expect_success 'modify original file, base index untouched' ' |
| 75 | + echo modified >one && |
| 76 | + git update-index one && |
| 77 | + git ls-files --stage >ls-files.actual && |
| 78 | + cat >ls-files.expect <<EOF && |
| 79 | +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one |
| 80 | +EOF |
| 81 | + test_cmp ls-files.expect ls-files.actual && |
| 82 | +
|
| 83 | + test-dump-split-index .git/index | sed "/^own/d" >actual && |
| 84 | + q_to_tab >expect <<EOF && |
| 85 | +$BASE |
| 86 | +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q |
| 87 | +replacements: 0 |
| 88 | +deletions: |
| 89 | +EOF |
| 90 | + test_cmp expect actual |
| 91 | +' |
| 92 | + |
| 93 | +test_expect_success 'add another file, which stays index' ' |
| 94 | + : >two && |
| 95 | + git update-index --add two && |
| 96 | + git ls-files --stage >ls-files.actual && |
| 97 | + cat >ls-files.expect <<EOF && |
| 98 | +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one |
| 99 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two |
| 100 | +EOF |
| 101 | + test_cmp ls-files.expect ls-files.actual && |
| 102 | +
|
| 103 | + test-dump-split-index .git/index | sed "/^own/d" >actual && |
| 104 | + q_to_tab >expect <<EOF && |
| 105 | +$BASE |
| 106 | +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q |
| 107 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two |
| 108 | +replacements: 0 |
| 109 | +deletions: |
| 110 | +EOF |
| 111 | + test_cmp expect actual |
| 112 | +' |
| 113 | + |
| 114 | +test_expect_success 'remove file not in base index' ' |
| 115 | + git update-index --force-remove two && |
| 116 | + git ls-files --stage >ls-files.actual && |
| 117 | + cat >ls-files.expect <<EOF && |
| 118 | +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one |
| 119 | +EOF |
| 120 | + test_cmp ls-files.expect ls-files.actual && |
| 121 | +
|
| 122 | + test-dump-split-index .git/index | sed "/^own/d" >actual && |
| 123 | + q_to_tab >expect <<EOF && |
| 124 | +$BASE |
| 125 | +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q |
| 126 | +replacements: 0 |
| 127 | +deletions: |
| 128 | +EOF |
| 129 | + test_cmp expect actual |
| 130 | +' |
| 131 | + |
| 132 | +test_expect_success 'remove file in base index' ' |
| 133 | + git update-index --force-remove one && |
| 134 | + git ls-files --stage >ls-files.actual && |
| 135 | + cat >ls-files.expect <<EOF && |
| 136 | +EOF |
| 137 | + test_cmp ls-files.expect ls-files.actual && |
| 138 | +
|
| 139 | + test-dump-split-index .git/index | sed "/^own/d" >actual && |
| 140 | + cat >expect <<EOF && |
| 141 | +$BASE |
| 142 | +replacements: |
| 143 | +deletions: 0 |
| 144 | +EOF |
| 145 | + test_cmp expect actual |
| 146 | +' |
| 147 | + |
| 148 | +test_expect_success 'add original file back' ' |
| 149 | + : >one && |
| 150 | + git update-index --add one && |
| 151 | + git ls-files --stage >ls-files.actual && |
| 152 | + cat >ls-files.expect <<EOF && |
| 153 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one |
| 154 | +EOF |
| 155 | + test_cmp ls-files.expect ls-files.actual && |
| 156 | +
|
| 157 | + test-dump-split-index .git/index | sed "/^own/d" >actual && |
| 158 | + cat >expect <<EOF && |
| 159 | +$BASE |
| 160 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one |
| 161 | +replacements: |
| 162 | +deletions: 0 |
| 163 | +EOF |
| 164 | + test_cmp expect actual |
| 165 | +' |
| 166 | + |
| 167 | +test_expect_success 'add new file' ' |
| 168 | + : >two && |
| 169 | + git update-index --add two && |
| 170 | + git ls-files --stage >actual && |
| 171 | + cat >expect <<EOF && |
| 172 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one |
| 173 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two |
| 174 | +EOF |
| 175 | + test_cmp expect actual |
| 176 | +' |
| 177 | + |
| 178 | +test_expect_success 'unify index, two files remain' ' |
| 179 | + git update-index --no-split-index && |
| 180 | + git ls-files --stage >ls-files.actual && |
| 181 | + cat >ls-files.expect <<EOF && |
| 182 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one |
| 183 | +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two |
| 184 | +EOF |
| 185 | + test_cmp ls-files.expect ls-files.actual |
| 186 | +
|
| 187 | + test-dump-split-index .git/index | sed "/^own/d" >actual && |
| 188 | + cat >expect <<EOF && |
| 189 | +not a split index |
| 190 | +EOF |
| 191 | + test_cmp expect actual |
| 192 | +' |
| 193 | + |
| 194 | +test_done |
0 commit comments