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

Re: [PATCH 04/11] t: convert tests to not write references via the filesystem

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 18, 2023, 21:18 UTC
Message-ID
<xmqqfs27r5ng.fsf@gitster.g>
In-Reply-To
<c79431c0bf117d756e1d584f4c9415888d9ff9eb.1697607222.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 6 quoted lines
> @@ -434,7 +432,7 @@ test_expect_success 'Query "main@{2005-05-28}" (past end of history)' '
>  	test_i18ngrep -F "warning: log for ref $m unexpectedly ended on $ld" e
>  '
>  
> -rm -f .git/$m .git/logs/$m expect
> +git update-ref -d $m

We are not clearing "expect" file. I do not know if it matters here, but I am only recording what I noticed.

Show 11 quoted lines
> diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
> index 10a539158c4..5cce24f1006 100755
> --- a/t/t1450-fsck.sh
> +++ b/t/t1450-fsck.sh
> @@ -115,15 +115,16 @@ test_expect_success 'zlib corrupt loose object output ' '
>  '
>  
>  test_expect_success 'branch pointing to non-commit' '
> -	git rev-parse HEAD^{tree} >.git/refs/heads/invalid &&
> +	tree_oid=$(git rev-parse --verify HEAD^{tree}) &&
> +	test-tool ref-store main update-ref msg refs/heads/invalid $tree_oid $ZERO_OID REF_SKIP_OID_VERIFICATION &&
I have mixed feelings on this.

In olden days, plumbing commands tended to allow to pass anything the user told them to use, but in more recent versions of Git, we, probably by mistake, managed to butcher some of the plumbing commands to make them unable to deliberately "break" repositories, one victim being "update-ref", i.e.

    $ git update-ref refs/heads/invalid HEAD^{tree}

is rejected these days (I just checked with v1.3.0 and it allows me to do this), and that is one of the reasons why we manually broke the repository in these tests. We need to have a warning message in comments near the implementation of "ref-store update-ref" that says never ever attempt to share code with the production version of update-ref---otherwise this (or the "safety" given to the plumbing command, possibly by mistake) will be broken, depending on which direction such a sharing goes. On the other hand, forcing us to keep two separate implementations, one deliberately loose to allow us corrupt repositories, the other for production and actively used, would mean the former one that is only used for validation would risk bitrotting.

>  	test_when_finished "git update-ref -d refs/heads/invalid" &&

Not a problem this patch introduces, but I think it is a better discipline to have when_finished clean-up routine prepared before we do actual damage, i.e. if I were writing this test today from scratch, I would expect it to be before "git rev-parse >.git/refs/heads/invalid" is done.

>  	test_must_fail git fsck 2>out &&
>  	test_i18ngrep "not a commit" out
>  '

A #leftoverbit that is not relevant to the topic; we should clean these test_i18ngrep and replace them with a plain "grep".

Show 6 quoted lines
>  test_expect_success 'HEAD link pointing at a funny object' '
> -	test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
> -	mv .git/HEAD .git/SAVED_HEAD &&
> +	saved_head=$(git rev-parse --verify HEAD) &&
> +	test_when_finished "git update-ref HEAD ${saved_head}" &&
>  	echo $ZERO_OID >.git/HEAD &&

Are you sure .git/HEAD when this test is entered is a detached HEAD? The title of the test says "HEAD link", and I take it to mean HEAD is a symlink, and we save it away, while we create a loose ref that points at 0{40} in a detached HEAD state. Actually, the original would also work if HEAD is detached on entry. In either case, moving SAVED_HEAD back to HEAD would restore the original state.

But the updated one only works if HEAD upon entry is already detached. Is this intended?

Show 8 quoted lines
> @@ -131,8 +132,8 @@ test_expect_success 'HEAD link pointing at a funny object' '
>  '
>  
>  test_expect_success 'HEAD link pointing at a funny place' '
> -	test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
> -	mv .git/HEAD .git/SAVED_HEAD &&
> +	saved_head=$(git rev-parse --verify HEAD) &&
> +	test_when_finished "git update-ref --no-deref HEAD ${saved_head}" &&

Likewise. Use of "update-ref" in the previous one vs "update-ref --no-deref" in this one to recover from the damage the tests make makes me feel that we may be assuming too much.

>  	echo "ref: refs/funny/place" >.git/HEAD &&

Even though "git symbolic-ref" refuses to point HEAD outside refs/, as plumbing command should, it allows it to point it outside refs/heads/. so this line should probably become

	git symbolic-ref HEAD refs/funny/place
in the same spirit as the rest of the series.
Show 6 quoted lines
> @@ -391,7 +393,7 @@ test_expect_success 'tag pointing to nonexistent' '
>  
>  	tag=$(git hash-object -t tag -w --stdin <invalid-tag) &&
>  	test_when_finished "remove_object $tag" &&
> -	echo $tag >.git/refs/tags/invalid &&
> +	git update-ref refs/tags/invalid $tag &&
Good (not just this one, but similar ones throughout this patch).
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 17 of 59 in “t: reduce direct disk access to data structures”
  1. 00/11 t: reduce direct disk access to data structuresPatrick Steinhardt, Oct 18, 2023
  2. 01/11 t: add helpers to test for reference existencePatrick Steinhardt, Oct 18, 2023
  3. Junio C HamanoOct 18, 2023
  4. Patrick SteinhardtOct 23, 2023
  5. Eric SunshineOct 18, 2023
  6. Patrick SteinhardtOct 23, 2023
  7. 02/11 t: allow skipping expected object ID in `ref-store update-ref`Patrick Steinhardt, Oct 18, 2023
  8. Junio C HamanoOct 18, 2023
  9. Patrick SteinhardtOct 23, 2023
  10. Junio C HamanoOct 23, 2023
  11. 03/11 t: convert tests to use helpers for reference existencePatrick Steinhardt, Oct 18, 2023
  12. Junio C HamanoOct 18, 2023
  13. 04/11 t: convert tests to not write references via the filesystemPatrick Steinhardt, Oct 18, 2023
  14. Junio C HamanoOct 18, 2023
  15. Patrick SteinhardtOct 23, 2023
  16. Junio C HamanoOct 23, 2023
  17. Junio C HamanoOct 18, 2023
  18. Patrick SteinhardtOct 23, 2023
  19. 05/11 t: convert tests to not access symrefs via the filesystemPatrick Steinhardt, Oct 18, 2023
  20. Junio C HamanoOct 20, 2023
  21. 06/11 t: convert tests to not access reflog via the filesystemPatrick Steinhardt, Oct 18, 2023
  22. Junio C HamanoOct 21, 2023
  23. 07/11 t1450: convert tests to remove worktrees via git-worktree(1)Patrick Steinhardt, Oct 18, 2023
  24. 08/11 t4207: delete replace references via git-update-ref(1)Patrick Steinhardt, Oct 18, 2023
  25. Han-Wen NienhuysOct 18, 2023
  26. Patrick SteinhardtOct 23, 2023
  27. Taylor BlauOct 23, 2023
  28. Patrick SteinhardtOct 24, 2023
  29. 09/11 t7300: assert exact states of repoPatrick Steinhardt, Oct 18, 2023
  30. 10/11 t7900: assert the absence of refs via git-for-each-ref(1)Patrick Steinhardt, Oct 18, 2023
  31. 11/11 t: mark several tests that assume the files backend with REFFILESPatrick Steinhardt, Oct 18, 2023
  32. Patrick SteinhardtOct 18, 2023
  33. Junio C HamanoOct 18, 2023
  34. Patrick SteinhardtOct 23, 2023
  35. Junio C HamanoOct 18, 2023
  36. Han-Wen NienhuysOct 19, 2023
  37. Junio C HamanoOct 19, 2023
  38. Patrick SteinhardtOct 23, 2023
  39. 0/9 t: reduce direct disk access to data structuresPatrick Steinhardt, Oct 24, 2023
  40. 1/9 t: allow skipping expected object ID in `ref-store update-ref`Patrick Steinhardt, Oct 24, 2023
  41. 2/9 t: convert tests to not write references via the filesystemPatrick Steinhardt, Oct 24, 2023
  42. 3/9 t: convert tests to not access symrefs via the filesystemPatrick Steinhardt, Oct 24, 2023
  43. 4/9 t: convert tests to not access reflog via the filesystemPatrick Steinhardt, Oct 24, 2023
  44. 5/9 t1450: convert tests to remove worktrees via git-worktree(1)Patrick Steinhardt, Oct 24, 2023
  45. Eric SunshineOct 27, 2023
  46. 6/9 t4207: delete replace references via git-update-ref(1)Patrick Steinhardt, Oct 24, 2023
  47. 7/9 t7300: assert exact states of repoPatrick Steinhardt, Oct 24, 2023
  48. 8/9 t7900: assert the absence of refs via git-for-each-ref(1)Patrick Steinhardt, Oct 24, 2023
  49. 9/9 t: mark several tests that assume the files backend with REFFILESPatrick Steinhardt, Oct 24, 2023
  50. 0/9 t: reduce direct disk access to data structuresPatrick Steinhardt, Nov 2, 2023
  51. 1/9 t: allow skipping expected object ID in `ref-store update-ref`Patrick Steinhardt, Nov 2, 2023
  52. 2/9 t: convert tests to not write references via the filesystemPatrick Steinhardt, Nov 2, 2023
  53. 3/9 t: convert tests to not access symrefs via the filesystemPatrick Steinhardt, Nov 2, 2023
  54. 4/9 t: convert tests to not access reflog via the filesystemPatrick Steinhardt, Nov 2, 2023
  55. 5/9 t1450: convert tests to remove worktrees via git-worktree(1)Patrick Steinhardt, Nov 2, 2023
  56. 6/9 t4207: delete replace references via git-update-ref(1)Patrick Steinhardt, Nov 2, 2023
  57. 7/9 t7300: assert exact states of repoPatrick Steinhardt, Nov 2, 2023
  58. 8/9 t7900: assert the absence of refs via git-for-each-ref(1)Patrick Steinhardt, Nov 2, 2023
  59. 9/9 t: mark several tests that assume the files backend with REFFILESPatrick Steinhardt, Nov 2, 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.