Merge branch 'master' of git://github.com/git-l10n/git-po
[git/raj.git] / t / t4053-diff-no-index.sh
blob6e0dd6f9e5c482631147bb4770498dc4e7a8165f
1 #!/bin/sh
3 test_description='diff --no-index'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 mkdir a &&
9 mkdir b &&
10 echo 1 >a/1 &&
11 echo 2 >a/2 &&
12 git init repo &&
13 echo 1 >repo/a &&
14 mkdir -p non/git &&
15 echo 1 >non/git/a &&
16 echo 1 >non/git/b
19 test_expect_success 'git diff --no-index directories' '
20 test_expect_code 1 git diff --no-index a b >cnt &&
21 test_line_count = 14 cnt
24 test_expect_success 'git diff --no-index relative path outside repo' '
26 cd repo &&
27 test_expect_code 0 git diff --no-index a ../non/git/a &&
28 test_expect_code 0 git diff --no-index ../non/git/a ../non/git/b
32 test_expect_success 'git diff --no-index with broken index' '
34 cd repo &&
35 echo broken >.git/index &&
36 git diff --no-index a ../non/git/a
40 test_expect_success 'git diff outside repo with broken index' '
42 cd repo &&
43 git diff ../non/git/a ../non/git/b
47 test_expect_success 'git diff --no-index executed outside repo gives correct error message' '
49 GIT_CEILING_DIRECTORIES=$TRASH_DIRECTORY/non &&
50 export GIT_CEILING_DIRECTORIES &&
51 cd non/git &&
52 test_must_fail git diff --no-index a 2>actual.err &&
53 echo "usage: git diff --no-index <path> <path>" >expect.err &&
54 test_cmp expect.err actual.err
58 test_expect_success 'diff D F and diff F D' '
60 cd repo &&
61 echo in-repo >a &&
62 echo non-repo >../non/git/a &&
63 mkdir sub &&
64 echo sub-repo >sub/a &&
66 test_must_fail git diff --no-index sub/a ../non/git/a >expect &&
67 test_must_fail git diff --no-index sub/a ../non/git/ >actual &&
68 test_cmp expect actual &&
70 test_must_fail git diff --no-index a ../non/git/a >expect &&
71 test_must_fail git diff --no-index a ../non/git/ >actual &&
72 test_cmp expect actual &&
74 test_must_fail git diff --no-index ../non/git/a a >expect &&
75 test_must_fail git diff --no-index ../non/git a >actual &&
76 test_cmp expect actual
80 test_expect_success 'turning a file into a directory' '
82 cd non/git &&
83 mkdir d e e/sub &&
84 echo 1 >d/sub &&
85 echo 2 >e/sub/file &&
86 printf "D\td/sub\nA\te/sub/file\n" >expect &&
87 test_must_fail git diff --no-index --name-status d e >actual &&
88 test_cmp expect actual
92 test_expect_success 'diff from repo subdir shows real paths (explicit)' '
93 echo "diff --git a/../../non/git/a b/../../non/git/b" >expect &&
94 test_expect_code 1 \
95 git -C repo/sub \
96 diff --no-index ../../non/git/a ../../non/git/b >actual &&
97 head -n 1 <actual >actual.head &&
98 test_cmp expect actual.head
101 test_expect_success 'diff from repo subdir shows real paths (implicit)' '
102 echo "diff --git a/../../non/git/a b/../../non/git/b" >expect &&
103 test_expect_code 1 \
104 git -C repo/sub \
105 diff ../../non/git/a ../../non/git/b >actual &&
106 head -n 1 <actual >actual.head &&
107 test_cmp expect actual.head
110 test_expect_success 'diff --no-index from repo subdir respects config (explicit)' '
111 echo "diff --git ../../non/git/a ../../non/git/b" >expect &&
112 test_config -C repo diff.noprefix true &&
113 test_expect_code 1 \
114 git -C repo/sub \
115 diff --no-index ../../non/git/a ../../non/git/b >actual &&
116 head -n 1 <actual >actual.head &&
117 test_cmp expect actual.head
120 test_expect_success 'diff --no-index from repo subdir respects config (implicit)' '
121 echo "diff --git ../../non/git/a ../../non/git/b" >expect &&
122 test_config -C repo diff.noprefix true &&
123 test_expect_code 1 \
124 git -C repo/sub \
125 diff ../../non/git/a ../../non/git/b >actual &&
126 head -n 1 <actual >actual.head &&
127 test_cmp expect actual.head
130 test_expect_success 'diff --no-index from repo subdir with absolute paths' '
131 cat <<-EOF >expect &&
132 1 1 $(pwd)/non/git/{a => b}
134 test_expect_code 1 \
135 git -C repo/sub diff --numstat \
136 "$(pwd)/non/git/a" "$(pwd)/non/git/b" >actual &&
137 test_cmp expect actual
140 test_done