Skip to content

Commit 4210ea6

Browse files
committed
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 <[email protected]>
1 parent 786a3e4 commit 4210ea6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

t/t4204-patch-id.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,29 @@ test_expect_success 'patch-id supports git-format-patch output' '
114114
test "$2" = $(git rev-parse HEAD)
115115
'
116116

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+
117140
test_expect_success 'whitespace is irrelevant in footer' '
118141
get_patch_id main &&
119142
git checkout same &&

0 commit comments

Comments
 (0)