]>
Commit | Line | Data |
---|---|---|
b26d8d21 TR |
1 | #!/bin/sh |
2 | ||
3 | test_description='git patch-id' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup' ' | |
8f2514e9 MT |
8 | as="a a a a a a a a" && # eight a |
9 | test_write_lines $as >foo && | |
10 | test_write_lines $as >bar && | |
11 | git add foo bar && | |
12 | git commit -a -m initial && | |
13 | test_write_lines $as b >foo && | |
14 | test_write_lines $as b >bar && | |
15 | git commit -a -m first && | |
16 | git checkout -b same master && | |
17 | git commit --amend -m same-msg && | |
18 | git checkout -b notsame master && | |
19 | echo c >foo && | |
20 | echo c >bar && | |
21 | git commit --amend -a -m notsame-msg && | |
22 | test_write_lines bar foo >bar-then-foo && | |
23 | test_write_lines foo bar >foo-then-bar | |
b26d8d21 TR |
24 | ' |
25 | ||
26 | test_expect_success 'patch-id output is well-formed' ' | |
8f2514e9 | 27 | git log -p -1 | git patch-id >output && |
b26d8d21 TR |
28 | grep "^[a-f0-9]\{40\} $(git rev-parse HEAD)$" output |
29 | ' | |
30 | ||
8f2514e9 | 31 | #calculate patch id. Make sure output is not empty. |
580fb25b | 32 | calc_patch_id () { |
5c639201 | 33 | patch_name="$1" |
8f2514e9 MT |
34 | shift |
35 | git patch-id "$@" | | |
5c639201 JH |
36 | sed "s/ .*//" >patch-id_"$patch_name" && |
37 | test_line_count -gt 0 patch-id_"$patch_name" | |
8f2514e9 MT |
38 | } |
39 | ||
40 | get_top_diff () { | |
41 | git log -p -1 "$@" -O bar-then-foo -- | |
580fb25b PB |
42 | } |
43 | ||
b26d8d21 | 44 | get_patch_id () { |
8f2514e9 | 45 | get_top_diff "$1" | calc_patch_id "$@" |
b26d8d21 TR |
46 | } |
47 | ||
48 | test_expect_success 'patch-id detects equality' ' | |
49 | get_patch_id master && | |
50 | get_patch_id same && | |
51 | test_cmp patch-id_master patch-id_same | |
52 | ' | |
53 | ||
54 | test_expect_success 'patch-id detects inequality' ' | |
55 | get_patch_id master && | |
56 | get_patch_id notsame && | |
57 | ! test_cmp patch-id_master patch-id_notsame | |
58 | ' | |
59 | ||
580fb25b PB |
60 | test_expect_success 'patch-id supports git-format-patch output' ' |
61 | get_patch_id master && | |
62 | git checkout same && | |
63 | git format-patch -1 --stdout | calc_patch_id same && | |
64 | test_cmp patch-id_master patch-id_same && | |
ce21ccfa EP |
65 | set $(git format-patch -1 --stdout | git patch-id) && |
66 | test "$2" = $(git rev-parse HEAD) | |
580fb25b PB |
67 | ' |
68 | ||
69 | test_expect_success 'whitespace is irrelevant in footer' ' | |
70 | get_patch_id master && | |
71 | git checkout same && | |
72 | git format-patch -1 --stdout | sed "s/ \$//" | calc_patch_id same && | |
73 | test_cmp patch-id_master patch-id_same | |
74 | ' | |
75 | ||
8f2514e9 MT |
76 | cmp_patch_id () { |
77 | if | |
78 | test "$1" = "relevant" | |
79 | then | |
80 | ! test_cmp patch-id_"$2" patch-id_"$3" | |
81 | else | |
82 | test_cmp patch-id_"$2" patch-id_"$3" | |
83 | fi | |
84 | } | |
85 | ||
86 | test_patch_id_file_order () { | |
87 | relevant="$1" | |
88 | shift | |
89 | name="order-${1}-$relevant" | |
90 | shift | |
91 | get_top_diff "master" | calc_patch_id "$name" "$@" && | |
92 | git checkout same && | |
93 | git format-patch -1 --stdout -O foo-then-bar | | |
94 | calc_patch_id "ordered-$name" "$@" && | |
95 | cmp_patch_id $relevant "$name" "ordered-$name" | |
96 | ||
97 | } | |
98 | ||
99 | # combined test for options: add more tests here to make them | |
100 | # run with all options | |
101 | test_patch_id () { | |
102 | test_patch_id_file_order "$@" | |
103 | } | |
104 | ||
105 | # small tests with detailed diagnostic for basic options. | |
106 | test_expect_success 'file order is irrelevant with --stable' ' | |
107 | test_patch_id_file_order irrelevant --stable --stable | |
108 | ' | |
109 | ||
110 | test_expect_success 'file order is relevant with --unstable' ' | |
111 | test_patch_id_file_order relevant --unstable --unstable | |
112 | ' | |
113 | ||
114 | #Now test various option combinations. | |
115 | test_expect_success 'default is unstable' ' | |
116 | test_patch_id relevant default | |
117 | ' | |
118 | ||
119 | test_expect_success 'patchid.stable = true is stable' ' | |
120 | test_config patchid.stable true && | |
121 | test_patch_id irrelevant patchid.stable=true | |
122 | ' | |
123 | ||
124 | test_expect_success 'patchid.stable = false is unstable' ' | |
125 | test_config patchid.stable false && | |
126 | test_patch_id relevant patchid.stable=false | |
127 | ' | |
128 | ||
129 | test_expect_success '--unstable overrides patchid.stable = true' ' | |
130 | test_config patchid.stable true && | |
131 | test_patch_id relevant patchid.stable=true--unstable --unstable | |
132 | ' | |
133 | ||
134 | test_expect_success '--stable overrides patchid.stable = false' ' | |
135 | test_config patchid.stable false && | |
136 | test_patch_id irrelevant patchid.stable=false--stable --stable | |
137 | ' | |
138 | ||
580fb25b PB |
139 | test_expect_success 'patch-id supports git-format-patch MIME output' ' |
140 | get_patch_id master && | |
141 | git checkout same && | |
142 | git format-patch -1 --attach --stdout | calc_patch_id same && | |
143 | test_cmp patch-id_master patch-id_same | |
144 | ' | |
145 | ||
f2b5e7af MG |
146 | cat >nonl <<\EOF |
147 | diff --git i/a w/a | |
148 | index e69de29..2e65efe 100644 | |
149 | --- i/a | |
150 | +++ w/a | |
151 | @@ -0,0 +1 @@ | |
152 | +a | |
153 | \ No newline at end of file | |
154 | diff --git i/b w/b | |
155 | index e69de29..6178079 100644 | |
156 | --- i/b | |
157 | +++ w/b | |
158 | @@ -0,0 +1 @@ | |
159 | +b | |
160 | EOF | |
161 | ||
162 | cat >withnl <<\EOF | |
163 | diff --git i/a w/a | |
164 | index e69de29..7898192 100644 | |
165 | --- i/a | |
166 | +++ w/a | |
167 | @@ -0,0 +1 @@ | |
168 | +a | |
169 | diff --git i/b w/b | |
170 | index e69de29..6178079 100644 | |
171 | --- i/b | |
172 | +++ w/b | |
173 | @@ -0,0 +1 @@ | |
174 | +b | |
175 | EOF | |
176 | ||
2485eab5 | 177 | test_expect_success 'patch-id handles no-nl-at-eof markers' ' |
f2b5e7af MG |
178 | cat nonl | calc_patch_id nonl && |
179 | cat withnl | calc_patch_id withnl && | |
180 | test_cmp patch-id_nonl patch-id_withnl | |
181 | ' | |
b26d8d21 | 182 | test_done |