t / t2004-checkout-cache-temp.shon commit Fix parsing of @{-1}@{1} (aa9c55b)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Shawn Pearce
   4#
   5
   6test_description='git checkout-index --temp test.
   7
   8With --temp flag, git checkout-index writes to temporary merge files
   9rather than the tracked path.'
  10
  11. ./test-lib.sh
  12
  13test_expect_success \
  14'preparation' '
  15mkdir asubdir &&
  16echo tree1path0 >path0 &&
  17echo tree1path1 >path1 &&
  18echo tree1path3 >path3 &&
  19echo tree1path4 >path4 &&
  20echo tree1asubdir/path5 >asubdir/path5 &&
  21git update-index --add path0 path1 path3 path4 asubdir/path5 &&
  22t1=$(git write-tree) &&
  23rm -f path* .merge_* out .git/index &&
  24echo tree2path0 >path0 &&
  25echo tree2path1 >path1 &&
  26echo tree2path2 >path2 &&
  27echo tree2path4 >path4 &&
  28git update-index --add path0 path1 path2 path4 &&
  29t2=$(git write-tree) &&
  30rm -f path* .merge_* out .git/index &&
  31echo tree2path0 >path0 &&
  32echo tree3path1 >path1 &&
  33echo tree3path2 >path2 &&
  34echo tree3path3 >path3 &&
  35git update-index --add path0 path1 path2 path3 &&
  36t3=$(git write-tree)'
  37
  38test_expect_success \
  39'checkout one stage 0 to temporary file' '
  40rm -f path* .merge_* out .git/index &&
  41git read-tree $t1 &&
  42git checkout-index --temp -- path1 >out &&
  43test $(wc -l <out) = 1 &&
  44test $(cut "-d  " -f2 out) = path1 &&
  45p=$(cut "-d     " -f1 out) &&
  46test -f $p &&
  47test $(cat $p) = tree1path1'
  48
  49test_expect_success \
  50'checkout all stage 0 to temporary files' '
  51rm -f path* .merge_* out .git/index &&
  52git read-tree $t1 &&
  53git checkout-index -a --temp >out &&
  54test $(wc -l <out) = 5 &&
  55for f in path0 path1 path3 path4 asubdir/path5
  56do
  57        test $(grep $f out | cut "-d    " -f2) = $f &&
  58        p=$(grep $f out | cut "-d       " -f1) &&
  59        test -f $p &&
  60        test $(cat $p) = tree1$f
  61done'
  62
  63test_expect_success \
  64'prepare 3-way merge' '
  65rm -f path* .merge_* out .git/index &&
  66git read-tree -m $t1 $t2 $t3'
  67
  68test_expect_success \
  69'checkout one stage 2 to temporary file' '
  70rm -f path* .merge_* out &&
  71git checkout-index --stage=2 --temp -- path1 >out &&
  72test $(wc -l <out) = 1 &&
  73test $(cut "-d  " -f2 out) = path1 &&
  74p=$(cut "-d     " -f1 out) &&
  75test -f $p &&
  76test $(cat $p) = tree2path1'
  77
  78test_expect_success \
  79'checkout all stage 2 to temporary files' '
  80rm -f path* .merge_* out &&
  81git checkout-index --all --stage=2 --temp >out &&
  82test $(wc -l <out) = 3 &&
  83for f in path1 path2 path4
  84do
  85        test $(grep $f out | cut "-d    " -f2) = $f &&
  86        p=$(grep $f out | cut "-d       " -f1) &&
  87        test -f $p &&
  88        test $(cat $p) = tree2$f
  89done'
  90
  91test_expect_success \
  92'checkout all stages/one file to nothing' '
  93rm -f path* .merge_* out &&
  94git checkout-index --stage=all --temp -- path0 >out &&
  95test $(wc -l <out) = 0'
  96
  97test_expect_success \
  98'checkout all stages/one file to temporary files' '
  99rm -f path* .merge_* out &&
 100git checkout-index --stage=all --temp -- path1 >out &&
 101test $(wc -l <out) = 1 &&
 102test $(cut "-d  " -f2 out) = path1 &&
 103cut "-d " -f1 out | (read s1 s2 s3 &&
 104test -f $s1 &&
 105test -f $s2 &&
 106test -f $s3 &&
 107test $(cat $s1) = tree1path1 &&
 108test $(cat $s2) = tree2path1 &&
 109test $(cat $s3) = tree3path1)'
 110
 111test_expect_success \
 112'checkout some stages/one file to temporary files' '
 113rm -f path* .merge_* out &&
 114git checkout-index --stage=all --temp -- path2 >out &&
 115test $(wc -l <out) = 1 &&
 116test $(cut "-d  " -f2 out) = path2 &&
 117cut "-d " -f1 out | (read s1 s2 s3 &&
 118test $s1 = . &&
 119test -f $s2 &&
 120test -f $s3 &&
 121test $(cat $s2) = tree2path2 &&
 122test $(cat $s3) = tree3path2)'
 123
 124test_expect_success \
 125'checkout all stages/all files to temporary files' '
 126rm -f path* .merge_* out &&
 127git checkout-index -a --stage=all --temp >out &&
 128test $(wc -l <out) = 5'
 129
 130test_expect_success \
 131'-- path0: no entry' '
 132test x$(grep path0 out | cut "-d        " -f2) = x'
 133
 134test_expect_success \
 135'-- path1: all 3 stages' '
 136test $(grep path1 out | cut "-d " -f2) = path1 &&
 137grep path1 out | cut "-d        " -f1 | (read s1 s2 s3 &&
 138test -f $s1 &&
 139test -f $s2 &&
 140test -f $s3 &&
 141test $(cat $s1) = tree1path1 &&
 142test $(cat $s2) = tree2path1 &&
 143test $(cat $s3) = tree3path1)'
 144
 145test_expect_success \
 146'-- path2: no stage 1, have stage 2 and 3' '
 147test $(grep path2 out | cut "-d " -f2) = path2 &&
 148grep path2 out | cut "-d        " -f1 | (read s1 s2 s3 &&
 149test $s1 = . &&
 150test -f $s2 &&
 151test -f $s3 &&
 152test $(cat $s2) = tree2path2 &&
 153test $(cat $s3) = tree3path2)'
 154
 155test_expect_success \
 156'-- path3: no stage 2, have stage 1 and 3' '
 157test $(grep path3 out | cut "-d " -f2) = path3 &&
 158grep path3 out | cut "-d        " -f1 | (read s1 s2 s3 &&
 159test -f $s1 &&
 160test $s2 = . &&
 161test -f $s3 &&
 162test $(cat $s1) = tree1path3 &&
 163test $(cat $s3) = tree3path3)'
 164
 165test_expect_success \
 166'-- path4: no stage 3, have stage 1 and 3' '
 167test $(grep path4 out | cut "-d " -f2) = path4 &&
 168grep path4 out | cut "-d        " -f1 | (read s1 s2 s3 &&
 169test -f $s1 &&
 170test -f $s2 &&
 171test $s3 = . &&
 172test $(cat $s1) = tree1path4 &&
 173test $(cat $s2) = tree2path4)'
 174
 175test_expect_success \
 176'-- asubdir/path5: no stage 2 and 3 have stage 1' '
 177test $(grep asubdir/path5 out | cut "-d " -f2) = asubdir/path5 &&
 178grep asubdir/path5 out | cut "-d        " -f1 | (read s1 s2 s3 &&
 179test -f $s1 &&
 180test $s2 = . &&
 181test $s3 = . &&
 182test $(cat $s1) = tree1asubdir/path5)'
 183
 184test_expect_success \
 185'checkout --temp within subdir' '
 186(cd asubdir &&
 187 git checkout-index -a --stage=all >out &&
 188 test $(wc -l <out) = 1 &&
 189 test $(grep path5 out | cut "-d        " -f2) = path5 &&
 190 grep path5 out | cut "-d       " -f1 | (read s1 s2 s3 &&
 191 test -f ../$s1 &&
 192 test $s2 = . &&
 193 test $s3 = . &&
 194 test $(cat ../$s1) = tree1asubdir/path5)
 195)'
 196
 197test_expect_success \
 198'checkout --temp symlink' '
 199rm -f path* .merge_* out .git/index &&
 200ln -s b a &&
 201git update-index --add a &&
 202t4=$(git write-tree) &&
 203rm -f .git/index &&
 204git read-tree $t4 &&
 205git checkout-index --temp -a >out &&
 206test $(wc -l <out) = 1 &&
 207test $(cut "-d  " -f2 out) = a &&
 208p=$(cut "-d     " -f1 out) &&
 209test -f $p &&
 210test $(cat $p) = b'
 211
 212test_done