interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t1307-config-blob.sh

100 lines · 2726 bytes Raw Blame History
1#!/bin/sh
2
3test_description='support for reading config from a blob'
4
5. ./test-lib.sh
6
7test_expect_success 'create config blob' '
8 cat >config <<-\EOF &&
9 [some]
10 value = 1
11 EOF
12 git add config &&
13 git commit -m foo
14'
15
16test_expect_success 'list config blob contents' '
17 echo some.value=1 >expect &&
18 git config --blob=HEAD:config --list >actual &&
19 test_cmp expect actual
20'
21
22test_expect_success 'fetch value from blob' '
23 echo true >expect &&
24 git config --blob=HEAD:config --bool some.value >actual &&
25 test_cmp expect actual
26'
27
28test_expect_success 'reading non-existing value from blob is an error' '
29 test_must_fail git config --blob=HEAD:config non.existing
30'
31
32test_expect_success 'reading from blob and file is an error' '
33 test_must_fail git config --blob=HEAD:config --system --list
34'
35
36test_expect_success 'reading from missing ref is an error' '
37 test_must_fail git config --blob=HEAD:doesnotexist --list
38'
39
40test_expect_success 'reading from non-blob is an error' '
41 test_must_fail git config --blob=HEAD --list
42'
43
44test_expect_success 'setting a value in a blob is an error' '
45 test_must_fail git config --blob=HEAD:config some.value foo
46'
47
48test_expect_success 'deleting a value in a blob is an error' '
49 test_must_fail git config --blob=HEAD:config --unset some.value
50'
51
52test_expect_success 'editing a blob is an error' '
53 test_must_fail git config --blob=HEAD:config --edit
54'
55
56test_expect_success 'parse errors in blobs are properly attributed' '
57 cat >config <<-\EOF &&
58 [some]
59 value = "
60 EOF
61 git add config &&
62 git commit -m broken &&
63
64 test_must_fail git config --blob=HEAD:config some.value 2>err &&
65 test_grep "HEAD:config" err
66'
67
68test_expect_success 'can parse blob ending with CR' '
69 test_commit --printf CR config "[some]key = value\\r" &&
70 echo value >expect &&
71 git config --blob=HEAD:config some.key >actual &&
72 test_cmp expect actual
73'
74
75test_expect_success 'a byte 0xff does not end a blob' '
76 test_commit --printf FF config "# caf\\377\\n[some]\\n\\tkey = value\\n" &&
77 echo value >expect &&
78 git config --blob=HEAD:config some.key >actual &&
79 test_cmp expect actual
80'
81
82test_expect_success 'a byte 0xff after a CR in a blob' '
83 test_commit --printf CRFF config "# a\\r\\377\\n[some]\\n\\tkey = value\\n" &&
84 echo value >expect &&
85 git config --blob=HEAD:config some.key >actual &&
86 test_cmp expect actual
87'
88
89test_expect_success 'can parse blob starting with a byte order mark' '
90 test_commit --printf BOM config "\\357\\273\\277[some]\\n\\tkey = value\\n" &&
91 echo value >expect &&
92 git config --blob=HEAD:config some.key >actual &&
93 test_cmp expect actual
94'
95
96test_expect_success 'config --blob outside of a repository is an error' '
97 nongit test_must_fail git config --blob=foo --list
98'
99
100test_done