]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4010-diff-pathspec.sh
Merge branch 'jk/complete-commit-c' into maint
[thirdparty/git.git] / t / t4010-diff-pathspec.sh
CommitLineData
66204988
JH
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
bfdbee98 13. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
66204988
JH
14
15test_expect_success \
16 setup \
17 'echo frotz >file0 &&
18 mkdir path1 &&
19 echo rezrov >path1/file1 &&
5be60078
JH
20 git update-index --add file0 path1/file1 &&
21 tree=`git write-tree` &&
66204988
JH
22 echo "$tree" &&
23 echo nitfol >file0 &&
24 echo yomin >path1/file1 &&
5be60078 25 git update-index file0 path1/file1'
66204988
JH
26
27cat >expected <<\EOF
28EOF
29test_expect_success \
30 'limit to path should show nothing' \
5be60078 31 'git diff-index --cached $tree -- path >current &&
66204988
JH
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' \
5be60078 39 'git diff-index --cached $tree -- path1 >current &&
66204988
JH
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' \
5be60078 47 'git diff-index --cached $tree -- path1/ >current &&
66204988
JH
48 compare_diff_raw current expected'
49
4838237c
NTND
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
66204988
JH
58cat >expected <<\EOF
59:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M file0
60EOF
61test_expect_success \
62 'limit to file0 should show file0' \
5be60078 63 'git diff-index --cached $tree -- file0 >current &&
66204988
JH
64 compare_diff_raw current expected'
65
66cat >expected <<\EOF
67EOF
68test_expect_success \
69 'limit to file0/ should emit nothing.' \
5be60078 70 'git diff-index --cached $tree -- file0/ >current &&
66204988
JH
71 compare_diff_raw current expected'
72
f0946cb8
BS
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
d38f2809
NTND
81EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904
82
83test_expect_success 'diff-tree with wildcard shows dir also matches' '
84 git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result &&
85 echo file0 >expected &&
86 test_cmp expected result
87'
88
89test_expect_success 'diff-tree -r with wildcard' '
90 git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result &&
91 echo path1/file1 >expected &&
92 test_cmp expected result
93'
94
f1a2ddbb
NTND
95test_expect_success 'diff-tree with wildcard shows dir also matches' '
96 git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
97 echo path1 >expected &&
98 test_cmp expected result
99'
100
101test_expect_success 'diff-tree -r with wildcard from beginning' '
102 git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
103 echo path1/file1 >expected &&
104 test_cmp expected result
105'
106
107test_expect_success 'diff-tree -r with wildcard' '
108 git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
109 echo path1/file1 >expected &&
110 test_cmp expected result
111'
112
66204988 113test_done