3 test_description
='git patch-id'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
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 &&
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 &&
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 | git patch-id >output &&
31 grep "^$OID_REGEX $(git rev-parse HEAD)$" output
34 #calculate patch id. Make sure output is not empty.
39 sed "s/ .*//" >patch-id_
"$patch_name" &&
40 test_line_count
-gt 0 patch-id_
"$patch_name"
44 git log
-p -1 "$@" -O bar-then-foo
--
48 get_top_diff
"$1" | calc_patch_id
"$@"
51 test_expect_success
'patch-id detects equality' '
54 test_cmp patch-id_main patch-id_same
57 test_expect_success
'patch-id detects inequality' '
59 get_patch_id notsame &&
60 ! test_cmp patch-id_main patch-id_notsame
63 test_expect_success
'patch-id supports git-format-patch output' '
66 git format-patch -1 --stdout | calc_patch_id same &&
67 test_cmp patch-id_main patch-id_same &&
68 set $(git format-patch -1 --stdout | git patch-id) &&
69 test "$2" = $(git rev-parse HEAD)
72 test_expect_success
'whitespace is irrelevant in footer' '
75 git format-patch -1 --stdout | sed "s/ \$//" | calc_patch_id same &&
76 test_cmp patch-id_main patch-id_same
81 test "$1" = "relevant"
83 ! test_cmp patch-id_
"$2" patch-id_
"$3"
85 test_cmp patch-id_
"$2" patch-id_
"$3"
89 test_patch_id_file_order
() {
92 name
="order-${1}-$relevant"
94 get_top_diff
"main" | calc_patch_id
"$name" "$@" &&
96 git format-patch
-1 --stdout -O foo-then-bar |
97 calc_patch_id
"ordered-$name" "$@" &&
98 cmp_patch_id
$relevant "$name" "ordered-$name"
102 # combined test for options: add more tests here to make them
103 # run with all options
105 test_patch_id_file_order
"$@"
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
113 test_expect_success
'file order is relevant with --unstable' '
114 test_patch_id_file_order relevant --unstable --unstable
117 #Now test various option combinations.
118 test_expect_success
'default is unstable' '
119 test_patch_id relevant default
122 test_expect_success
'patchid.stable = true is stable' '
123 test_config patchid.stable true &&
124 test_patch_id irrelevant patchid.stable=true
127 test_expect_success
'patchid.stable = false is unstable' '
128 test_config patchid.stable false &&
129 test_patch_id relevant patchid.stable=false
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
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
142 test_expect_success
'patch-id supports git-format-patch MIME output' '
145 git format-patch -1 --attach --stdout | calc_patch_id same &&
146 test_cmp patch-id_main patch-id_same
149 test_expect_success
'patch-id respects config from subdir' '
150 test_config patchid.stable true &&
153 # copy these because test_patch_id() looks for them in
154 # the current directory
155 cp bar-then-foo foo-then-bar subdir &&
159 test_patch_id irrelevant patchid.stable=true
165 index e69de29.
.2e65efe
100644
170 \ No newline
at end of
file
172 index e69de29.
.6178079 100644
181 index e69de29.
.7898192 100644
187 index e69de29.
.6178079 100644
194 test_expect_success
'patch-id handles no-nl-at-eof markers' '
195 cat nonl | calc_patch_id nonl &&
196 cat withnl | calc_patch_id withnl &&
197 test_cmp patch-id_nonl patch-id_withnl