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