git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 3/7] read-tree: expand sparse checkout test coverage

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 28, 2022, 23:46 UTC
Message-ID
<220301.86sfs21ri8.gmgdl@evledraar.gmail.com>
In-Reply-To
<509e860c-5bda-b92f-96c5-39f9a54f1e9b@github.com>
On Mon, Feb 28 2022, Victoria Dye wrote:
Show 85 quoted lines
> Ævar Arnfjörð Bjarmason wrote:
>> 
>> On Thu, Feb 24 2022, Victoria Dye via GitGitGadget wrote:
>> 
>>> From: Victoria Dye <vdye@github.com>
>>>
>>> Add tests focused on how 'git read-tree' behaves in sparse checkouts. Extra
>>> emphasis is placed on interactions with files outside the sparse cone, e.g.
>>> merges with out-of-cone conflicts.
>>>
>>> Signed-off-by: Victoria Dye <vdye@github.com>
>>> ---
>>>  t/perf/p2000-sparse-operations.sh        |  1 +
>>>  t/t1092-sparse-checkout-compatibility.sh | 85 ++++++++++++++++++++++++
>>>  2 files changed, 86 insertions(+)
>>>
>>> diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh
>>> index 2a7106b9495..382716cfca9 100755
>>> --- a/t/perf/p2000-sparse-operations.sh
>>> +++ b/t/perf/p2000-sparse-operations.sh
>>> @@ -117,6 +117,7 @@ test_perf_on_all git diff
>>>  test_perf_on_all git diff --cached
>>>  test_perf_on_all git blame $SPARSE_CONE/a
>>>  test_perf_on_all git blame $SPARSE_CONE/f3/a
>>> +test_perf_on_all git read-tree -mu HEAD
>>>  test_perf_on_all git checkout-index -f --all
>>>  test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
>>>  
>>> diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
>>> index b1dcaa0e642..9d58da4e925 100755
>>> --- a/t/t1092-sparse-checkout-compatibility.sh
>>> +++ b/t/t1092-sparse-checkout-compatibility.sh
>>> @@ -819,6 +819,91 @@ test_expect_success 'update-index --cacheinfo' '
>>>  	test_cmp expect sparse-checkout-out
>>>  '
>>>  
>>> +test_expect_success 'read-tree --merge with files outside sparse definition' '
>>> +	init_repos &&
>>> +
>>> +	test_all_match git checkout -b test-branch update-folder1 &&
>>> +	for MERGE_TREES in "base HEAD update-folder2" \
>>> +			   "update-folder1 update-folder2" \
>>> +			   "update-folder2"
>>> +	do
>>> +		# Clean up and remove on-disk files
>>> +		test_all_match git reset --hard HEAD &&
>>> +		test_sparse_match git sparse-checkout reapply &&
>>> +
>>> +		# Although the index matches, without --no-sparse-checkout, outside-of-
>>> +		# definition files will not exist on disk for sparse checkouts
>>> +		test_all_match git read-tree -mu $MERGE_TREES &&
>>> +		test_all_match git status --porcelain=v2 &&
>>> +		test_path_is_missing sparse-checkout/folder2 &&
>>> +		test_path_is_missing sparse-index/folder2 &&
>>> +
>>> +		test_all_match git read-tree --reset -u HEAD &&
>>> +		test_all_match git status --porcelain=v2 &&
>>> +
>>> +		test_all_match git read-tree -mu --no-sparse-checkout $MERGE_TREES &&
>>> +		test_all_match git status --porcelain=v2 &&
>>> +		test_cmp sparse-checkout/folder2/a sparse-index/folder2/a &&
>>> +		test_cmp sparse-checkout/folder2/a full-checkout/folder2/a || return 1
>>> +	done
>>> +'
>> 
>> Nit: Isn't this nicer/easier by unrolling the for-loop to the top-level, i.e.:
>> 
>> for MERGE_TREES in "base HEAD update-folder2" [...]
>> do
>> 	test_expect_success "'read-tree -mu $MERGE_TREES' with files outside sparse definition" '
>> 		init_repos &&
>> 		test_when_finished "test_all_match git reset --hard HEAD" &&
>>                 ...
>> 	'
>> done
>> 
>> It makes failures easier to reason about since you see which for-loop
>> iteration you're in right away, and can e.g. pick one with --run.
>> 
>
> I like how this separates the test cases (while not adding any
> redundant/copied code). I'll update in the next version, thanks!
>
>> And we can do the cleanup in test_when_finished instead of at the start
>> of every loop.
Sounds good!

Note for <reasons> we eval the body of the test into existence, but *not* the description. So:

    for x in [...] test_expect_success "$x" '$x'
Works to expand "$x" in both cases, but not:
    for x in [...] test_expect_success '$x' '$x'
And you don't need to do:
    for x in [...] test_expect_success "$x" "$x"

Which is handy as double-quoting the body is often a hassle with escaping stuff.

I only think I got that wrong the first 1, 2, 3.... etc. times I used this pattern, so I thought I'd mention it :)

> Because `init_repos` completely resets the test repos, this actually lets me
> remove the extra cleanup steps completely.
\o/
Previous: Victoria DyeNext: Victoria Dye via GitGitGadget
Message 30 of 48 in “Sparse index: integrate with 'read-tree'”
  1. 0/7 Sparse index: integrate with 'read-tree'Victoria Dye via GitGitGadget, Feb 23, 2022
  2. 1/7 sparse-index: prevent repo root from becoming sparseVictoria Dye via GitGitGadget, Feb 23, 2022
  3. Derrick StoleeFeb 24, 2022
  4. Victoria DyeFeb 24, 2022
  5. 2/7 status: fix nested sparse directory diff in sparse indexVictoria Dye via GitGitGadget, Feb 23, 2022
  6. 4/7 read-tree: integrate with sparse indexVictoria Dye via GitGitGadget, Feb 23, 2022
  7. 3/7 read-tree: expand sparse checkout test coverageVictoria Dye via GitGitGadget, Feb 23, 2022
  8. 5/7 read-tree: narrow scope of index expansion for '--prefix'Victoria Dye via GitGitGadget, Feb 23, 2022
  9. 6/7 read-tree: make two-way merge sparse-awareVictoria Dye via GitGitGadget, Feb 23, 2022
  10. Elijah NewrenFeb 26, 2022
  11. Victoria DyeFeb 28, 2022
  12. Elijah NewrenMar 1, 2022
  13. 7/7 read-tree: make three-way merge sparse-awareVictoria Dye via GitGitGadget, Feb 23, 2022
  14. Derrick StoleeFeb 24, 2022
  15. 0/7 Sparse index: integrate with 'read-tree'Victoria Dye via GitGitGadget, Feb 24, 2022
  16. 1/7 sparse-index: prevent repo root from becoming sparseVictoria Dye via GitGitGadget, Feb 24, 2022
  17. 2/7 status: fix nested sparse directory diff in sparse indexVictoria Dye via GitGitGadget, Feb 24, 2022
  18. Elijah NewrenFeb 25, 2022
  19. Victoria DyeFeb 28, 2022
  20. 5/7 read-tree: narrow scope of index expansion for '--prefix'Victoria Dye via GitGitGadget, Feb 24, 2022
  21. Elijah NewrenFeb 25, 2022
  22. Victoria DyeFeb 25, 2022
  23. Elijah NewrenFeb 26, 2022
  24. Victoria DyeFeb 28, 2022
  25. 3/7 read-tree: expand sparse checkout test coverageVictoria Dye via GitGitGadget, Feb 24, 2022
  26. Elijah NewrenFeb 26, 2022
  27. Victoria DyeFeb 28, 2022
  28. Ævar Arnfjörð BjarmasonFeb 28, 2022
  29. Victoria DyeFeb 28, 2022
  30. Ævar Arnfjörð BjarmasonFeb 28, 2022
  31. 7/7 read-tree: make three-way merge sparse-awareVictoria Dye via GitGitGadget, Feb 24, 2022
  32. 4/7 read-tree: integrate with sparse indexVictoria Dye via GitGitGadget, Feb 24, 2022
  33. 6/7 read-tree: make two-way merge sparse-awareVictoria Dye via GitGitGadget, Feb 24, 2022
  34. Elijah NewrenFeb 26, 2022
  35. 0/8 Sparse index: integrate with 'read-tree'Victoria Dye via GitGitGadget, Mar 1, 2022
  36. 1/8 sparse-index: prevent repo root from becoming sparseVictoria Dye via GitGitGadget, Mar 1, 2022
  37. 2/8 status: fix nested sparse directory diff in sparse indexVictoria Dye via GitGitGadget, Mar 1, 2022
  38. 3/8 read-tree: explicitly disallow prefixes with a leading '/'Victoria Dye via GitGitGadget, Mar 1, 2022
  39. 8/8 read-tree: make three-way merge sparse-awareVictoria Dye via GitGitGadget, Mar 1, 2022
  40. 6/8 read-tree: narrow scope of index expansion for '--prefix'Victoria Dye via GitGitGadget, Mar 1, 2022
  41. Glen ChooMar 3, 2022
  42. Victoria DyeMar 3, 2022
  43. Glen ChooMar 4, 2022
  44. 7/8 read-tree: make two-way merge sparse-awareVictoria Dye via GitGitGadget, Mar 1, 2022
  45. 5/8 read-tree: integrate with sparse indexVictoria Dye via GitGitGadget, Mar 1, 2022
  46. 4/8 read-tree: expand sparse checkout test coverageVictoria Dye via GitGitGadget, Mar 1, 2022
  47. Elijah NewrenMar 2, 2022
  48. Derrick StoleeMar 2, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.