t / t4010-diff-pathspec.shon commit send-email: support separate Reply-To address (d11c943)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='Pathspec restrictions
   7
   8Prepare:
   9        file0
  10        path1/file1
  11'
  12. ./test-lib.sh
  13. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
  14
  15test_expect_success \
  16    setup \
  17    'echo frotz >file0 &&
  18     mkdir path1 &&
  19     echo rezrov >path1/file1 &&
  20     git update-index --add file0 path1/file1 &&
  21     tree=$(git write-tree) &&
  22     echo "$tree" &&
  23     echo nitfol >file0 &&
  24     echo yomin >path1/file1 &&
  25     git update-index file0 path1/file1'
  26
  27cat >expected <<\EOF
  28EOF
  29test_expect_success \
  30    'limit to path should show nothing' \
  31    'git diff-index --cached $tree -- path >current &&
  32     compare_diff_raw current expected'
  33
  34cat >expected <<\EOF
  35:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M      path1/file1
  36EOF
  37test_expect_success \
  38    'limit to path1 should show path1/file1' \
  39    'git diff-index --cached $tree -- path1 >current &&
  40     compare_diff_raw current expected'
  41
  42cat >expected <<\EOF
  43:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M      path1/file1
  44EOF
  45test_expect_success \
  46    'limit to path1/ should show path1/file1' \
  47    'git diff-index --cached $tree -- path1/ >current &&
  48     compare_diff_raw current expected'
  49
  50cat >expected <<\EOF
  51:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M      path1/file1
  52EOF
  53test_expect_success \
  54    '"*file1" should show path1/file1' \
  55    'git diff-index --cached $tree -- "*file1" >current &&
  56     compare_diff_raw current expected'
  57
  58cat >expected <<\EOF
  59:100644 100644 8e4020bb5a8d8c873b25de15933e75cc0fc275df dca6b92303befc93086aa025d90a5facd7eb2812 M      file0
  60EOF
  61test_expect_success \
  62    'limit to file0 should show file0' \
  63    'git diff-index --cached $tree -- file0 >current &&
  64     compare_diff_raw current expected'
  65
  66cat >expected <<\EOF
  67EOF
  68test_expect_success \
  69    'limit to file0/ should emit nothing.' \
  70    'git diff-index --cached $tree -- file0/ >current &&
  71     compare_diff_raw current expected'
  72
  73test_expect_success 'diff-tree pathspec' '
  74        tree2=$(git write-tree) &&
  75        echo "$tree2" &&
  76        git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
  77        >expected &&
  78        test_cmp expected current
  79'
  80
  81test_expect_success 'diff-tree with wildcard shows dir also matches' '
  82        git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result &&
  83        echo file0 >expected &&
  84        test_cmp expected result
  85'
  86
  87test_expect_success 'diff-tree -r with wildcard' '
  88        git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result &&
  89        echo path1/file1 >expected &&
  90        test_cmp expected result
  91'
  92
  93test_expect_success 'diff-tree with wildcard shows dir also matches' '
  94        git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
  95        echo path1 >expected &&
  96        test_cmp expected result
  97'
  98
  99test_expect_success 'diff-tree -r with wildcard from beginning' '
 100        git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
 101        echo path1/file1 >expected &&
 102        test_cmp expected result
 103'
 104
 105test_expect_success 'diff-tree -r with wildcard' '
 106        git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
 107        echo path1/file1 >expected &&
 108        test_cmp expected result
 109'
 110
 111test_expect_success 'setup submodules' '
 112        test_tick &&
 113        git init submod &&
 114        ( cd submod && test_commit first; ) &&
 115        git add submod &&
 116        git commit -m first &&
 117        ( cd submod && test_commit second; ) &&
 118        git add submod &&
 119        git commit -m second
 120'
 121
 122test_expect_success 'diff-tree ignores trailing slash on submodule path' '
 123        git diff --name-only HEAD^ HEAD submod >expect &&
 124        git diff --name-only HEAD^ HEAD submod/ >actual &&
 125        test_cmp expect actual
 126'
 127
 128test_expect_success 'diff multiple wildcard pathspecs' '
 129        mkdir path2 &&
 130        echo rezrov >path2/file1 &&
 131        git update-index --add path2/file1 &&
 132        tree3=$(git write-tree) &&
 133        git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
 134        cat <<-\EOF >expect &&
 135        path1/file1
 136        path2/file1
 137        EOF
 138        test_cmp expect actual
 139'
 140
 141test_expect_success 'diff-cache ignores trailing slash on submodule path' '
 142        git diff --name-only HEAD^ submod >expect &&
 143        git diff --name-only HEAD^ submod/ >actual &&
 144        test_cmp expect actual
 145'
 146
 147test_done