Merge branch 'maint'
[git/jrn.git] / t / t4010-diff-pathspec.sh
blobfbc8cd8f05f4debeb30b935c1b1db86e94e49f0e
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Pathspec restrictions
8 Prepare:
9 file0
10 path1/file1
12 . ./test-lib.sh
13 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
15 test_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'
27 cat >expected <<\EOF
28 EOF
29 test_expect_success \
30 'limit to path should show nothing' \
31 'git diff-index --cached $tree -- path >current &&
32 compare_diff_raw current expected'
34 cat >expected <<\EOF
35 :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1
36 EOF
37 test_expect_success \
38 'limit to path1 should show path1/file1' \
39 'git diff-index --cached $tree -- path1 >current &&
40 compare_diff_raw current expected'
42 cat >expected <<\EOF
43 :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1
44 EOF
45 test_expect_success \
46 'limit to path1/ should show path1/file1' \
47 'git diff-index --cached $tree -- path1/ >current &&
48 compare_diff_raw current expected'
50 cat >expected <<\EOF
51 :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M file0
52 EOF
53 test_expect_success \
54 'limit to file0 should show file0' \
55 'git diff-index --cached $tree -- file0 >current &&
56 compare_diff_raw current expected'
58 cat >expected <<\EOF
59 EOF
60 test_expect_success \
61 'limit to file0/ should emit nothing.' \
62 'git diff-index --cached $tree -- file0/ >current &&
63 compare_diff_raw current expected'
65 test_expect_success 'diff-tree pathspec' '
66 tree2=$(git write-tree) &&
67 echo "$tree2" &&
68 git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
69 >expected &&
70 test_cmp expected current
73 EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904
75 test_expect_success 'diff-tree with wildcard shows dir also matches' '
76 git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result &&
77 echo file0 >expected &&
78 test_cmp expected result
81 test_expect_success 'diff-tree -r with wildcard' '
82 git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result &&
83 echo path1/file1 >expected &&
84 test_cmp expected result
87 test_expect_success 'diff-tree with wildcard shows dir also matches' '
88 git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
89 echo path1 >expected &&
90 test_cmp expected result
93 test_expect_success 'diff-tree -r with wildcard from beginning' '
94 git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
95 echo path1/file1 >expected &&
96 test_cmp expected result
99 test_expect_success 'diff-tree -r with wildcard' '
100 git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
101 echo path1/file1 >expected &&
102 test_cmp expected result
105 test_done