]>
Commit | Line | Data |
---|---|---|
d8faea9d JN |
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 && | |
5c024287 | 11 | blob=$(git hash-object subdir/file2) && |
d8faea9d JN |
12 | git add . && |
13 | git commit -m one | |
14 | ' | |
15 | ||
f1e4fb24 JH |
16 | check_diff () { |
17 | dir=$1 | |
18 | shift | |
19 | expect=$1 | |
20 | shift | |
5c024287 | 21 | short_blob=$(git rev-parse --short $blob) |
f1e4fb24 JH |
22 | cat >expected <<-EOF |
23 | diff --git a/$expect b/$expect | |
24 | new file mode 100644 | |
5c024287 | 25 | index 0000000..$short_blob |
f1e4fb24 JH |
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 | " | |
d8faea9d JN |
35 | } |
36 | ||
f1e4fb24 JH |
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 | " | |
6dd88832 JN |
50 | } |
51 | ||
f1e4fb24 JH |
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 | " | |
d8faea9d JN |
65 | } |
66 | ||
f1e4fb24 JH |
67 | check_raw () { |
68 | dir=$1 | |
69 | shift | |
70 | expect=$1 | |
71 | shift | |
72 | cat >expected <<-EOF | |
5c024287 | 73 | :000000 100644 0000000000000000000000000000000000000000 $blob A $expect |
f1e4fb24 JH |
74 | EOF |
75 | test_expect_success "--raw $*" " | |
76 | git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual && | |
77 | test_cmp expected actual | |
78 | " | |
d8faea9d JN |
79 | } |
80 | ||
6d7c17ec JK |
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 | |
d8faea9d JN |
87 | done |
88 | ||
89 | test_done |