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 >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.
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"
45 git log
-p -1 "$@" -O bar-then-foo
--
49 get_top_diff
"$1" >top-diff.output
&&
50 calc_patch_id
<top-diff.output
"$@"
53 test_expect_success
'patch-id detects equality' '
56 test_cmp patch-id_main patch-id_same
59 test_expect_success
'patch-id detects inequality' '
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' '
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' '
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
85 test "$1" = "relevant"
87 ! test_cmp patch-id_
"$2" patch-id_
"$3"
89 test_cmp patch-id_
"$2" patch-id_
"$3"
93 test_patch_id_file_order
() {
96 name
="order-${1}-$relevant"
98 get_top_diff
"main" >top-diff.output
&&
99 calc_patch_id
<top-diff.output
"$name" "$@" &&
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
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' '
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 &&
159 # copy these because test_patch_id() looks for them in
160 # the current directory
161 cp bar-then-foo foo-then-bar subdir &&
165 test_patch_id irrelevant patchid.stable=true
169 test_expect_success
'patch-id handles no-nl-at-eof markers' '
172 index e69de29..2e65efe 100644
177 \ No newline at end of file
179 index e69de29..6178079 100644
185 cat >withnl <<-\EOF &&
187 index e69de29..7898192 100644
193 index e69de29..6178079 100644
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
213 diff --git a/car b/car
214 index 00750ed..2ae5e34 100644
220 diff --git a/foo b/foo
221 index e439850..7146eb8 100644
228 calc_patch_id diffu1 <diffu1 &&
229 test_config patchid.stable true &&
230 calc_patch_id diffu1stable <diffu1