git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: John Cai <johncai86@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "John Cai via GitGitGadget" <gitgitgadget@gmail.com>,
	git@vger.kernel.org, "Phillip Wood" <phillip.wood123@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH v4 1/3] rebase: test showing bug in rebase with non-branch
Date: Thu, 17 Mar 2022 18:44:44 -0400	[thread overview]
Message-ID: <1BEA9176-EB83-4E7C-A592-037667D0D9ED@gmail.com> (raw)
In-Reply-To: <xmqqo824e145.fsf@gitster.g>

Hi Junio,

On 17 Mar 2022, at 17:10, Junio C Hamano wrote:

> "John Cai via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> From: John Cai <johncai86@gmail.com>
>>
>> Currently when rebase is used with a non branch, and <oid> is up to
>> date with base:
>>
>> git rebase base <oid>
>>
>> It will update the ref that HEAD is pointing at to <oid>, and leave HEAD
>> unmodified.
>>
>> This is a bug. The expected behavior is that the branch HEAD points at
>> remains unmodified while HEAD is updated to point to <oid> in detached
>> HEAD mode.
>
> Never do tests this way.
>
> The primary reason why we do not want to write our tests the way
> this patch does is because we do not _care_ how it is broken in the
> behaviour of the original code.  'main' moving out of $old_main is
> the bug we care about.  It is still buggy if it did not move to
> Second, but some other commit.  Yet this patch insists that 'main'
> to move to Second and nothing else.  What we want is 'main' to stay
> at $old_main in the end anyway, and we should directly test that
> condition.

I was attemping to follow the advice to "show" vs "tell" in [1]. All this
make sense to me however.

>
> If you insist to have two commits (which I strongly recommend
> against in this case), you write a test that makes sure that 'main'
> stays at $old_main, but mark the test with test_expect_failure.  And
> then later in the step that fixes the code, flip "expect_failure" to
> "expect_success".
>
> But it is not ideal, either.  Imagine what you see in "git show"
> output of the commit that fixed the problem.  Most of the test that
> shows the behaviour that the commit _cares_ about will be outside
> post-context of the hunk that flips test_expect_failure to
> test_expect_success.
>
> The best and the simplest way, for a simple case like this, to write
> test is to add the test to expect what we want to see in the end,
> and do so in the same commit as the one that corrects the behaviour
> of the code.  If somebody wants to see what the breakage looks like,
> it is easy to
>
>  (1) checkout the commit that fixes the code and adds such a test,
>
>  (2) tentatively revert everything outside t/, and
>
>  (3) run the test with "-i -v" options.
>
> Then test_expect_success that wants to see 'main' to stay at
> $old_main will show that 'main' moved by a test failure.  Working
> from a patch is the same way, i.e. you can apply only the parts
> inside t/ and run the current code to see the breakage, and then
> apply the rest to see the fix.
>
>> +test_expect_success 'switch to non-branch changes branch HEAD points to' '
>> +	git checkout main &&
>> +	old_main=$(git rev-parse HEAD) &&
>> +	git rebase First Second^0 &&
>
>> +	test_cmp_rev HEAD main &&
>> +	test_cmp_rev main $(git rev-parse Second) &&
>> +	git symbolic-ref HEAD
>
> I already said that the second one should expect main to be at
> $old_main, but the "HEAD and main are the same" and "HEAD is a
> symolic-ref" test can be replaced with a single test that is "HEAD
> is a symbolic-ref to 'main'", which would be more strict.  I.e.
>
> 	test "$(git symbolic-ref HEAD)" = refs/heads/main &&
> 	test_cmp_rev main "$old_main"
>
> And such a test that expects the correct behaviour we want to have
> in the end should be added in [PATCH 3/3] when the code is fixed,
> not here in a separate commit.

1. https://lore.kernel.org/git/220317.86r170d6zs.gmgdl@evledraar.gmail.com/

>
>> +'
>
> Thanks.

  parent reply	other threads:[~2022-03-17 22:44 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11  5:05 [PATCH] rebase: set REF_HEAD_DETACH in checkout_up_to_date() John Cai via GitGitGadget
2022-03-11  5:33 ` Junio C Hamano
2022-03-11  5:55 ` Junio C Hamano
2022-03-11 14:14   ` John Cai
2022-03-11 15:05 ` Phillip Wood
2022-03-11 15:28   ` John Cai
2022-03-11 19:42   ` John Cai
2022-03-11 21:31     ` Phillip Wood
2022-03-11 17:24 ` [PATCH v2 0/2] rebase: update HEAD when is an oid John Cai via GitGitGadget
2022-03-11 17:24   ` [PATCH v2 1/2] rebase: use test_commit helper in setup John Cai via GitGitGadget
2022-03-13  7:50     ` Junio C Hamano
2022-03-14 10:52       ` Phillip Wood
2022-03-14 21:47         ` Junio C Hamano
2022-03-11 17:24   ` [PATCH v2 2/2] rebase: set REF_HEAD_DETACH in checkout_up_to_date() John Cai via GitGitGadget
2022-03-13  7:58     ` Junio C Hamano
2022-03-14 10:54       ` Phillip Wood
2022-03-14 14:05         ` Phillip Wood
2022-03-14 14:11       ` John Cai
2022-03-14 14:25         ` Phillip Wood
2022-03-17  3:16   ` [PATCH v3 0/2] rebase: update HEAD when is an oid John Cai via GitGitGadget
2022-03-17  3:16     ` [PATCH v3 1/2] rebase: use test_commit helper in setup John Cai via GitGitGadget
2022-03-17 13:37       ` Ævar Arnfjörð Bjarmason
2022-03-17  3:16     ` [PATCH v3 2/2] rebase: set REF_HEAD_DETACH in checkout_up_to_date() John Cai via GitGitGadget
2022-03-17 13:42       ` Ævar Arnfjörð Bjarmason
2022-03-17 15:34         ` Junio C Hamano
2022-03-17 19:53     ` [PATCH v4 0/3] rebase: update HEAD when is an oid John Cai via GitGitGadget
2022-03-17 19:53       ` [PATCH v4 1/3] rebase: test showing bug in rebase with non-branch John Cai via GitGitGadget
2022-03-17 21:10         ` Junio C Hamano
2022-03-17 21:37           ` Junio C Hamano
2022-03-17 22:44           ` John Cai [this message]
2022-03-17 19:53       ` [PATCH v4 2/3] rebase: use test_commit helper in setup John Cai via GitGitGadget
2022-03-18 11:14         ` Phillip Wood
2022-03-18 13:06           ` John Cai
2022-03-17 19:53       ` [PATCH v4 3/3] rebase: set REF_HEAD_DETACH in checkout_up_to_date() John Cai via GitGitGadget
2022-03-17 21:36         ` Junio C Hamano
2022-03-18  0:30           ` John Cai
2022-03-18 13:54       ` [PATCH v5 0/2] rebase: update HEAD when is an oid John Cai via GitGitGadget
2022-03-18 13:54         ` [PATCH v5 1/2] rebase: use test_commit helper in setup John Cai via GitGitGadget
2022-03-18 16:51           ` Junio C Hamano
2022-03-18 13:54         ` [PATCH v5 2/2] rebase: set REF_HEAD_DETACH in checkout_up_to_date() John Cai via GitGitGadget
2022-03-18 16:55         ` [PATCH v5 0/2] rebase: update HEAD when is an oid Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1BEA9176-EB83-4E7C-A592-037667D0D9ED@gmail.com \
    --to=johncai86@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=phillip.wood123@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).