git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
	David Bimmler via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, David Bimmler <david.bimmler@isovalent.com>
Subject: Re: [PATCH] sequencer: honor signoff opt in run_git_commit
Date: Thu, 4 Apr 2024 20:21:49 +0100	[thread overview]
Message-ID: <a80a5aa9-34f4-4bfe-9e32-7b5e878554ba@gmail.com> (raw)
In-Reply-To: <xmqqzfu914jc.fsf@gitster.g>

On 04/04/2024 17:22, Junio C Hamano wrote:
> "David Bimmler via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> From: David Bimmler <david.bimmler@isovalent.com>
>>
>> When rebasing interactively, --signoff would not take effect for commits
>> which conflict. That is, commits applying cleanly would be signed off,
>> but commits requiring intervention would miss the sign off trailer.
> 
> Good finding.

Yes, thanks for posting this patch.

>> The reason is that run_git_commit did not check for the signoff replay
>> opt, and hence even though the option was picked up and passed
>> correctly, the actual committing dropped the ball.
> 
> We record and read back the initial "--signoff" given from the
> command line (and options.signoff from the "options sheet" when not
> REPLAY_INTERACTIVE_REBASE) in opts->signoff, but that piece of
> information is used only to decide if we call append_signoff().
> When do_commit(), after try_to_commit() punts, calls "git commit",
> the invocation lacks "--signoff" on the command line.
> 
>      Side note: the "let's avoid spawning 'git commit' and duplicate
>      it in-process" codepath in try_to_commit() does not seem to pay
>      attention to opts->signoff at all, and it does not do the
>      append_signoff() to add the trailer.  Is this something this
>      patch needs to fix as well, or am I misreading the control flow
>      (e.g., perhaps opts->signoff is set we somehow refrain from
>      doing the "let's do it in-process" logic)?

I think it is more complicated than that. We do not use the "--signoff" 
option of "git commit" because we do not want to append the 
"Signed-off-by:" trailer when processing "fixup" and "squash" commands. 
The trailer is appended to the commit message by the sequencer in 
do_pick_commits(). The problem is that when we commit a conflict 
resolution we end up using the original commit message rather than the 
file containing the commit message that we would have used if we had not 
stopped for conflicts. I've got some patches which need their commit 
messages cleaning up at 
https://github.com/phillipwood/git/commits/wip/fix-rebase-signoff-with-conflicts/ 
which use the correct file when committing conflict resolutions. I'll 
try and clean them up next week.

Best Wishes

Phillip

> If we forgot to tell "git commit" that we want the result
> signed-off, of course it would not add the trailer.  Perhaps
> 
>      -correctly, the actual committing dropped the ball"
>      +correctly to run_git_commit(), it failed to pass it to
>      +underlying 'git commit'
> 
> is less misleading.
> 
>> The patch adds a test specifically for this case, as well as amending a
>> squash test which codified the broken behaviour.
> 
> "The patch adds" -> "Add"
> 
> I love this kind of test update that corrects a mistaken expectation
> after a careful analysis of how the commands should behave.
> 
> Very good job.  Nicely done.
> 
>> diff --git a/sequencer.c b/sequencer.c
>> index fa838f264f5..16595e26a17 100644
>> --- a/sequencer.c
>> +++ b/sequencer.c
>> @@ -1121,6 +1121,8 @@ static int run_git_commit(const char *defmsg,
>>   		strvec_pushf(&cmd.args, "-S%s", opts->gpg_sign);
>>   	else
>>   		strvec_push(&cmd.args, "--no-gpg-sign");
>> +	if (opts->signoff)
>> +		strvec_push(&cmd.args, "--signoff");
>>   	if (defmsg)
>>   		strvec_pushl(&cmd.args, "-F", defmsg, NULL);
>>   	else if (!(flags & EDIT_MSG))
> 
> This is straight-forward and obviously correct.
> 
>> diff --git a/t/t3428-rebase-signoff.sh b/t/t3428-rebase-signoff.sh
>> index e1b1e947647..fcecdf41978 100755
>> --- a/t/t3428-rebase-signoff.sh
>> +++ b/t/t3428-rebase-signoff.sh
>> @@ -27,6 +27,13 @@ first
>>   Signed-off-by: $(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/")
>>   EOF
>>   
>> +# Expected signed off message after resolving the conflict
>> +cat >expected-signed-after-conflict <<EOF
>> +update file on side
>> +
>> +Signed-off-by: $(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/")
>> +EOF
>> +
> 
> The t3428 script uses ancient style to prepare these expectations
> outside the test_expect_success blocks, and following the pattern
> is fine (until we clean-up the style of the whole script).  Cleaning
> it up is better done as a separate series, and when the dust settles
> after this fix lands.  #leftoverbits
> 
>>   # Expected commit message after rebase without --signoff (or with --no-signoff)
>>   cat >expected-unsigned <<EOF
>>   first
>> @@ -82,4 +89,30 @@ test_expect_success 'rebase -m --signoff fails' '
>>   	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
>>   	test_cmp expected-signed actual
>>   '
>> +
>> +test_expect_success 'rebase -i signs commits even if a conflict occurs' '
>> +	git branch -M main &&
>> +
>> +	git branch side &&
>> +	echo "b" >file &&
>> +	git add file &&
>> +	git commit -m"update file" &&
> 
> Have a SP between "-m" and its value, imitating existing tests.
> 
>> +	test_tick &&
> 
> Why?  Does the rest of the test depend on commits to have different
> timestamps?
> 
> If you want to use test_tick, the pattern to follow is to call it
> _before_ creating a commit, not after.  Up to this point in the
> original script nobody calls it (or test_commit that by default
> calls it), so "test_tick && git_commit" would be OK.
> 
> But if there is no dependency on exact sequence of timestamps,
> letting the commit share the same initial timestamp (hardcoded in
> test-lib.sh for better reproducibility) is more preferable, as use
> of test_tick sends a wrong message that the test results may be
> affected by the exact timestamps.
> 
>> +	test_must_fail git rebase -i --signoff main &&
>> +
>> +	echo "merged" >file &&
>> +	git add file &&
>> +	git rebase --continue &&
>> +
>> +	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
>> +	test_cmp expected-signed-after-conflict actual
> 
> Running any git command on the left hand side of a pipe is frowned
> upon, as it will hide exit status from it when it fails.
> 
> In this case, the primary thing we care about is that we have added
> the sign off that did not exist in the original, so I wonder
> 
> 	git cat-file commit HEAD >actual &&
> 	test_grep "Signed-off-by: " actual
> 
> would be sufficient?
> 
>> +'
>> +
>>   test_done
>> diff --git a/t/t3437/expected-squash-message b/t/t3437/expected-squash-message
>> index ab2434f90ed..d74af0bcf6b 100644
>> --- a/t/t3437/expected-squash-message
>> +++ b/t/t3437/expected-squash-message
>> @@ -48,4 +48,6 @@ edited 1
>>   edited 2
>>   
>>   edited 3
>> +
>> +Signed-off-by: Rebase Committer <rebase.committer@example.com>
>>   squashed
> 
> This defines the expected outcome from
> 
>      git rebase -ik --signoff A
> 
> in t3437-rebase-fixup-options.sh; I am not sure if the location the
> sign-off is inserted is sensible, though.
> 
> Thanks.
> 


  parent reply	other threads:[~2024-04-04 19:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-04  9:39 [PATCH] sequencer: honor signoff opt in run_git_commit David Bimmler via GitGitGadget
2024-04-04 16:22 ` Junio C Hamano
2024-04-04 16:45   ` Junio C Hamano
2024-04-04 19:22     ` Phillip Wood
2024-04-04 19:21   ` Phillip Wood [this message]
2024-04-05 11:50     ` David Bimmler

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=a80a5aa9-34f4-4bfe-9e32-7b5e878554ba@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=david.bimmler@isovalent.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=phillip.wood@dunelm.org.uk \
    /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).