Merge branch 'jt/connectivity-check-after-unshallow'
[git] / t / t4045-diff-relative.sh
1 #!/bin/sh
2
3 test_description='diff --relative tests'
4 . ./test-lib.sh
5
6 test_expect_success 'setup' '
7         git commit --allow-empty -m empty &&
8         echo content >file1 &&
9         mkdir subdir &&
10         echo other content >subdir/file2 &&
11         blob=$(git hash-object subdir/file2) &&
12         git add . &&
13         git commit -m one
14 '
15
16 check_diff () {
17         dir=$1
18         shift
19         expect=$1
20         shift
21         short_blob=$(git rev-parse --short $blob)
22         cat >expected <<-EOF
23         diff --git a/$expect b/$expect
24         new file mode 100644
25         index 0000000..$short_blob
26         --- /dev/null
27         +++ b/$expect
28         @@ -0,0 +1 @@
29         +other content
30         EOF
31         test_expect_success "-p $*" "
32                 git -C '$dir' diff -p $* HEAD^ >actual &&
33                 test_cmp expected actual
34         "
35 }
36
37 check_numstat () {
38         dir=$1
39         shift
40         expect=$1
41         shift
42         cat >expected <<-EOF
43         1       0       $expect
44         EOF
45         test_expect_success "--numstat $*" "
46                 echo '1 0       $expect' >expected &&
47                 git -C '$dir' diff --numstat $* HEAD^ >actual &&
48                 test_cmp expected actual
49         "
50 }
51
52 check_stat () {
53         dir=$1
54         shift
55         expect=$1
56         shift
57         cat >expected <<-EOF
58          $expect | 1 +
59          1 file changed, 1 insertion(+)
60         EOF
61         test_expect_success "--stat $*" "
62                 git -C '$dir' diff --stat $* HEAD^ >actual &&
63                 test_i18ncmp expected actual
64         "
65 }
66
67 check_raw () {
68         dir=$1
69         shift
70         expect=$1
71         shift
72         cat >expected <<-EOF
73         :000000 100644 0000000000000000000000000000000000000000 $blob A $expect
74         EOF
75         test_expect_success "--raw $*" "
76                 git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&
77                 test_cmp expected actual
78         "
79 }
80
81 for type in diff numstat stat raw
82 do
83         check_$type . file2 --relative=subdir/
84         check_$type . file2 --relative=subdir
85         check_$type subdir file2 --relative
86         check_$type . dir/file2 --relative=sub
87 done
88
89 test_done