Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006 Shawn Pearce |
| 4 | # |
| 5 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 6 | test_description='git checkout-index --temp test. |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 7 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 8 | With --temp flag, git checkout-index writes to temporary merge files |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 9 | rather than the tracked path.' |
| 10 | |
Ævar Arnfjörð Bjarmason | b7bcdbd | 2021-10-12 15:56:41 +0200 | [diff] [blame^] | 11 | TEST_PASSES_SANITIZE_LEAK=true |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 12 | . ./test-lib.sh |
| 13 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 14 | test_expect_success 'setup' ' |
| 15 | mkdir asubdir && |
| 16 | echo tree1path0 >path0 && |
| 17 | echo tree1path1 >path1 && |
| 18 | echo tree1path3 >path3 && |
| 19 | echo tree1path4 >path4 && |
| 20 | echo tree1asubdir/path5 >asubdir/path5 && |
| 21 | git update-index --add path0 path1 path3 path4 asubdir/path5 && |
| 22 | t1=$(git write-tree) && |
| 23 | rm -f path* .merge_* actual .git/index && |
| 24 | echo tree2path0 >path0 && |
| 25 | echo tree2path1 >path1 && |
| 26 | echo tree2path2 >path2 && |
| 27 | echo tree2path4 >path4 && |
| 28 | git update-index --add path0 path1 path2 path4 && |
| 29 | t2=$(git write-tree) && |
| 30 | rm -f path* .merge_* actual .git/index && |
| 31 | echo tree2path0 >path0 && |
| 32 | echo tree3path1 >path1 && |
| 33 | echo tree3path2 >path2 && |
| 34 | echo tree3path3 >path3 && |
| 35 | git update-index --add path0 path1 path2 path3 && |
| 36 | t3=$(git write-tree) |
| 37 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 38 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 39 | test_expect_success 'checkout one stage 0 to temporary file' ' |
| 40 | rm -f path* .merge_* actual .git/index && |
| 41 | git read-tree $t1 && |
| 42 | git checkout-index --temp -- path1 >actual && |
| 43 | test_line_count = 1 actual && |
| 44 | test $(cut "-d " -f2 actual) = path1 && |
| 45 | p=$(cut "-d " -f1 actual) && |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 46 | test -f $p && |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 47 | test $(cat $p) = tree1path1 |
| 48 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 49 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 50 | test_expect_success 'checkout all stage 0 to temporary files' ' |
| 51 | rm -f path* .merge_* actual .git/index && |
| 52 | git read-tree $t1 && |
| 53 | git checkout-index -a --temp >actual && |
| 54 | test_line_count = 5 actual && |
| 55 | for f in path0 path1 path3 path4 asubdir/path5 |
| 56 | do |
| 57 | test $(grep $f actual | cut "-d " -f2) = $f && |
| 58 | p=$(grep $f actual | cut "-d " -f1) && |
| 59 | test -f $p && |
| 60 | test $(cat $p) = tree1$f |
| 61 | done |
| 62 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 63 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 64 | test_expect_success 'setup 3-way merge' ' |
| 65 | rm -f path* .merge_* actual .git/index && |
| 66 | git read-tree -m $t1 $t2 $t3 |
| 67 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 68 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 69 | test_expect_success 'checkout one stage 2 to temporary file' ' |
| 70 | rm -f path* .merge_* actual && |
| 71 | git checkout-index --stage=2 --temp -- path1 >actual && |
| 72 | test_line_count = 1 actual && |
| 73 | test $(cut "-d " -f2 actual) = path1 && |
| 74 | p=$(cut "-d " -f1 actual) && |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 75 | test -f $p && |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 76 | test $(cat $p) = tree2path1 |
| 77 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 78 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 79 | test_expect_success 'checkout all stage 2 to temporary files' ' |
| 80 | rm -f path* .merge_* actual && |
| 81 | git checkout-index --all --stage=2 --temp >actual && |
| 82 | test_line_count = 3 actual && |
| 83 | for f in path1 path2 path4 |
| 84 | do |
| 85 | test $(grep $f actual | cut "-d " -f2) = $f && |
| 86 | p=$(grep $f actual | cut "-d " -f1) && |
| 87 | test -f $p && |
| 88 | test $(cat $p) = tree2$f |
| 89 | done |
| 90 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 91 | |
Jeff King | 7e41061 | 2020-10-27 03:37:14 -0400 | [diff] [blame] | 92 | test_expect_success 'checkout all stages of unknown path' ' |
Jeff King | 0b809c8 | 2020-10-27 03:36:02 -0400 | [diff] [blame] | 93 | rm -f path* .merge_* actual && |
| 94 | test_must_fail git checkout-index --stage=all --temp \ |
| 95 | -- does-not-exist 2>stderr && |
| 96 | test_i18ngrep not.in.the.cache stderr |
| 97 | ' |
| 98 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 99 | test_expect_success 'checkout all stages/one file to nothing' ' |
| 100 | rm -f path* .merge_* actual && |
Jeff King | 0b809c8 | 2020-10-27 03:36:02 -0400 | [diff] [blame] | 101 | git checkout-index --stage=all --temp -- path0 >actual 2>stderr && |
| 102 | test_must_be_empty stderr && |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 103 | test_line_count = 0 actual |
| 104 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 105 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 106 | test_expect_success 'checkout all stages/one file to temporary files' ' |
| 107 | rm -f path* .merge_* actual && |
| 108 | git checkout-index --stage=all --temp -- path1 >actual && |
| 109 | test_line_count = 1 actual && |
| 110 | test $(cut "-d " -f2 actual) = path1 && |
| 111 | cut "-d " -f1 actual | (read s1 s2 s3 && |
| 112 | test -f $s1 && |
| 113 | test -f $s2 && |
| 114 | test -f $s3 && |
| 115 | test $(cat $s1) = tree1path1 && |
| 116 | test $(cat $s2) = tree2path1 && |
| 117 | test $(cat $s3) = tree3path1) |
| 118 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 119 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 120 | test_expect_success 'checkout some stages/one file to temporary files' ' |
| 121 | rm -f path* .merge_* actual && |
| 122 | git checkout-index --stage=all --temp -- path2 >actual && |
| 123 | test_line_count = 1 actual && |
| 124 | test $(cut "-d " -f2 actual) = path2 && |
| 125 | cut "-d " -f1 actual | (read s1 s2 s3 && |
| 126 | test $s1 = . && |
| 127 | test -f $s2 && |
| 128 | test -f $s3 && |
| 129 | test $(cat $s2) = tree2path2 && |
| 130 | test $(cat $s3) = tree3path2) |
| 131 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 132 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 133 | test_expect_success 'checkout all stages/all files to temporary files' ' |
| 134 | rm -f path* .merge_* actual && |
| 135 | git checkout-index -a --stage=all --temp >actual && |
| 136 | test_line_count = 5 actual |
| 137 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 138 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 139 | test_expect_success '-- path0: no entry' ' |
| 140 | test x$(grep path0 actual | cut "-d " -f2) = x |
| 141 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 142 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 143 | test_expect_success '-- path1: all 3 stages' ' |
| 144 | test $(grep path1 actual | cut "-d " -f2) = path1 && |
| 145 | grep path1 actual | cut "-d " -f1 | (read s1 s2 s3 && |
| 146 | test -f $s1 && |
| 147 | test -f $s2 && |
| 148 | test -f $s3 && |
| 149 | test $(cat $s1) = tree1path1 && |
| 150 | test $(cat $s2) = tree2path1 && |
| 151 | test $(cat $s3) = tree3path1) |
| 152 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 153 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 154 | test_expect_success '-- path2: no stage 1, have stage 2 and 3' ' |
| 155 | test $(grep path2 actual | cut "-d " -f2) = path2 && |
| 156 | grep path2 actual | cut "-d " -f1 | (read s1 s2 s3 && |
| 157 | test $s1 = . && |
| 158 | test -f $s2 && |
| 159 | test -f $s3 && |
| 160 | test $(cat $s2) = tree2path2 && |
| 161 | test $(cat $s3) = tree3path2) |
| 162 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 163 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 164 | test_expect_success '-- path3: no stage 2, have stage 1 and 3' ' |
| 165 | test $(grep path3 actual | cut "-d " -f2) = path3 && |
| 166 | grep path3 actual | cut "-d " -f1 | (read s1 s2 s3 && |
| 167 | test -f $s1 && |
| 168 | test $s2 = . && |
| 169 | test -f $s3 && |
| 170 | test $(cat $s1) = tree1path3 && |
| 171 | test $(cat $s3) = tree3path3) |
| 172 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 173 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 174 | test_expect_success '-- path4: no stage 3, have stage 1 and 3' ' |
| 175 | test $(grep path4 actual | cut "-d " -f2) = path4 && |
| 176 | grep path4 actual | cut "-d " -f1 | (read s1 s2 s3 && |
| 177 | test -f $s1 && |
| 178 | test -f $s2 && |
| 179 | test $s3 = . && |
| 180 | test $(cat $s1) = tree1path4 && |
| 181 | test $(cat $s2) = tree2path4) |
| 182 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 183 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 184 | test_expect_success '-- asubdir/path5: no stage 2 and 3 have stage 1' ' |
| 185 | test $(grep asubdir/path5 actual | cut "-d " -f2) = asubdir/path5 && |
| 186 | grep asubdir/path5 actual | cut "-d " -f1 | (read s1 s2 s3 && |
| 187 | test -f $s1 && |
| 188 | test $s2 = . && |
| 189 | test $s3 = . && |
| 190 | test $(cat $s1) = tree1asubdir/path5) |
| 191 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 192 | |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 193 | test_expect_success 'checkout --temp within subdir' ' |
| 194 | ( |
| 195 | cd asubdir && |
| 196 | git checkout-index -a --stage=all >actual && |
| 197 | test_line_count = 1 actual && |
| 198 | test $(grep path5 actual | cut "-d " -f2) = path5 && |
| 199 | grep path5 actual | cut "-d " -f1 | (read s1 s2 s3 && |
| 200 | test -f ../$s1 && |
| 201 | test $s2 = . && |
| 202 | test $s3 = . && |
| 203 | test $(cat ../$s1) = tree1asubdir/path5) |
| 204 | ) |
| 205 | ' |
| 206 | |
| 207 | test_expect_success 'checkout --temp symlink' ' |
| 208 | rm -f path* .merge_* actual .git/index && |
Eric Sunshine | 66e28e9 | 2014-12-24 04:43:14 -0500 | [diff] [blame] | 209 | test_ln_s_add path7 path6 && |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 210 | git checkout-index --temp -a >actual && |
| 211 | test_line_count = 1 actual && |
Eric Sunshine | 66e28e9 | 2014-12-24 04:43:14 -0500 | [diff] [blame] | 212 | test $(cut "-d " -f2 actual) = path6 && |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 213 | p=$(cut "-d " -f1 actual) && |
| 214 | test -f $p && |
Eric Sunshine | 66e28e9 | 2014-12-24 04:43:14 -0500 | [diff] [blame] | 215 | test $(cat $p) = path7 |
Eric Sunshine | 9fb7b57 | 2014-12-24 04:43:12 -0500 | [diff] [blame] | 216 | ' |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 217 | |
Eric Sunshine | 74c4de5 | 2014-12-24 04:43:16 -0500 | [diff] [blame] | 218 | test_expect_success 'emit well-formed relative path' ' |
Eric Sunshine | 052b255 | 2014-12-24 04:43:15 -0500 | [diff] [blame] | 219 | rm -f path* .merge_* actual .git/index && |
| 220 | >path0123456789 && |
| 221 | git update-index --add path0123456789 && |
| 222 | ( |
| 223 | cd asubdir && |
| 224 | git checkout-index --temp -- ../path0123456789 >actual && |
| 225 | test_line_count = 1 actual && |
| 226 | test $(cut "-d " -f2 actual) = ../path0123456789 |
| 227 | ) |
| 228 | ' |
| 229 | |
Shawn Pearce | de84f99 | 2006-03-05 03:24:15 -0500 | [diff] [blame] | 230 | test_done |