t4204: patch-id supports various input format
"git patch-id" was first developed to read from "git diff-tree --stdin -p" output. Later it was enhanced to read from "git diff-tree --stdin -p -v", which was the downstream of an early imitation of "git log" ("git rev-list" run in the upstream of a pipe to feed the "diff-tree"). These days, we also read from "git format-patch". Their output begins slightly differently, but the patch-id computed over them for the same commit should be the same. Ensure that we won't accidentally break this expectation. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 29, 2024 at 18:17 UTC
4210ea6f0f2ee95370694e6a3d4fbb8ccf8c4847
1 file changed
+23
t/t4204-patch-id.sh
+23
@@ -114,6 +114,29 @@ test_expect_success 'patch-id supports git-format-patch output' '
114
test "$2" = $(git rev-parse HEAD)
115
'
116
117
+test_expect_success 'patch-id computes the same for various formats' '
118
+ # This test happens to consider "git log -p -1" output
119
+ # the canonical input format, so use it as the norm.
120
+ git log -1 -p same >log-p.output &&
121
+ git patch-id <log-p.output >expect &&
122
+
123
+ # format-patch begins with "From <commit object name>"
124
+ git format-patch -1 --stdout same >format-patch.output &&
125
+ git patch-id <format-patch.output >actual &&
126
+ test_cmp actual expect &&
127
+
128
+ # "diff-tree --stdin -p" begins with "<commit object name>"
129
+ same=$(git rev-parse same) &&
130
+ echo $same | git diff-tree --stdin -p >diff-tree.output &&
131
+ git patch-id <diff-tree.output >actual &&
132
+ test_cmp actual expect &&
133
+
134
+ # "diff-tree --stdin -v -p" begins with "commit <commit object name>"
135
+ echo $same | git diff-tree --stdin -p -v >diff-tree-v.output &&
136
+ git patch-id <diff-tree-v.output >actual &&
137
+ test_cmp actual expect
138
+'
139
+
140
test_expect_success 'whitespace is irrelevant in footer' '
141
get_patch_id main &&
142
git checkout same &&