3 test_description
='diff --relative tests'
6 test_expect_success
'setup' '
7 git commit --allow-empty -m empty &&
10 echo other content >subdir/file2 &&
11 blob_file1=$(git hash-object file1) &&
12 blob_file2=$(git hash-object subdir/file2) &&
22 short_blob
=$
(git rev-parse
--short $blob_file2)
24 diff --git a/$expect b/$expect
26 index 0000000..$short_blob
32 test_expect_success
"-p $*" "
33 git -C '$dir' diff -p $* HEAD^ >actual &&
34 test_cmp expected actual
46 test_expect_success
"--numstat $*" "
47 echo '1 0 $expect' >expected &&
48 git -C '$dir' diff --numstat $* HEAD^ >actual &&
49 test_cmp expected actual
60 1 file changed, 1 insertion(+)
62 test_expect_success
"--stat $*" "
63 git -C '$dir' diff --stat $* HEAD^ >actual &&
64 test_cmp expected actual
74 :000000 100644 $ZERO_OID $blob_file2 A $expect
76 test_expect_success
"--raw $*" "
77 git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&
78 test_cmp expected actual
82 for type in diff numstat stat raw
84 check_
$type . file2
--relative=subdir
/
85 check_
$type . file2
--relative=subdir
86 check_
$type subdir file2
--relative
87 check_
$type . dir
/file2
--relative=sub
90 check_diff_relative_option
() {
97 test_expect_success
"config diff.relative $relative_opt -p $*" "
98 short_blob=\$(git rev-parse --short $blob_file2) &&
99 cat >expected <<-EOF &&
100 diff --git a/$expect b/$expect
102 index 0000000..\$short_blob
108 test_config -C $dir diff.relative $relative_opt &&
109 git -C '$dir' diff -p $* HEAD^ >actual &&
110 test_cmp expected actual
114 check_diff_no_relative_option
() {
121 test_expect_success
"config diff.relative $relative_opt -p $*" "
122 short_blob_file1=\$(git rev-parse --short $blob_file1) &&
123 short_blob_file2=\$(git rev-parse --short $blob_file2) &&
124 cat >expected <<-EOF &&
125 diff --git a/file1 b/file1
127 index 0000000..\$short_blob_file1
132 diff --git a/$expect b/$expect
134 index 0000000..\$short_blob_file2
140 test_config -C $dir diff.relative $relative_opt &&
141 git -C '$dir' diff -p $* HEAD^ >actual &&
142 test_cmp expected actual
146 check_diff_no_relative_option . subdir
/file2 false
147 check_diff_no_relative_option . subdir
/file2 true
--no-relative
148 check_diff_no_relative_option . subdir
/file2 false
--no-relative
149 check_diff_no_relative_option subdir subdir
/file2 false
150 check_diff_no_relative_option subdir subdir
/file2 true
--no-relative
151 check_diff_no_relative_option subdir subdir
/file2 false
--no-relative
153 check_diff_relative_option . file2 false
--relative=subdir
/
154 check_diff_relative_option . file2 false
--relative=subdir
155 check_diff_relative_option . file2 true
--relative=subdir
/
156 check_diff_relative_option . file2 true
--relative=subdir
157 check_diff_relative_option subdir file2 false
--relative
158 check_diff_relative_option subdir file2 true
--relative
159 check_diff_relative_option subdir file2 true
160 check_diff_relative_option subdir file2 false
--no-relative --relative
161 check_diff_relative_option subdir file2 true
--no-relative --relative
162 check_diff_relative_option . file2 false
--no-relative --relative=subdir
163 check_diff_relative_option . file2 true
--no-relative --relative=subdir
165 test_expect_success
'setup diff --relative unmerged' '
166 test_commit zero file0 &&
167 test_commit base subdir/file0 &&
169 test_commit one file0 &&
170 test_commit sub1 subdir/file0 &&
171 git switch -c br2 base &&
172 test_commit two file0 &&
174 test_commit sub3 subdir/file0
177 test_expect_success
'diff --relative without change in subdir' '
179 test_when_finished "git merge --abort" &&
180 test_must_fail git merge one &&
181 git -C subdir diff --relative >out &&
182 test_must_be_empty out &&
183 git -C subdir diff --relative --name-only >out &&
184 test_must_be_empty out
187 test_expect_success
'diff --relative --name-only with change in subdir' '
189 test_when_finished "git merge --abort" &&
190 test_must_fail git merge sub1 &&
191 test_write_lines file0 file0 >expected &&
192 git -C subdir diff --relative --name-only >out &&
193 test_cmp expected out
196 test_expect_failure
'diff --relative with change in subdir' '
198 br1_blob=$(git rev-parse --short --verify br1:subdir/file0) &&
199 br3_blob=$(git rev-parse --short --verify br3:subdir/file0) &&
200 test_when_finished "git merge --abort" &&
201 test_must_fail git merge br1 &&
202 cat >expected <<-EOF &&
204 index $br3_blob,$br1_blob..0000000
207 @@@ -1,1 -1,1 +1,5 @@@
214 git -C subdir diff --relative >out &&
215 test_cmp expected out