3 test_description
='git patch-id'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'setup' '
12 as="a a a a a a a a" && # eight a
13 test_write_lines $as >foo &&
14 test_write_lines $as >bar &&
16 git commit -a -m initial &&
17 test_write_lines $as b >foo &&
18 test_write_lines $as b >bar &&
19 git commit -a -m first &&
20 git checkout -b same main &&
21 git commit --amend -m same-msg &&
22 git checkout -b notsame main &&
25 git commit --amend -a -m notsame-msg &&
26 test_write_lines bar foo >bar-then-foo &&
27 test_write_lines foo bar >foo-then-bar
30 test_expect_success
'patch-id output is well-formed' '
31 git log -p -1 | git patch-id >output &&
32 grep "^$OID_REGEX $(git rev-parse HEAD)$" output
35 #calculate patch id. Make sure output is not empty.
40 sed "s/ .*//" >patch-id_
"$patch_name" &&
41 test_line_count
-gt 0 patch-id_
"$patch_name"
45 git log
-p -1 "$@" -O bar-then-foo
--
49 get_top_diff
"$1" | calc_patch_id
"$@"
52 test_expect_success
'patch-id detects equality' '
55 test_cmp patch-id_main patch-id_same
58 test_expect_success
'patch-id detects inequality' '
60 get_patch_id notsame &&
61 ! test_cmp patch-id_main patch-id_notsame
64 test_expect_success
'patch-id supports git-format-patch output' '
67 git format-patch -1 --stdout | calc_patch_id same &&
68 test_cmp patch-id_main patch-id_same &&
69 set $(git format-patch -1 --stdout | git patch-id) &&
70 test "$2" = $(git rev-parse HEAD)
73 test_expect_success
'whitespace is irrelevant in footer' '
76 git format-patch -1 --stdout | sed "s/ \$//" | calc_patch_id same &&
77 test_cmp patch-id_main patch-id_same
82 test "$1" = "relevant"
84 ! test_cmp patch-id_
"$2" patch-id_
"$3"
86 test_cmp patch-id_
"$2" patch-id_
"$3"
90 test_patch_id_file_order
() {
93 name
="order-${1}-$relevant"
95 get_top_diff
"main" | calc_patch_id
"$name" "$@" &&
97 git format-patch
-1 --stdout -O foo-then-bar |
98 calc_patch_id
"ordered-$name" "$@" &&
99 cmp_patch_id
$relevant "$name" "ordered-$name"
103 # combined test for options: add more tests here to make them
104 # run with all options
106 test_patch_id_file_order
"$@"
109 # small tests with detailed diagnostic for basic options.
110 test_expect_success
'file order is irrelevant with --stable' '
111 test_patch_id_file_order irrelevant --stable --stable
114 test_expect_success
'file order is relevant with --unstable' '
115 test_patch_id_file_order relevant --unstable --unstable
118 #Now test various option combinations.
119 test_expect_success
'default is unstable' '
120 test_patch_id relevant default
123 test_expect_success
'patchid.stable = true is stable' '
124 test_config patchid.stable true &&
125 test_patch_id irrelevant patchid.stable=true
128 test_expect_success
'patchid.stable = false is unstable' '
129 test_config patchid.stable false &&
130 test_patch_id relevant patchid.stable=false
133 test_expect_success
'--unstable overrides patchid.stable = true' '
134 test_config patchid.stable true &&
135 test_patch_id relevant patchid.stable=true--unstable --unstable
138 test_expect_success
'--stable overrides patchid.stable = false' '
139 test_config patchid.stable false &&
140 test_patch_id irrelevant patchid.stable=false--stable --stable
143 test_expect_success
'patch-id supports git-format-patch MIME output' '
146 git format-patch -1 --attach --stdout | calc_patch_id same &&
147 test_cmp patch-id_main patch-id_same
150 test_expect_success
'patch-id respects config from subdir' '
151 test_config patchid.stable true &&
154 # copy these because test_patch_id() looks for them in
155 # the current directory
156 cp bar-then-foo foo-then-bar subdir &&
160 test_patch_id irrelevant patchid.stable=true
166 index e69de29.
.2e65efe
100644
171 \ No newline
at end of
file
173 index e69de29.
.6178079 100644
182 index e69de29.
.7898192 100644
188 index e69de29.
.6178079 100644
195 test_expect_success
'patch-id handles no-nl-at-eof markers' '
196 cat nonl | calc_patch_id nonl &&
197 cat withnl | calc_patch_id withnl &&
198 test_cmp patch-id_nonl patch-id_withnl