Skip to content

Commit 6d7c17e

Browse files
jacob-kellergitster
authored andcommitted
diff: add tests for --relative without optional prefix value
We already have tests for --relative, but they currently only test when a prefix has been provided. This fails to test the case where --relative by itself should use the current directory as the prefix. Teach the check_$type functions to take a directory argument to indicate which subdirectory to run the git commands in. Add a new test which uses this to test --relative without a prefix value. Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1efad51 commit 6d7c17e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

t/t4045-diff-relative.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ test_expect_success 'setup' '
1313
'
1414

1515
check_diff() {
16+
dir=$1; shift
1617
expect=$1; shift
1718
cat >expected <<EOF
1819
diff --git a/$expect b/$expect
@@ -24,50 +25,55 @@ index 0000000..25c05ef
2425
+other content
2526
EOF
2627
test_expect_success "-p $*" "
27-
git diff -p $* HEAD^ >actual &&
28+
git -C '$dir' diff -p $* HEAD^ >actual &&
2829
test_cmp expected actual
2930
"
3031
}
3132

3233
check_numstat() {
34+
dir=$1; shift
3335
expect=$1; shift
3436
cat >expected <<EOF
3537
1 0 $expect
3638
EOF
3739
test_expect_success "--numstat $*" "
3840
echo '1 0 $expect' >expected &&
39-
git diff --numstat $* HEAD^ >actual &&
41+
git -C '$dir' diff --numstat $* HEAD^ >actual &&
4042
test_cmp expected actual
4143
"
4244
}
4345

4446
check_stat() {
47+
dir=$1; shift
4548
expect=$1; shift
4649
cat >expected <<EOF
4750
$expect | 1 +
4851
1 file changed, 1 insertion(+)
4952
EOF
5053
test_expect_success "--stat $*" "
51-
git diff --stat $* HEAD^ >actual &&
54+
git -C '$dir' diff --stat $* HEAD^ >actual &&
5255
test_i18ncmp expected actual
5356
"
5457
}
5558

5659
check_raw() {
60+
dir=$1; shift
5761
expect=$1; shift
5862
cat >expected <<EOF
5963
:000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A $expect
6064
EOF
6165
test_expect_success "--raw $*" "
62-
git diff --no-abbrev --raw $* HEAD^ >actual &&
66+
git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&
6367
test_cmp expected actual
6468
"
6569
}
6670

67-
for type in diff numstat stat raw; do
68-
check_$type file2 --relative=subdir/
69-
check_$type file2 --relative=subdir
70-
check_$type dir/file2 --relative=sub
71+
for type in diff numstat stat raw
72+
do
73+
check_$type . file2 --relative=subdir/
74+
check_$type . file2 --relative=subdir
75+
check_$type subdir file2 --relative
76+
check_$type . dir/file2 --relative=sub
7177
done
7278

7379
test_done

0 commit comments

Comments
 (0)