list-objects-filter: don't memset after releasing filter struct
[git/debian.git] / t / t4204-patch-id.sh
bloba730c0db9856c1d92ba840ca07f4c67064d437a1
1 #!/bin/sh
3 test_description='git patch-id'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 test_expect_success 'setup' '
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 main &&
20 git commit --amend -m same-msg &&
21 git checkout -b notsame main &&
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
29 test_expect_success 'patch-id output is well-formed' '
30 git log -p -1 >log.output &&
31 git patch-id <log.output >output &&
32 grep "^$OID_REGEX $(git rev-parse HEAD)$" output
35 #calculate patch id. Make sure output is not empty.
36 calc_patch_id () {
37 patch_name="$1"
38 shift
39 git patch-id "$@" >patch-id.output &&
40 sed "s/ .*//" patch-id.output >patch-id_"$patch_name" &&
41 test_line_count -eq 1 patch-id_"$patch_name"
44 get_top_diff () {
45 git log -p -1 "$@" -O bar-then-foo --
48 get_patch_id () {
49 get_top_diff "$1" >top-diff.output &&
50 calc_patch_id <top-diff.output "$@"
53 test_expect_success 'patch-id detects equality' '
54 get_patch_id main &&
55 get_patch_id same &&
56 test_cmp patch-id_main patch-id_same
59 test_expect_success 'patch-id detects inequality' '
60 get_patch_id main &&
61 get_patch_id notsame &&
62 ! test_cmp patch-id_main patch-id_notsame
65 test_expect_success 'patch-id supports git-format-patch output' '
66 get_patch_id main &&
67 git checkout same &&
68 git format-patch -1 --stdout >format-patch.output &&
69 calc_patch_id same <format-patch.output &&
70 test_cmp patch-id_main patch-id_same &&
71 set $(git patch-id <format-patch.output) &&
72 test "$2" = $(git rev-parse HEAD)
75 test_expect_success 'whitespace is irrelevant in footer' '
76 get_patch_id main &&
77 git checkout same &&
78 git format-patch -1 --stdout >format-patch.output &&
79 sed "s/ \$//" format-patch.output | calc_patch_id same &&
80 test_cmp patch-id_main patch-id_same
83 cmp_patch_id () {
85 test "$1" = "relevant"
86 then
87 ! test_cmp patch-id_"$2" patch-id_"$3"
88 else
89 test_cmp patch-id_"$2" patch-id_"$3"
93 test_patch_id_file_order () {
94 relevant="$1"
95 shift
96 name="order-${1}-$relevant"
97 shift
98 get_top_diff "main" >top-diff.output &&
99 calc_patch_id <top-diff.output "$name" "$@" &&
100 git checkout same &&
101 git format-patch -1 --stdout -O foo-then-bar >format-patch.output &&
102 calc_patch_id <format-patch.output "ordered-$name" "$@" &&
103 cmp_patch_id $relevant "$name" "ordered-$name"
107 # combined test for options: add more tests here to make them
108 # run with all options
109 test_patch_id () {
110 test_patch_id_file_order "$@"
113 # small tests with detailed diagnostic for basic options.
114 test_expect_success 'file order is irrelevant with --stable' '
115 test_patch_id_file_order irrelevant --stable --stable
118 test_expect_success 'file order is relevant with --unstable' '
119 test_patch_id_file_order relevant --unstable --unstable
122 #Now test various option combinations.
123 test_expect_success 'default is unstable' '
124 test_patch_id relevant default
127 test_expect_success 'patchid.stable = true is stable' '
128 test_config patchid.stable true &&
129 test_patch_id irrelevant patchid.stable=true
132 test_expect_success 'patchid.stable = false is unstable' '
133 test_config patchid.stable false &&
134 test_patch_id relevant patchid.stable=false
137 test_expect_success '--unstable overrides patchid.stable = true' '
138 test_config patchid.stable true &&
139 test_patch_id relevant patchid.stable=true--unstable --unstable
142 test_expect_success '--stable overrides patchid.stable = false' '
143 test_config patchid.stable false &&
144 test_patch_id irrelevant patchid.stable=false--stable --stable
147 test_expect_success 'patch-id supports git-format-patch MIME output' '
148 get_patch_id main &&
149 git checkout same &&
150 git format-patch -1 --attach --stdout >format-patch.output &&
151 calc_patch_id <format-patch.output same &&
152 test_cmp patch-id_main patch-id_same
155 test_expect_success 'patch-id respects config from subdir' '
156 test_config patchid.stable true &&
157 mkdir subdir &&
159 # copy these because test_patch_id() looks for them in
160 # the current directory
161 cp bar-then-foo foo-then-bar subdir &&
164 cd subdir &&
165 test_patch_id irrelevant patchid.stable=true
169 test_expect_success 'patch-id handles no-nl-at-eof markers' '
170 cat >nonl <<-\EOF &&
171 diff --git i/a w/a
172 index e69de29..2e65efe 100644
173 --- i/a
174 +++ w/a
175 @@ -0,0 +1 @@
177 \ No newline at end of file
178 diff --git i/b w/b
179 index e69de29..6178079 100644
180 --- i/b
181 +++ w/b
182 @@ -0,0 +1 @@
185 cat >withnl <<-\EOF &&
186 diff --git i/a w/a
187 index e69de29..7898192 100644
188 --- i/a
189 +++ w/a
190 @@ -0,0 +1 @@
192 diff --git i/b w/b
193 index e69de29..6178079 100644
194 --- i/b
195 +++ w/b
196 @@ -0,0 +1 @@
199 calc_patch_id nonl <nonl &&
200 calc_patch_id withnl <withnl &&
201 test_cmp patch-id_nonl patch-id_withnl
204 test_expect_success 'patch-id handles diffs with one line of before/after' '
205 cat >diffu1 <<-\EOF &&
206 diff --git a/bar b/bar
207 index bdaf90f..31051f6 100644
208 --- a/bar
209 +++ b/bar
210 @@ -2 +2,2 @@
213 diff --git a/car b/car
214 index 00750ed..2ae5e34 100644
215 --- a/car
216 +++ b/car
217 @@ -1 +1,2 @@
220 diff --git a/foo b/foo
221 index e439850..7146eb8 100644
222 --- a/foo
223 +++ b/foo
224 @@ -2 +2,2 @@
228 calc_patch_id diffu1 <diffu1 &&
229 test_config patchid.stable true &&
230 calc_patch_id diffu1stable <diffu1
232 test_done