t / t3010-ls-files-killed-modified.shon commit Merge branch 'js/xread-in-full' (0a3bc7d)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='git ls-files -k and -m flags test.
   7
   8This test prepares the following in the cache:
   9
  10    path0       - a file
  11    path1       - a symlink
  12    path2/file2 - a file in a directory
  13    path3/file3 - a file in a directory
  14    submod1/    - a submodule
  15    submod2/    - another submodule
  16
  17and the following on the filesystem:
  18
  19    path0/file0 - a file in a directory
  20    path1/file1 - a file in a directory
  21    path2       - a file
  22    path3       - a symlink
  23    path4       - a file
  24    path5       - a symlink
  25    path6/file6 - a file in a directory
  26    submod1/    - a submodule (modified from the cache)
  27    submod2/    - a submodule (matches the cache)
  28
  29git ls-files -k should report that existing filesystem objects
  30path0/*, path1/*, path2 and path3 to be killed.
  31
  32Also for modification test, the cache and working tree have:
  33
  34    path7       - an empty file, modified to a non-empty file.
  35    path8       - a non-empty file, modified to an empty file.
  36    path9       - an empty file, cache dirtied.
  37    path10      - a non-empty file, cache dirtied.
  38
  39We should report path0, path1, path2/file2, path3/file3, path7 and path8
  40modified without reporting path9 and path10.  submod1 is also modified.
  41'
  42. ./test-lib.sh
  43
  44test_expect_success 'git update-index --add to add various paths.' '
  45        date >path0 &&
  46        test_ln_s_add xyzzy path1 &&
  47        mkdir path2 path3 &&
  48        date >path2/file2 &&
  49        date >path3/file3 &&
  50        : >path7 &&
  51        date >path8 &&
  52        : >path9 &&
  53        date >path10 &&
  54        git update-index --add -- path0 path?/file? path7 path8 path9 path10 &&
  55        for i in 1 2
  56        do
  57                git init submod$i &&
  58                (
  59                        cd submod$i && git commit --allow-empty -m "empty $i"
  60                ) || break
  61        done &&
  62        git update-index --add submod[12]
  63        (
  64                cd submod1 &&
  65                git commit --allow-empty -m "empty 1 (updated)"
  66        ) &&
  67        rm -fr path?    # leave path10 alone
  68'
  69
  70test_expect_success 'git ls-files -k to show killed files.' '
  71        date >path2 &&
  72        if test_have_prereq SYMLINKS
  73        then
  74                ln -s frotz path3 &&
  75                ln -s nitfol path5
  76        else
  77                date >path3 &&
  78                date >path5
  79        fi &&
  80        mkdir path0 path1 path6 &&
  81        date >path0/file0 &&
  82        date >path1/file1 &&
  83        date >path6/file6 &&
  84        date >path7 &&
  85        : >path8 &&
  86        : >path9 &&
  87        touch path10 &&
  88        git ls-files -k >.output
  89'
  90
  91test_expect_success 'validate git ls-files -k output.' '
  92        cat >.expected <<-\EOF &&
  93        path0/file0
  94        path1/file1
  95        path2
  96        path3
  97        EOF
  98        test_cmp .expected .output
  99'
 100
 101test_expect_success 'git ls-files -m to show modified files.' '
 102        git ls-files -m >.output
 103'
 104
 105test_expect_success 'validate git ls-files -m output.' '
 106        cat >.expected <<-\EOF &&
 107        path0
 108        path1
 109        path2/file2
 110        path3/file3
 111        path7
 112        path8
 113        submod1
 114        EOF
 115        test_cmp .expected .output
 116'
 117
 118test_done