| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='support for reading config from a blob' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_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 | |
| 16 | test_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 | |
| 22 | test_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 | |
| 28 | test_expect_success 'reading non-existing value from blob is an error' ' |
| 29 | test_must_fail git config --blob=HEAD:config non.existing |
| 30 | ' |
| 31 | |
| 32 | test_expect_success 'reading from blob and file is an error' ' |
| 33 | test_must_fail git config --blob=HEAD:config --system --list |
| 34 | ' |
| 35 | |
| 36 | test_expect_success 'reading from missing ref is an error' ' |
| 37 | test_must_fail git config --blob=HEAD:doesnotexist --list |
| 38 | ' |
| 39 | |
| 40 | test_expect_success 'reading from non-blob is an error' ' |
| 41 | test_must_fail git config --blob=HEAD --list |
| 42 | ' |
| 43 | |
| 44 | test_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 | |
| 48 | test_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 | |
| 52 | test_expect_success 'editing a blob is an error' ' |
| 53 | test_must_fail git config --blob=HEAD:config --edit |
| 54 | ' |
| 55 | |
| 56 | test_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 | |
| 68 | test_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 | |
| 75 | test_expect_success 'config --blob outside of a repository is an error' ' |
| 76 | nongit test_must_fail git config --blob=foo --list |
| 77 | ' |
| 78 | |
| 79 | test_done |