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

Re: [PATCH v2 2/8] t3406: rework rebase reflog tests

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 20, 2022, 20:17 UTC
Message-ID
<xmqqzgkfo6gy.fsf@gitster.g>
In-Reply-To
<0904b50a377ce3ac242f9594a635f9ae7cffc687.1650448612.git.gitgitgadget@gmail.com>
"Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 11 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Refactor the tests in preparation for adding more tests in the next
> few commits. The reworked tests use the same function for testing both
> the "merge" and "apply" backends. The test coverage for the "apply"
> backend now includes setting GIT_REFLOG_ACTION.
>
> Note that rebasing the "conflicts" branch does not create any
> conflicts yet. A commit to do that will be added in the next commit
> and the diff ends up smaller if we have don't rename the branch when
> it is added.
"if we have don't rename"?  Ecannotparse.
Show 26 quoted lines
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  t/t3406-rebase-message.sh | 115 +++++++++++++++++++++++++-------------
>  1 file changed, 76 insertions(+), 39 deletions(-)
>
> diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
> index d17b450e811..5253dd1551d 100755
> --- a/t/t3406-rebase-message.sh
> +++ b/t/t3406-rebase-message.sh
> @@ -10,10 +10,15 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
>  test_expect_success 'setup' '
>  	test_commit O fileO &&
>  	test_commit X fileX &&
> +	git branch fast-forward &&
>  	test_commit A fileA &&
>  	test_commit B fileB &&
>  	test_commit Y fileY &&
>  
> +	git checkout -b conflicts O &&
> +	test_commit P &&
> +	test_commit Q &&
> +
>  	git checkout -b topic O &&
>  	git cherry-pick A B &&
>  	test_commit Z fileZ &&
So, we'd create
	O---X---A---B---Y (main)
        |\
        | P---Q (conflicts)
        \
         A'--B'--Z (topic)
with the above.  The "fast-forward" branch is not yet used.

Without reading the rest of this patch (or the series), especially because you said you'll test multiple rebase strategies (and presumably make sure they result in the same state), my gut says that it may not buy us much to create such an unused branch. If we successfully run a fast-forward test on the branch for one strategy, we have to rewind the result before testing another strategy anyway, so forking a branch to be tested at X when we start testing each rebase strategy would be fine. But we'll see.

Show 28 quoted lines
> @@ -79,54 +84,86 @@ test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
>  	test_i18ngrep "Invalid whitespace option" err
>  '
>  
> -test_expect_success 'GIT_REFLOG_ACTION' '
> -	git checkout start &&
> -	test_commit reflog-onto &&
> -	git checkout -b reflog-topic start &&
> -	test_commit reflog-to-rebase &&
> -
> -	git rebase reflog-onto &&
> -	git log -g --format=%gs -3 >actual &&
> -	cat >expect <<-\EOF &&
> -	rebase (finish): returning to refs/heads/reflog-topic
> -	rebase (pick): reflog-to-rebase
> -	rebase (start): checkout reflog-onto
> +write_reflog_expect () {
> +	if test $mode = --apply
> +	then
> +		sed 's/.*(finish)/rebase finished/; s/ ([^)]*)//'
> +	else
> +		cat
> +	fi >expect
> +}
> +
> +test_reflog () {
> +	mode=$1
> +	reflog_action="$2"

$1 being left unquoted while $2 being quoted makes them look incoherent. It is not wrong to enclose $2 in double quotes, but it is not necessary.

Show 12 quoted lines
> +	test_expect_success "rebase $mode reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
> +	git checkout conflicts &&
> +	test_when_finished "git reset --hard Q" &&
> +
> +	(
> +		if test -n "$reflog_action"
> +		then
> +			GIT_REFLOG_ACTION="$reflog_action" &&
> +			export GIT_REFLOG_ACTION
> +		fi &&
> +		git rebase $mode main
> +	) &&

Is the subshell because you may want to export the envirohnment, or is there anything more subtle going on?

Show 8 quoted lines
> +	git log -g --format=%gs -4 >actual &&
> +	write_reflog_expect <<-EOF &&
> +	${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
> +	${reflog_action:-rebase} (pick): Q
> +	${reflog_action:-rebase} (pick): P
> +	${reflog_action:-rebase} (start): checkout main
>  	EOF
>  	test_cmp expect actual &&

We reset to Q and rebase it onto main, which would mean that we'd replay P and then Q on top of Y. The 4 most recent events on HEAD are that we start at 'main', picking P and Q and then updating the conflicts branch with the result. OK.

It is not what we used to test, but with reference to Q that was established at the beginning, though.

Show 11 quoted lines
> -	git checkout -b reflog-prefix reflog-to-rebase &&
> -	GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
> -	git log -g --format=%gs -3 >actual &&
> -	cat >expect <<-\EOF &&
> -	change-the-reflog (finish): returning to refs/heads/reflog-prefix
> -	change-the-reflog (pick): reflog-to-rebase
> -	change-the-reflog (start): checkout reflog-onto
> +	git log -g --format=%gs -1 conflicts >actual &&
> +	write_reflog_expect <<-EOF &&
> +	${reflog_action:-rebase} (finish): refs/heads/conflicts onto $(git rev-parse main)
>  	EOF

And after doing that, there only is one reflog entry for the conflicts branch itself, i.e. record of finishing to rebase.

For both of the above two tests, I wonder if we want to make sure these four and one entries are the ONLY entries added by the operation. I.e. take the topmost reflog entry _before_ starting to run rebase for both conflicts branch and HEAD, grab five and two reflog entries after the operation from conflicts and HEAD and make sure the four and one are the truly new entries added by the operation, or something like that. Even easier would be to merely count the number of reflog entries of HEAD and conflicts before rebasing, and count them after. We can do subtraction in the shell just fine.

> +	test_cmp expect actual &&
>  
> +	# check there is only one new entry in the branch reflog
It is a valid thing to try verifying, but ...
> +	test_cmp_rev conflicts@{1} Q

... it is unclear how this can count the new reflog entries. If we added two reflog entries, one pointing at Y (i.e. tip of main), another that points at Q (i.e. tip of conflicts before the rebasing), conflicts@{1} would be the same as Q.

Show 21 quoted lines
> +	'
> +
> +	test_expect_success "rebase $mode fast-forward reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
> +	git checkout fast-forward &&
> +	test_when_finished "git reset --hard X" &&
> +
> +	(
> +		if test -n "$reflog_action"
> +		then
> +			GIT_REFLOG_ACTION="$reflog_action" &&
> +			export GIT_REFLOG_ACTION
> +		fi &&
> +		git rebase $mode main
> +	) &&
> +
> +	git log -g --format=%gs -2 >actual &&
> +	write_reflog_expect <<-EOF &&
> +	${reflog_action:-rebase} (finish): returning to refs/heads/fast-forward
> +	${reflog_action:-rebase} (start): checkout main
>  	EOF
>  	test_cmp expect actual &&

Likewise. This only makes sure that the topmost two are what you expect without checking if it added anything extra before these two. Actually counting the entries would give you an easy fix.

Show 14 quoted lines
> -	git log -g --format=%gs -2 reflog-apply >actual &&
> -	cat >expect <<-EOF &&
> -	rebase finished: refs/heads/reflog-apply onto $(git rev-parse Y)
> -	branch: Created from start
> +	git log -g --format=%gs -1 fast-forward >actual &&
> +	write_reflog_expect <<-EOF &&
> +	${reflog_action:-rebase} (finish): refs/heads/fast-forward onto $(git rev-parse main)
>  	EOF
> -	test_cmp expect actual
> -'
> +	test_cmp expect actual &&
> +
> +	# check there is only one new entry in the branch reflog
> +	test_cmp_rev fast-forward@{1} X

The same. This does not ensure there is only one new entry. It merely says that the set of entries you cared about (which is a set of one) is preceded by an entry that happened to point at X.

Show 10 quoted lines
> +	'
> +}
> +
> +test_reflog --merge
> +test_reflog --merge my-reflog-action
> +test_reflog --apply
> +test_reflog --apply my-reflog-action
>  
>  test_expect_success 'rebase -i onto unrelated history' '
>  	git init unrelated &&
Thanks.
Previous: Phillip Wood via GitGitGadgetNext: Phillip Wood via GitGitGadget
Message 27 of 73 in “rebase: make reflog messages independent of the backend”
  1. 0/7 rebase: make reflog messages independent of the backendPhillip Wood via GitGitGadget, Feb 21, 2022
  2. 3/7 rebase --merge: fix reflog message after skippingPhillip Wood via GitGitGadget, Feb 21, 2022
  3. Elijah NewrenApr 17, 2022
  4. 4/7 rebase --apply: respect GIT_REFLOG_ACTIONPhillip Wood via GitGitGadget, Feb 21, 2022
  5. Christian CouderApr 7, 2022
  6. Phillip WoodApr 15, 2022
  7. 7/7 rebase: cleanup action handlingPhillip Wood via GitGitGadget, Feb 21, 2022
  8. Elijah NewrenApr 17, 2022
  9. 5/7 rebase --apply: make reflog messages match rebase --mergePhillip Wood via GitGitGadget, Feb 21, 2022
  10. Elijah NewrenApr 17, 2022
  11. 2/7 rebase --merge: fix reflog when continuingPhillip Wood via GitGitGadget, Feb 21, 2022
  12. Christian CouderApr 7, 2022
  13. Phillip WoodApr 15, 2022
  14. Elijah NewrenApr 17, 2022
  15. 1/7 rebase --apply: remove duplicated codePhillip Wood via GitGitGadget, Feb 21, 2022
  16. Christian CouderApr 7, 2022
  17. Elijah NewrenApr 17, 2022
  18. 6/7 rebase --abort: improve reflog messagePhillip Wood via GitGitGadget, Feb 21, 2022
  19. Elijah NewrenApr 17, 2022
  20. Review Request (was Re: [PATCH 0/7] rebase: make reflog messages independent of the backend)Phillip Wood, Apr 4, 2022
  21. Elijah NewrenApr 17, 2022
  22. Phillip WoodApr 18, 2022
  23. Christian CouderApr 7, 2022
  24. Elijah NewrenApr 17, 2022
  25. 0/8 rebase: make reflog messages independent of the backendPhillip Wood via GitGitGadget, Apr 20, 2022
  26. 2/8 t3406: rework rebase reflog testsPhillip Wood via GitGitGadget, Apr 20, 2022
  27. Junio C HamanoApr 20, 2022
  28. 1/8 rebase --apply: remove duplicated codePhillip Wood via GitGitGadget, Apr 20, 2022
  29. Ævar Arnfjörð BjarmasonApr 20, 2022
  30. Junio C HamanoApr 20, 2022
  31. Junio C HamanoApr 20, 2022
  32. 3/8 rebase --merge: fix reflog when continuingPhillip Wood via GitGitGadget, Apr 20, 2022
  33. 4/8 rebase --merge: fix reflog message after skippingPhillip Wood via GitGitGadget, Apr 20, 2022
  34. 5/8 rebase --apply: respect GIT_REFLOG_ACTIONPhillip Wood via GitGitGadget, Apr 20, 2022
  35. 6/8 rebase --apply: make reflog messages match rebase --mergePhillip Wood via GitGitGadget, Apr 20, 2022
  36. Ævar Arnfjörð BjarmasonApr 20, 2022
  37. Junio C HamanoApr 20, 2022
  38. 7/8 rebase --abort: improve reflog messagePhillip Wood via GitGitGadget, Apr 20, 2022
  39. 8/8 rebase: cleanup action handlingPhillip Wood via GitGitGadget, Apr 20, 2022
  40. Ævar Arnfjörð BjarmasonApr 20, 2022
  41. 0/8 rebase: make reflog messages independent of the backendPhillip Wood via GitGitGadget, Oct 12, 2022
  42. 1/8 rebase --apply: remove duplicated codePhillip Wood via GitGitGadget, Oct 12, 2022
  43. Junio C HamanoOct 12, 2022
  44. Junio C HamanoOct 13, 2022
  45. Phillip WoodOct 20, 2022
  46. 2/8 t3406: rework rebase reflog testsPhillip Wood via GitGitGadget, Oct 12, 2022
  47. 3/8 rebase --merge: fix reflog when continuingPhillip Wood via GitGitGadget, Oct 12, 2022
  48. 4/8 rebase --merge: fix reflog message after skippingPhillip Wood via GitGitGadget, Oct 12, 2022
  49. 5/8 rebase --apply: respect GIT_REFLOG_ACTIONPhillip Wood via GitGitGadget, Oct 12, 2022
  50. 6/8 rebase --apply: make reflog messages match rebase --mergePhillip Wood via GitGitGadget, Oct 12, 2022
  51. 7/8 rebase --abort: improve reflog messagePhillip Wood via GitGitGadget, Oct 12, 2022
  52. 8/8 rebase: cleanup action handlingPhillip Wood via GitGitGadget, Oct 12, 2022
  53. Junio C HamanoOct 12, 2022
  54. Phillip WoodOct 13, 2022
  55. Junio C HamanoOct 13, 2022
  56. 0/8 rebase: make reflog messages independent of the backendPhillip Wood via GitGitGadget, Oct 21, 2022
  57. 1/8 t3406: rework rebase reflog testsPhillip Wood via GitGitGadget, Oct 21, 2022
  58. 2/8 rebase --apply: improve fast-forward reflog messagePhillip Wood via GitGitGadget, Oct 21, 2022
  59. 3/8 rebase --merge: fix reflog when continuingPhillip Wood via GitGitGadget, Oct 21, 2022
  60. Junio C HamanoOct 21, 2022
  61. Phillip WoodOct 25, 2022
  62. Junio C HamanoOct 25, 2022
  63. Phillip WoodOct 26, 2022
  64. Junio C HamanoOct 26, 2022
  65. 4/8 rebase --merge: fix reflog message after skippingPhillip Wood via GitGitGadget, Oct 21, 2022
  66. 5/8 rebase --apply: respect GIT_REFLOG_ACTIONPhillip Wood via GitGitGadget, Oct 21, 2022
  67. Junio C HamanoOct 21, 2022
  68. 6/8 rebase --apply: make reflog messages match rebase --mergePhillip Wood via GitGitGadget, Oct 21, 2022
  69. Junio C HamanoOct 21, 2022
  70. 7/8 rebase --abort: improve reflog messagePhillip Wood via GitGitGadget, Oct 21, 2022
  71. Junio C HamanoOct 21, 2022
  72. 8/8 rebase: cleanup action handlingPhillip Wood via GitGitGadget, Oct 21, 2022
  73. Junio C HamanoOct 21, 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.