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