t / t1002-read-tree-m-u-2way.shon commit Extend index to save more flags (06aaaa0)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='Two way merge with read-tree -m -u $H $M
   7
   8This is identical to t1001, but uses -u to update the work tree as well.
   9
  10'
  11. ./test-lib.sh
  12
  13_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
  14_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
  15compare_change () {
  16        sed >current \
  17            -e '1{/^diff --git /d;}' \
  18            -e '2{/^index /d;}' \
  19            -e '/^--- /d; /^+++ /d; /^@@ /d;' \
  20            -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /' "$1"
  21        test_cmp expected current
  22}
  23
  24check_cache_at () {
  25        clean_if_empty=`git diff-files -- "$1"`
  26        case "$clean_if_empty" in
  27        '')  echo "$1: clean" ;;
  28        ?*)  echo "$1: dirty" ;;
  29        esac
  30        case "$2,$clean_if_empty" in
  31        clean,)         :     ;;
  32        clean,?*)       false ;;
  33        dirty,)         false ;;
  34        dirty,?*)       :     ;;
  35        esac
  36}
  37
  38test_expect_success \
  39    setup \
  40    'echo frotz >frotz &&
  41     echo nitfol >nitfol &&
  42     echo bozbar >bozbar &&
  43     echo rezrov >rezrov &&
  44     git update-index --add nitfol bozbar rezrov &&
  45     treeH=`git write-tree` &&
  46     echo treeH $treeH &&
  47     git ls-tree $treeH &&
  48
  49     echo gnusto >bozbar &&
  50     git update-index --add frotz bozbar --force-remove rezrov &&
  51     git ls-files --stage >M.out &&
  52     treeM=`git write-tree` &&
  53     echo treeM $treeM &&
  54     git ls-tree $treeM &&
  55     sum bozbar frotz nitfol >M.sum &&
  56     git diff-tree $treeH $treeM'
  57
  58test_expect_success \
  59    '1, 2, 3 - no carry forward' \
  60    'rm -f .git/index nitfol bozbar rezrov frotz &&
  61     git read-tree --reset -u $treeH &&
  62     git read-tree -m -u $treeH $treeM &&
  63     git ls-files --stage >1-3.out &&
  64     cmp M.out 1-3.out &&
  65     sum bozbar frotz nitfol >actual3.sum &&
  66     cmp M.sum actual3.sum &&
  67     check_cache_at bozbar clean &&
  68     check_cache_at frotz clean &&
  69     check_cache_at nitfol clean'
  70
  71test_expect_success \
  72    '4 - carry forward local addition.' \
  73    'rm -f .git/index nitfol bozbar rezrov frotz &&
  74     git read-tree --reset -u $treeH &&
  75     echo "+100644 X 0  yomin" >expected &&
  76     echo yomin >yomin &&
  77     git update-index --add yomin &&
  78     git read-tree -m -u $treeH $treeM &&
  79     git ls-files --stage >4.out || return 1
  80     git diff -U0 --no-index M.out 4.out >4diff.out
  81     compare_change 4diff.out expected &&
  82     check_cache_at yomin clean &&
  83     sum bozbar frotz nitfol >actual4.sum &&
  84     cmp M.sum actual4.sum &&
  85     echo yomin >yomin1 &&
  86     diff yomin yomin1 &&
  87     rm -f yomin1'
  88
  89test_expect_success \
  90    '5 - carry forward local addition.' \
  91    'rm -f .git/index nitfol bozbar rezrov frotz &&
  92     git read-tree --reset -u $treeH &&
  93     git read-tree -m -u $treeH &&
  94     echo yomin >yomin &&
  95     git update-index --add yomin &&
  96     echo yomin yomin >yomin &&
  97     git read-tree -m -u $treeH $treeM &&
  98     git ls-files --stage >5.out || return 1
  99     git diff -U0 --no-index M.out 5.out >5diff.out
 100     compare_change 5diff.out expected &&
 101     check_cache_at yomin dirty &&
 102     sum bozbar frotz nitfol >actual5.sum &&
 103     cmp M.sum actual5.sum &&
 104     : dirty index should have prevented -u from checking it out. &&
 105     echo yomin yomin >yomin1 &&
 106     diff yomin yomin1 &&
 107     rm -f yomin1'
 108
 109test_expect_success \
 110    '6 - local addition already has the same.' \
 111    'rm -f .git/index nitfol bozbar rezrov frotz &&
 112     git read-tree --reset -u $treeH &&
 113     echo frotz >frotz &&
 114     git update-index --add frotz &&
 115     git read-tree -m -u $treeH $treeM &&
 116     git ls-files --stage >6.out &&
 117     test_cmp M.out 6.out &&
 118     check_cache_at frotz clean &&
 119     sum bozbar frotz nitfol >actual3.sum &&
 120     cmp M.sum actual3.sum &&
 121     echo frotz >frotz1 &&
 122     diff frotz frotz1 &&
 123     rm -f frotz1'
 124
 125test_expect_success \
 126    '7 - local addition already has the same.' \
 127    'rm -f .git/index nitfol bozbar rezrov frotz &&
 128     git read-tree --reset -u $treeH &&
 129     echo frotz >frotz &&
 130     git update-index --add frotz &&
 131     echo frotz frotz >frotz &&
 132     git read-tree -m -u $treeH $treeM &&
 133     git ls-files --stage >7.out &&
 134     test_cmp M.out 7.out &&
 135     check_cache_at frotz dirty &&
 136     sum bozbar frotz nitfol >actual7.sum &&
 137     if cmp M.sum actual7.sum; then false; else :; fi &&
 138     : dirty index should have prevented -u from checking it out. &&
 139     echo frotz frotz >frotz1 &&
 140     diff frotz frotz1 &&
 141     rm -f frotz1'
 142
 143test_expect_success \
 144    '8 - conflicting addition.' \
 145    'rm -f .git/index nitfol bozbar rezrov frotz &&
 146     git read-tree --reset -u $treeH &&
 147     echo frotz frotz >frotz &&
 148     git update-index --add frotz &&
 149     if git read-tree -m -u $treeH $treeM; then false; else :; fi'
 150
 151test_expect_success \
 152    '9 - conflicting addition.' \
 153    'rm -f .git/index nitfol bozbar rezrov frotz &&
 154     git read-tree --reset -u $treeH &&
 155     echo frotz frotz >frotz &&
 156     git update-index --add frotz &&
 157     echo frotz >frotz &&
 158     if git read-tree -m -u $treeH $treeM; then false; else :; fi'
 159
 160test_expect_success \
 161    '10 - path removed.' \
 162    'rm -f .git/index nitfol bozbar rezrov frotz &&
 163     git read-tree --reset -u $treeH &&
 164     echo rezrov >rezrov &&
 165     git update-index --add rezrov &&
 166     git read-tree -m -u $treeH $treeM &&
 167     git ls-files --stage >10.out &&
 168     cmp M.out 10.out &&
 169     sum bozbar frotz nitfol >actual10.sum &&
 170     cmp M.sum actual10.sum'
 171
 172test_expect_success \
 173    '11 - dirty path removed.' \
 174    'rm -f .git/index nitfol bozbar rezrov frotz &&
 175     git read-tree --reset -u $treeH &&
 176     echo rezrov >rezrov &&
 177     git update-index --add rezrov &&
 178     echo rezrov rezrov >rezrov &&
 179     if git read-tree -m -u $treeH $treeM; then false; else :; fi'
 180
 181test_expect_success \
 182    '12 - unmatching local changes being removed.' \
 183    'rm -f .git/index nitfol bozbar rezrov frotz &&
 184     git read-tree --reset -u $treeH &&
 185     echo rezrov rezrov >rezrov &&
 186     git update-index --add rezrov &&
 187     if git read-tree -m -u $treeH $treeM; then false; else :; fi'
 188
 189test_expect_success \
 190    '13 - unmatching local changes being removed.' \
 191    'rm -f .git/index nitfol bozbar rezrov frotz &&
 192     git read-tree --reset -u $treeH &&
 193     echo rezrov rezrov >rezrov &&
 194     git update-index --add rezrov &&
 195     echo rezrov >rezrov &&
 196     if git read-tree -m -u $treeH $treeM; then false; else :; fi'
 197
 198cat >expected <<EOF
 199-100644 X 0     nitfol
 200+100644 X 0     nitfol
 201EOF
 202
 203test_expect_success \
 204    '14 - unchanged in two heads.' \
 205    'rm -f .git/index nitfol bozbar rezrov frotz &&
 206     git read-tree --reset -u $treeH &&
 207     echo nitfol nitfol >nitfol &&
 208     git update-index --add nitfol &&
 209     git read-tree -m -u $treeH $treeM &&
 210     git ls-files --stage >14.out || return 1
 211     git diff -U0 --no-index M.out 14.out >14diff.out
 212     compare_change 14diff.out expected &&
 213     sum bozbar frotz >actual14.sum &&
 214     grep -v nitfol M.sum > expected14.sum &&
 215     cmp expected14.sum actual14.sum &&
 216     sum bozbar frotz nitfol >actual14a.sum &&
 217     if cmp M.sum actual14a.sum; then false; else :; fi &&
 218     check_cache_at nitfol clean &&
 219     echo nitfol nitfol >nitfol1 &&
 220     diff nitfol nitfol1 &&
 221     rm -f nitfol1'
 222
 223test_expect_success \
 224    '15 - unchanged in two heads.' \
 225    'rm -f .git/index nitfol bozbar rezrov frotz &&
 226     git read-tree --reset -u $treeH &&
 227     echo nitfol nitfol >nitfol &&
 228     git update-index --add nitfol &&
 229     echo nitfol nitfol nitfol >nitfol &&
 230     git read-tree -m -u $treeH $treeM &&
 231     git ls-files --stage >15.out || return 1
 232     git diff -U0 --no-index M.out 15.out >15diff.out
 233     compare_change 15diff.out expected &&
 234     check_cache_at nitfol dirty &&
 235     sum bozbar frotz >actual15.sum &&
 236     grep -v nitfol M.sum > expected15.sum &&
 237     cmp expected15.sum actual15.sum &&
 238     sum bozbar frotz nitfol >actual15a.sum &&
 239     if cmp M.sum actual15a.sum; then false; else :; fi &&
 240     echo nitfol nitfol nitfol >nitfol1 &&
 241     diff nitfol nitfol1 &&
 242     rm -f nitfol1'
 243
 244test_expect_success \
 245    '16 - conflicting local change.' \
 246    'rm -f .git/index nitfol bozbar rezrov frotz &&
 247     git read-tree --reset -u $treeH &&
 248     echo bozbar bozbar >bozbar &&
 249     git update-index --add bozbar &&
 250     if git read-tree -m -u $treeH $treeM; then false; else :; fi'
 251
 252test_expect_success \
 253    '17 - conflicting local change.' \
 254    'rm -f .git/index nitfol bozbar rezrov frotz &&
 255     git read-tree --reset -u $treeH &&
 256     echo bozbar bozbar >bozbar &&
 257     git update-index --add bozbar &&
 258     echo bozbar bozbar bozbar >bozbar &&
 259     if git read-tree -m -u $treeH $treeM; then false; else :; fi'
 260
 261test_expect_success \
 262    '18 - local change already having a good result.' \
 263    'rm -f .git/index nitfol bozbar rezrov frotz &&
 264     git read-tree --reset -u $treeH &&
 265     echo gnusto >bozbar &&
 266     git update-index --add bozbar &&
 267     git read-tree -m -u $treeH $treeM &&
 268     git ls-files --stage >18.out &&
 269     test_cmp M.out 18.out &&
 270     check_cache_at bozbar clean &&
 271     sum bozbar frotz nitfol >actual18.sum &&
 272     cmp M.sum actual18.sum'
 273
 274test_expect_success \
 275    '19 - local change already having a good result, further modified.' \
 276    'rm -f .git/index nitfol bozbar rezrov frotz &&
 277     git read-tree --reset -u $treeH &&
 278     echo gnusto >bozbar &&
 279     git update-index --add bozbar &&
 280     echo gnusto gnusto >bozbar &&
 281     git read-tree -m -u $treeH $treeM &&
 282     git ls-files --stage >19.out &&
 283     test_cmp M.out 19.out &&
 284     check_cache_at bozbar dirty &&
 285     sum frotz nitfol >actual19.sum &&
 286     grep -v bozbar  M.sum > expected19.sum &&
 287     cmp expected19.sum actual19.sum &&
 288     sum bozbar frotz nitfol >actual19a.sum &&
 289     if cmp M.sum actual19a.sum; then false; else :; fi &&
 290     echo gnusto gnusto >bozbar1 &&
 291     diff bozbar bozbar1 &&
 292     rm -f bozbar1'
 293
 294test_expect_success \
 295    '20 - no local change, use new tree.' \
 296    'rm -f .git/index nitfol bozbar rezrov frotz &&
 297     git read-tree --reset -u $treeH &&
 298     echo bozbar >bozbar &&
 299     git update-index --add bozbar &&
 300     git read-tree -m -u $treeH $treeM &&
 301     git ls-files --stage >20.out &&
 302     test_cmp M.out 20.out &&
 303     check_cache_at bozbar clean &&
 304     sum bozbar frotz nitfol >actual20.sum &&
 305     cmp M.sum actual20.sum'
 306
 307test_expect_success \
 308    '21 - no local change, dirty cache.' \
 309    'rm -f .git/index nitfol bozbar rezrov frotz &&
 310     git read-tree --reset -u $treeH &&
 311     echo bozbar >bozbar &&
 312     git update-index --add bozbar &&
 313     echo gnusto gnusto >bozbar &&
 314     if git read-tree -m -u $treeH $treeM; then false; else :; fi'
 315
 316# Also make sure we did not break DF vs DF/DF case.
 317test_expect_success \
 318    'DF vs DF/DF case setup.' \
 319    'rm -f .git/index
 320     echo DF >DF &&
 321     git update-index --add DF &&
 322     treeDF=`git write-tree` &&
 323     echo treeDF $treeDF &&
 324     git ls-tree $treeDF &&
 325
 326     rm -f DF &&
 327     mkdir DF &&
 328     echo DF/DF >DF/DF &&
 329     git update-index --add --remove DF DF/DF &&
 330     treeDFDF=`git write-tree` &&
 331     echo treeDFDF $treeDFDF &&
 332     git ls-tree $treeDFDF &&
 333     git ls-files --stage >DFDF.out'
 334
 335test_expect_success \
 336    'DF vs DF/DF case test.' \
 337    'rm -f .git/index &&
 338     rm -fr DF &&
 339     echo DF >DF &&
 340     git update-index --add DF &&
 341     git read-tree -m -u $treeDF $treeDFDF &&
 342     git ls-files --stage >DFDFcheck.out &&
 343     test_cmp DFDF.out DFDFcheck.out &&
 344     check_cache_at DF/DF clean'
 345
 346test_done