Skip to content

Commit 21e2edd

Browse files
committed
t1092: add tests for config --blob with sparse index
Verify that `git config --blob :path` does not expand the sparse index when the path is in-cone, and does expand when the path is behind a sparse directory entry. Uses valid config blobs (staged via git add) for the in-cone cases to verify end-to-end correctness including config value parsing. Add a separate test verifying that `git config --file` does not trigger sparse index expansion, since it does not access the index at all. Signed-off-by: Kristofer Karlsson <krka@spotify.com>
1 parent 7f3f0ac commit 21e2edd

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,4 +2573,67 @@ test_expect_success 'sparse-index is not expanded: merge-ours' '
25732573
ensure_not_expanded merge -s ours merge-right
25742574
'
25752575

2576+
test_expect_success 'sparse-index is not expanded: config --blob with index path' '
2577+
init_repos &&
2578+
2579+
# Stage valid config blobs at in-cone locations.
2580+
for repo in full-checkout sparse-checkout sparse-index
2581+
do
2582+
test_write_lines "[test]" "value = root" \
2583+
>"$repo/test-config" &&
2584+
git -C "$repo" add test-config &&
2585+
test_write_lines "[test]" "value = deep" \
2586+
>"$repo/deep/test-config" &&
2587+
git -C "$repo" add deep/test-config || return 1
2588+
done &&
2589+
2590+
# Nonexistent file: must not expand.
2591+
rm -f trace2.txt &&
2592+
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
2593+
test_must_fail \
2594+
git -C sparse-index config --blob ":.lfsconfig" -l &&
2595+
test_region ! index ensure_full_index trace2.txt &&
2596+
2597+
# Root-level file (always in-cone): must not expand, and must
2598+
# successfully parse the config values.
2599+
rm -f trace2.txt &&
2600+
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
2601+
git -C sparse-index config --blob ":test-config" -l >actual &&
2602+
echo "test.value=root" >expect &&
2603+
test_cmp expect actual &&
2604+
test_region ! index ensure_full_index trace2.txt &&
2605+
2606+
# File inside sparse cone (deep/): must not expand.
2607+
rm -f trace2.txt &&
2608+
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
2609+
git -C sparse-index config --blob ":deep/test-config" -l >actual &&
2610+
echo "test.value=deep" >expect &&
2611+
test_cmp expect actual &&
2612+
test_region ! index ensure_full_index trace2.txt &&
2613+
2614+
# File outside sparse cone (folder1/a): must expand because
2615+
# it is behind a sparse directory entry. The blob contains
2616+
# "a\n" from the initial setup, which git config parses as
2617+
# a valueless key.
2618+
rm -f trace2.txt &&
2619+
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
2620+
git -C sparse-index config --blob ":folder1/a" -l &&
2621+
test_region index ensure_full_index trace2.txt
2622+
'
2623+
2624+
test_expect_success 'config --file and --blob do not expand sparse index' '
2625+
init_repos &&
2626+
2627+
test_write_lines "[test]" "value = external" >external-config &&
2628+
2629+
# --file reads an external config file; the sparse index
2630+
# should not be read or expanded.
2631+
rm -f trace2.txt &&
2632+
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
2633+
git -C sparse-index config --file ../external-config -l >actual &&
2634+
echo "test.value=external" >expect &&
2635+
test_cmp expect actual &&
2636+
test_region ! index ensure_full_index trace2.txt
2637+
'
2638+
25762639
test_done

0 commit comments

Comments
 (0)