Heiko Voigt | 1bc8881 | 2013-07-12 00:46:47 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='support for reading config from a blob' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | test_expect_success 'create config blob' ' |
| 7 | cat >config <<-\EOF && |
| 8 | [some] |
| 9 | value = 1 |
| 10 | EOF |
| 11 | git add config && |
| 12 | git commit -m foo |
| 13 | ' |
| 14 | |
| 15 | test_expect_success 'list config blob contents' ' |
| 16 | echo some.value=1 >expect && |
| 17 | git config --blob=HEAD:config --list >actual && |
| 18 | test_cmp expect actual |
| 19 | ' |
| 20 | |
| 21 | test_expect_success 'fetch value from blob' ' |
| 22 | echo true >expect && |
| 23 | git config --blob=HEAD:config --bool some.value >actual && |
| 24 | test_cmp expect actual |
| 25 | ' |
| 26 | |
| 27 | test_expect_success 'reading non-existing value from blob is an error' ' |
| 28 | test_must_fail git config --blob=HEAD:config non.existing |
| 29 | ' |
| 30 | |
| 31 | test_expect_success 'reading from blob and file is an error' ' |
| 32 | test_must_fail git config --blob=HEAD:config --system --list |
| 33 | ' |
| 34 | |
| 35 | test_expect_success 'reading from missing ref is an error' ' |
| 36 | test_must_fail git config --blob=HEAD:doesnotexist --list |
| 37 | ' |
| 38 | |
| 39 | test_expect_success 'reading from non-blob is an error' ' |
| 40 | test_must_fail git config --blob=HEAD --list |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'setting a value in a blob is an error' ' |
| 44 | test_must_fail git config --blob=HEAD:config some.value foo |
| 45 | ' |
| 46 | |
| 47 | test_expect_success 'deleting a value in a blob is an error' ' |
| 48 | test_must_fail git config --blob=HEAD:config --unset some.value |
| 49 | ' |
| 50 | |
| 51 | test_expect_success 'editing a blob is an error' ' |
| 52 | test_must_fail git config --blob=HEAD:config --edit |
| 53 | ' |
| 54 | |
| 55 | test_expect_success 'parse errors in blobs are properly attributed' ' |
| 56 | cat >config <<-\EOF && |
| 57 | [some] |
| 58 | value = " |
| 59 | EOF |
| 60 | git add config && |
| 61 | git commit -m broken && |
| 62 | |
| 63 | test_must_fail git config --blob=HEAD:config some.value 2>err && |
Vasco Almeida | 1edbaac | 2016-06-17 20:21:07 +0000 | [diff] [blame] | 64 | test_i18ngrep "HEAD:config" err |
Heiko Voigt | 1bc8881 | 2013-07-12 00:46:47 +0200 | [diff] [blame] | 65 | ' |
| 66 | |
Jeff King | 5e0be13 | 2015-02-05 01:53:28 -0500 | [diff] [blame] | 67 | test_expect_success 'can parse blob ending with CR' ' |
| 68 | printf "[some]key = value\\r" >config && |
| 69 | git add config && |
| 70 | git commit -m CR && |
| 71 | echo value >expect && |
| 72 | git config --blob=HEAD:config some.key >actual && |
| 73 | test_cmp expect actual |
| 74 | ' |
| 75 | |
Jeff King | 17b8a2d | 2018-05-18 15:27:04 -0700 | [diff] [blame] | 76 | test_expect_success 'config --blob outside of a repository is an error' ' |
Denton Liu | 9b92070 | 2019-12-20 10:15:56 -0800 | [diff] [blame] | 77 | nongit test_must_fail git config --blob=foo --list |
Jeff King | 17b8a2d | 2018-05-18 15:27:04 -0700 | [diff] [blame] | 78 | ' |
| 79 | |
Heiko Voigt | 1bc8881 | 2013-07-12 00:46:47 +0200 | [diff] [blame] | 80 | test_done |