cat-file tests: test messaging on bad objects/paths

Add tests for the output that's emitted when we disambiguate <obj>:<path> in cat-file. This gives us a baseline for improving these messages. For e.g. "git blame" we'll emit: $ git blame HEAD:foo fatal: no such path 'HEAD:foo' in HEAD But cat-file doesn't disambiguate these two cases, and just gives the rather unhelpful: $ git cat-file --textconv HEAD:foo fatal: Not a valid object name HEAD:foo Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Dec 28, 2021 at 14:28 UTC 68c69f90c8e98b305d9effd1d25f6261a30b8e50
1 file changed +42
t/t8007-cat-file-textconv.sh
+42
@@ -19,6 +19,48 @@ test_expect_success 'setup ' '
19 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
20 '
21
22 +test_expect_success 'usage: <bad rev>' '
23 + cat >expect <<-\EOF &&
24 + fatal: Not a valid object name HEAD2
25 + EOF
26 + test_must_fail git cat-file --textconv HEAD2 2>actual &&
27 + test_cmp expect actual
28 +'
29 +
30 +test_expect_success 'usage: <bad rev>:<bad path>' '
31 + cat >expect <<-\EOF &&
32 + fatal: Not a valid object name HEAD2:two.bin
33 + EOF
34 + test_must_fail git cat-file --textconv HEAD2:two.bin 2>actual &&
35 + test_cmp expect actual
36 +'
37 +
38 +test_expect_success 'usage: <rev>:<bad path>' '
39 + cat >expect <<-\EOF &&
40 + fatal: Not a valid object name HEAD:two.bin
41 + EOF
42 + test_must_fail git cat-file --textconv HEAD:two.bin 2>actual &&
43 + test_cmp expect actual
44 +'
45 +
46 +
47 +test_expect_success 'usage: <rev> with no <path>' '
48 + cat >expect <<-\EOF &&
49 + fatal: git cat-file --textconv HEAD: <object> must be <sha1:path>
50 + EOF
51 + test_must_fail git cat-file --textconv HEAD 2>actual &&
52 + test_cmp expect actual
53 +'
54 +
55 +
56 +test_expect_success 'usage: <bad rev>:<good (in HEAD) path>' '
57 + cat >expect <<-\EOF &&
58 + fatal: Not a valid object name HEAD2:one.bin
59 + EOF
60 + test_must_fail git cat-file --textconv HEAD2:one.bin 2>actual &&
61 + test_cmp expect actual
62 +'
63 +
64 cat >expected <<EOF
65 bin: test version 2
66 EOF