blob: 6471a68701dd4bc140d43ba91ebb899036ae0d4d [file] [log] [blame]
Jakub Narebskid8faea92010-08-09 10:50:53 -04001#!/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
Junio C Hamanof1e4fb22017-12-09 21:40:13 +010015check_diff () {
16 dir=$1
17 shift
18 expect=$1
19 shift
20 cat >expected <<-EOF
21 diff --git a/$expect b/$expect
22 new file mode 100644
23 index 0000000..25c05ef
24 --- /dev/null
25 +++ b/$expect
26 @@ -0,0 +1 @@
27 +other content
28 EOF
29 test_expect_success "-p $*" "
30 git -C '$dir' diff -p $* HEAD^ >actual &&
31 test_cmp expected actual
32 "
Jakub Narebskid8faea92010-08-09 10:50:53 -040033}
34
Junio C Hamanof1e4fb22017-12-09 21:40:13 +010035check_numstat () {
36 dir=$1
37 shift
38 expect=$1
39 shift
40 cat >expected <<-EOF
41 1 0 $expect
42 EOF
43 test_expect_success "--numstat $*" "
44 echo '1 0 $expect' >expected &&
45 git -C '$dir' diff --numstat $* HEAD^ >actual &&
46 test_cmp expected actual
47 "
Jonathan Nieder6dd88832012-03-13 00:05:54 -050048}
49
Junio C Hamanof1e4fb22017-12-09 21:40:13 +010050check_stat () {
51 dir=$1
52 shift
53 expect=$1
54 shift
55 cat >expected <<-EOF
56 $expect | 1 +
57 1 file changed, 1 insertion(+)
58 EOF
59 test_expect_success "--stat $*" "
60 git -C '$dir' diff --stat $* HEAD^ >actual &&
61 test_i18ncmp expected actual
62 "
Jakub Narebskid8faea92010-08-09 10:50:53 -040063}
64
Junio C Hamanof1e4fb22017-12-09 21:40:13 +010065check_raw () {
66 dir=$1
67 shift
68 expect=$1
69 shift
70 cat >expected <<-EOF
71 :000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A $expect
72 EOF
73 test_expect_success "--raw $*" "
74 git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&
75 test_cmp expected actual
76 "
Jakub Narebskid8faea92010-08-09 10:50:53 -040077}
78
Jacob Keller6d7c17e2017-12-09 21:40:12 +010079for type in diff numstat stat raw
80do
81 check_$type . file2 --relative=subdir/
82 check_$type . file2 --relative=subdir
83 check_$type subdir file2 --relative
84 check_$type . dir/file2 --relative=sub
Jakub Narebskid8faea92010-08-09 10:50:53 -040085done
86
87test_done