]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t4204: patch-id supports various input format
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 Jul 2024 01:17:34 +0000 (18:17 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Jul 2024 01:19:14 +0000 (18:19 -0700)
"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>
t/t4204-patch-id.sh

index a7fa94ce0a212e5062a6cc0356261d29af973e32..1627fdda1b266f2218d0f01b8c9c75fbe81389c9 100755 (executable)
@@ -114,6 +114,29 @@ test_expect_success 'patch-id supports git-format-patch output' '
        test "$2" = $(git rev-parse HEAD)
 '
 
+test_expect_success 'patch-id computes the same for various formats' '
+       # This test happens to consider "git log -p -1" output
+       # the canonical input format, so use it as the norm.
+       git log -1 -p same >log-p.output &&
+       git patch-id <log-p.output >expect &&
+
+       # format-patch begins with "From <commit object name>"
+       git format-patch -1 --stdout same >format-patch.output &&
+       git patch-id <format-patch.output >actual &&
+       test_cmp actual expect &&
+
+       # "diff-tree --stdin -p" begins with "<commit object name>"
+       same=$(git rev-parse same) &&
+       echo $same | git diff-tree --stdin -p >diff-tree.output &&
+       git patch-id <diff-tree.output >actual &&
+       test_cmp actual expect &&
+
+       # "diff-tree --stdin -v -p" begins with "commit <commit object name>"
+       echo $same | git diff-tree --stdin -p -v >diff-tree-v.output &&
+       git patch-id <diff-tree-v.output >actual &&
+       test_cmp actual expect
+'
+
 test_expect_success 'whitespace is irrelevant in footer' '
        get_patch_id main &&
        git checkout same &&