]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4045-diff-relative.sh
diff: use skip_to_optional_arg_default() in parsing --relative
[thirdparty/git.git] / t / t4045-diff-relative.sh
CommitLineData
d8faea9d
JN
1#!/bin/sh
2
3test_description='diff --relative tests'
4. ./test-lib.sh
5
6test_expect_success 'setup' '
7 git commit --allow-empty -m empty &&
8 echo content >file1 &&
9 mkdir subdir &&
10 echo other content >subdir/file2 &&
11 git add . &&
12 git commit -m one
13'
14
15check_diff() {
16expect=$1; shift
17cat >expected <<EOF
18diff --git a/$expect b/$expect
19new file mode 100644
20index 0000000..25c05ef
21--- /dev/null
22+++ b/$expect
23@@ -0,0 +1 @@
24+other content
25EOF
26test_expect_success "-p $*" "
27 git diff -p $* HEAD^ >actual &&
28 test_cmp expected actual
29"
30}
31
6dd88832
JN
32check_numstat() {
33expect=$1; shift
34cat >expected <<EOF
351 0 $expect
36EOF
37test_expect_success "--numstat $*" "
38 echo '1 0 $expect' >expected &&
39 git diff --numstat $* HEAD^ >actual &&
40 test_cmp expected actual
41"
42}
43
d8faea9d
JN
44check_stat() {
45expect=$1; shift
46cat >expected <<EOF
dc801e71 47 $expect | 1 +
7f814632 48 1 file changed, 1 insertion(+)
d8faea9d
JN
49EOF
50test_expect_success "--stat $*" "
51 git diff --stat $* HEAD^ >actual &&
6dd88832 52 test_i18ncmp expected actual
d8faea9d
JN
53"
54}
55
56check_raw() {
57expect=$1; shift
58cat >expected <<EOF
59:000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A $expect
60EOF
61test_expect_success "--raw $*" "
62 git diff --no-abbrev --raw $* HEAD^ >actual &&
63 test_cmp expected actual
64"
65}
66
6dd88832 67for type in diff numstat stat raw; do
d8faea9d
JN
68 check_$type file2 --relative=subdir/
69 check_$type file2 --relative=subdir
70 check_$type dir/file2 --relative=sub
71done
72
73test_done