t / t2101-update-index-reupdate.shon commit git_mkstemps: correctly test return value of open() (a2cb86c)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Junio C Hamano
   4#
   5
   6test_description='git update-index --again test.
   7'
   8
   9. ./test-lib.sh
  10
  11cat > expected <<\EOF
  12100644 3b18e512dba79e4c8300dd08aeb37f8e728b8dad 0       file1
  13100644 9db8893856a8a02eaa73470054b7c1c5a7c82e47 0       file2
  14EOF
  15test_expect_success 'update-index --add' \
  16        'echo hello world >file1 &&
  17         echo goodbye people >file2 &&
  18         git update-index --add file1 file2 &&
  19         git ls-files -s >current &&
  20         cmp current expected'
  21
  22test_expect_success 'update-index --again' \
  23        'rm -f file1 &&
  24        echo hello everybody >file2 &&
  25        if git update-index --again
  26        then
  27                echo should have refused to remove file1
  28                exit 1
  29        else
  30                echo happy - failed as expected
  31        fi &&
  32         git ls-files -s >current &&
  33         cmp current expected'
  34
  35cat > expected <<\EOF
  36100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0       file2
  37EOF
  38test_expect_success 'update-index --remove --again' \
  39        'git update-index --remove --again &&
  40         git ls-files -s >current &&
  41         cmp current expected'
  42
  43test_expect_success 'first commit' 'git commit -m initial'
  44
  45cat > expected <<\EOF
  46100644 53ab446c3f4e42ce9bb728a0ccb283a101be4979 0       dir1/file3
  47100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0       file2
  48EOF
  49test_expect_success 'update-index again' \
  50        'mkdir -p dir1 &&
  51        echo hello world >dir1/file3 &&
  52        echo goodbye people >file2 &&
  53        git update-index --add file2 dir1/file3 &&
  54        echo hello everybody >file2 &&
  55        echo happy >dir1/file3 &&
  56        git update-index --again &&
  57        git ls-files -s >current &&
  58        cmp current expected'
  59
  60cat > expected <<\EOF
  61100644 d7fb3f695f06c759dbf3ab00046e7cc2da22d10f 0       dir1/file3
  62100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0       file2
  63EOF
  64test_expect_success 'update-index --update from subdir' \
  65        'echo not so happy >file2 &&
  66        (cd dir1 &&
  67        cat ../file2 >file3 &&
  68        git update-index --again
  69        ) &&
  70        git ls-files -s >current &&
  71        cmp current expected'
  72
  73cat > expected <<\EOF
  74100644 594fb5bb1759d90998e2bf2a38261ae8e243c760 0       dir1/file3
  75100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0       file2
  76EOF
  77test_expect_success 'update-index --update with pathspec' \
  78        'echo very happy >file2 &&
  79        cat file2 >dir1/file3 &&
  80        git update-index --again dir1/ &&
  81        git ls-files -s >current &&
  82        cmp current expected'
  83
  84test_done