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

Re: [PATCH v5 1/2] t1092: add tests for `git diff-files`

From
Shuqi Liang <cheskaqiqi@gmail.com>
Date
Mar 20, 2023, 20:55 UTC
Message-ID
<CAMO4yUFsGQbeu=wbqG8EuptYFDv9c1tB8Y0RAU_UJ-GdbMAfVg@mail.gmail.com>
In-Reply-To
<b537d855-edb7-4f67-de08-d651868247a5@github.com>
On Fri, Mar 10, 2023 at 1:23 PM Victoria Dye <vdye@github.com> wrote:
 Hi Victoria!
Sorry for the late reply! I was having midterm exams.

Thank you for the feedback on the patch . I appreciate your time giving me the advice for improvement.

> > In order to have staged changes outside of
> > the sparse-checkout cone, create a 'newdirectory/testfile' and
> > add it to the index, while leaving it outside of
> > the sparse-checkout definition.Test 'newdirectory/testfile'
> nit: missing space after "definition."
Will do!
Show 5 quoted lines
> I'd be interested in seeing an additional test case for a pathspec with
> wildcards or other "magic" [1], e.g. 'git diff-files "deep/*"'. In past
> sparse index integrations, there has occasionally been a need for special
> handling of those types of pathspecs [2][3], so it would be good for the
> test to cover cases like that.
Will do!
Show 22 quoted lines
> From the comment you've added here, it looks like the state you want to test
> is "file outside sparse checkout definition exists on disk". However, since
> one of the goals of this test is to verify sparse index behavior once its
> integrated with the 'diff-files' command, whether the "outside of sparse-
> checkout definition" file belongs to a sparse directory entry is an
> important (and fairly nuanced) factor to consider.
>
> The main difference between a "regular" sparse-checkout and a sparse
> index-enabled sparse-checkout is the existence of "sparse directory"
> entries: index entries with 'SKIP_WORKTREE' that represent directories and
> their contents. In the context of these tests, the thing we really want to
> verify is that the sparse index-enabled case produces the same results as
> the full index when an operation needs to get some information out of a
> sparse directory.
>
> Coming back to this test, the 'newdirectory/testfile' you create, while
> outside the sparse-checkout definition, never actually belongs to a sparse
> directory because 'newdirectory' is never collapsed - in fact, I don't
> think it even gets the SKIP_WORKTREE bit in the index. To ensure you have a
> sparse directory & SKIP_WORKTREE, you'd need to run 'git sparse-checkout
> reapply' after removing 'newdirectory/testfile' from disk - which doesn't
> help if you want to test what happens when the file exists on disk!
Thanks for the explanation here! I learn a lot.
Show 32 quoted lines
> In fact, because of built-in safeguards around on-disk files and
> sparse-checkout, there isn't really a way in Git to materialize a file
> without also expanding its sparse directory and removing SKIP_WORKTREE. If
> you want to preserve a sparse directory, you should write the contents of an
> existing file inside that sparse directory to disk manually:
>
>         run_on_sparse mkdir folder1 &&
>         run_on_sparse cp a folder1/a &&  # `folder1/a` is identical to `a` in the base commit
>
> Git's index will not be touched by doing this, meaning the next command you
> invoke (in this case, 'diff-files') will need to reconcile the file on disk
> with what it sees in the index.
>
> > +     test_sparse_match git diff-files &&
> > +     test_must_be_empty sparse-checkout-out &&
> > +     test_must_be_empty sparse-checkout-err &&
> > +     test_sparse_match git diff-files newdirectory/testfile &&
> > +     test_must_be_empty sparse-checkout-out &&
> > +     test_must_be_empty sparse-checkout-err &&
>
> These checks should be 'test_all_match' rather than 'test_sparse_match'.
> Since (through other tests) we're confident that 'git diff-files' on an
> unmodified, non-sparse-checkout repository will give us an empty result, you
> wouldn't need the additional 'test_must_be_empty' checks.
>
> A bit of a "spoiler": when I tested this out locally, I found that the diff
> was *not* empty for the sparse-checkout cases, until I ran 'git status'
> (which strips the 'SKIP_WORKTREE' bit from the file and writes it to the
> index). That's not the desired behavior, so there's a bug in the
> sparse-checkout logic used in 'diff-files' that needs to be fixed (my first
> guess would be that 'clear_skip_worktree_from_present_files()' is not being
> applied when the index is read).
Yeah. After I use
 run_on_sparse mkdir folder1 &&
 run_on_sparse cp a folder1/a &&  # `folder1/a` is identical to `a` in
the base commit
 diff was *not* empty for the sparse-checkout cases
 when I look into builtin/diff-files.c
'repo_read_index_preload' call 'repo_read_index' which call
 'clear_skip_worktree_from_present_files()' to apply when the index is read.

I got stuck in here and do not have the idea to investigate it. Any tips would be helpful!

Show 10 quoted lines
> > +     run_on_sparse ../edit-contents newdirectory/testfile &&
> > +     test_sparse_match git diff-files &&
> > +     test_cmp expect sparse-checkout-out &&
> > +     test_sparse_match git diff-files newdirectory/testfile &&
> > +     test_cmp expect sparse-checkout-out
>
> Similarly, you should use 'run_on_all' to modify the file & 'test_all_match'
> to verify that they all match here. It would demonstrate that we don't
> expect any "special" behavior from sparse-checkout, meaning you can probably
> avoid checking the result verbatim.
> Finally, as with the earlier test, it'd be nice to show that the result is
> the same with a wildcard pathspec, e.g. 'git diff-files "folder*/a"'.

Will do! ---------------------------------------------------------------------------- Thanks Shuqi

Previous: Victoria DyeNext: Shuqi Liang
Message 22 of 73 in “t1092: add tests for `git diff-files`”
  1. Shuqi LiangMar 4, 2023
  2. Derrick StoleeMar 6, 2023
  3. 0/2 diff-files: integrate with sparse indexShuqi Liang, Mar 7, 2023
  4. 2/2 diff-files: integrate with sparse indexShuqi Liang, Mar 7, 2023
  5. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, Mar 7, 2023
  6. Junio C HamanoMar 7, 2023
  7. Shuqi LiangMar 8, 2023
  8. Junio C HamanoMar 8, 2023
  9. 0/2 diff-files: integrate with sparse indexShuqi Liang, Mar 9, 2023
  10. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, Mar 9, 2023
  11. Junio C HamanoMar 9, 2023
  12. 2/2 diff-files: integrate with sparse indexShuqi Liang, Mar 9, 2023
  13. 0/2 diff-files: integrate with sparse indexShuqi Liang, Mar 9, 2023
  14. 2/2 diff-files: integrate with sparse indexShuqi Liang, Mar 9, 2023
  15. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, Mar 9, 2023
  16. Junio C HamanoMar 9, 2023
  17. Shuqi LiangMar 9, 2023
  18. Junio C HamanoMar 9, 2023
  19. 0/2 diff-files: integrate with sparse indexShuqi Liang, Mar 10, 2023
  20. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, Mar 10, 2023
  21. Victoria DyeMar 10, 2023
  22. Shuqi LiangMar 20, 2023
  23. 2/2 diff-files: integrate with sparse indexShuqi Liang, Mar 10, 2023
  24. Victoria DyeMar 10, 2023
  25. 0/2 diff-files: integrate with sparse indexShuqi Liang, Mar 20, 2023
  26. 2/2 diff-files: integrate with sparse indexShuqi Liang, Mar 20, 2023
  27. Victoria DyeMar 21, 2023
  28. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, Mar 20, 2023
  29. Victoria DyeMar 21, 2023
  30. Junio C HamanoMar 21, 2023
  31. Victoria DyeMar 21, 2023
  32. Victoria DyeMar 21, 2023
  33. 0/2 diff-files: integrate with sparse indexShuqi Liang, Mar 22, 2023
  34. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, Mar 22, 2023
  35. Victoria DyeApr 13, 2023
  36. 2/2 diff-files: integrate with sparse indexShuqi Liang, Mar 22, 2023
  37. Victoria DyeApr 13, 2023
  38. Shuqi LiangApr 20, 2023
  39. Victoria DyeApr 20, 2023
  40. Shuqi LiangApr 21, 2023
  41. Victoria DyeApr 21, 2023
  42. Shuqi LiangApr 22, 2023
  43. Junio C HamanoMar 22, 2023
  44. Shuqi LiangMar 23, 2023
  45. Junio C HamanoMar 23, 2023
  46. Shuqi LiangMar 23, 2023
  47. Victoria DyeMar 23, 2023
  48. Junio C HamanoApr 13, 2023
  49. Victoria DyeApr 13, 2023
  50. 0/2 diff-files: integrate with sparse indexShuqi Liang, Apr 23, 2023
  51. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, Apr 23, 2023
  52. 2/2 diff-files: integrate with sparse indexShuqi Liang, Apr 23, 2023
  53. Victoria DyeMay 1, 2023
  54. Junio C HamanoApr 25, 2023
  55. Junio C HamanoMay 1, 2023
  56. 0/2 diff-files: integrate with sparse indexShuqi Liang, May 2, 2023
  57. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, May 2, 2023
  58. Junio C HamanoMay 2, 2023
  59. Victoria DyeMay 3, 2023
  60. 2/2 diff-files: integrate with sparse indexShuqi Liang, May 2, 2023
  61. 0/2 diff-files: integrate with sparse indexShuqi Liang, May 3, 2023
  62. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, May 3, 2023
  63. Junio C HamanoMay 3, 2023
  64. 2/2 diff-files: integrate with sparse indexShuqi Liang, May 3, 2023
  65. 0/2 diff-files: integrate with sparse indexShuqi Liang, May 8, 2023
  66. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, May 8, 2023
  67. Victoria DyeMay 8, 2023
  68. 2/2 diff-files: integrate with sparse indexShuqi Liang, May 8, 2023
  69. 0/2 diff-files: integrate with sparse indexShuqi Liang, May 9, 2023
  70. 1/2 t1092: add tests for `git diff-files`Shuqi Liang, May 9, 2023
  71. 2/2 diff-files: integrate with sparse indexShuqi Liang, May 9, 2023
  72. Victoria DyeMay 11, 2023
  73. Junio C HamanoMay 11, 2023

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.