t / t2101-update-index-reupdate.shon commit Merge branch 'jk/HEAD-symref-in-xfer-namespaces' into maint (5ca0db3)
   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
  11test_expect_success 'update-index --add' '
  12        echo hello world >file1 &&
  13        echo goodbye people >file2 &&
  14        git update-index --add file1 file2 &&
  15        git ls-files -s >current &&
  16        cat >expected <<-EOF &&
  17        100644 $(git hash-object file1) 0       file1
  18        100644 $(git hash-object file2) 0       file2
  19        EOF
  20        cmp current expected
  21'
  22
  23test_expect_success 'update-index --again' '
  24        rm -f file1 &&
  25        echo hello everybody >file2 &&
  26        if git update-index --again
  27        then
  28                echo should have refused to remove file1
  29                exit 1
  30        else
  31                echo happy - failed as expected
  32        fi &&
  33        git ls-files -s >current &&
  34        cmp current expected
  35'
  36
  37test_expect_success 'update-index --remove --again' '
  38        git update-index --remove --again &&
  39        git ls-files -s >current &&
  40        cat >expected <<-EOF &&
  41        100644 $(git hash-object file2) 0       file2
  42        EOF
  43        cmp current expected
  44'
  45
  46test_expect_success 'first commit' 'git commit -m initial'
  47
  48test_expect_success 'update-index again' '
  49        mkdir -p dir1 &&
  50        echo hello world >dir1/file3 &&
  51        echo goodbye people >file2 &&
  52        git update-index --add file2 dir1/file3 &&
  53        echo hello everybody >file2 &&
  54        echo happy >dir1/file3 &&
  55        git update-index --again &&
  56        git ls-files -s >current &&
  57        cat >expected <<-EOF &&
  58        100644 $(git hash-object dir1/file3) 0  dir1/file3
  59        100644 $(git hash-object file2) 0       file2
  60        EOF
  61        cmp current expected
  62'
  63
  64file2=$(git hash-object file2)
  65test_expect_success 'update-index --update from subdir' '
  66        echo not so happy >file2 &&
  67        (cd dir1 &&
  68        cat ../file2 >file3 &&
  69        git update-index --again
  70        ) &&
  71        git ls-files -s >current &&
  72        cat >expected <<-EOF &&
  73        100644 $(git hash-object dir1/file3) 0  dir1/file3
  74        100644 $file2 0 file2
  75        EOF
  76        test_cmp expected current
  77'
  78
  79test_expect_success 'update-index --update with pathspec' '
  80        echo very happy >file2 &&
  81        cat file2 >dir1/file3 &&
  82        git update-index --again dir1/ &&
  83        git ls-files -s >current &&
  84        cat >expected <<-EOF &&
  85        100644 $(git hash-object dir1/file3) 0  dir1/file3
  86        100644 $file2 0 file2
  87        EOF
  88        cmp current expected
  89'
  90
  91test_done