git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@lohmann.sh
Cc: ps@pks.im,  git@vger.kernel.org
Subject: Re: [PATCH v2] builtin/reflog: respect user config in "write" subcommand
Date: Tue, 30 Sep 2025 10:13:05 -0700	[thread overview]
Message-ID: <xmqqplb750f2.fsf@gitster.g> (raw)
In-Reply-To: <20250930143741.18331-1-git@lohmann.sh> (git@lohmann.sh's message of "Tue, 30 Sep 2025 16:37:41 +0200")

git@lohmann.sh writes:

> From: Michael Lohmann <git@lohmann.sh>
>
> The reflog write recognizes only GIT_COMMITTER_NAME and
> GIT_COMMITTER_EMAIL environment variables, ignoring the user.name and
> user.email settings from the Git configuration.

Rephrasing ", ignoring" and everything after the sentence to
something like

    ..., but forgot to honor the user.name and user.email
    configuration variables, due to lack of repo_config() call to
    grab these values from the configuration files.

would make it more obvious to readers what the right correction
would be.

> The test suite sets these variables, so this behavior was unnoticed.
>
> Ensure that the reflog write also uses the values of user.name and
> user.email if set in the Git configuration.
>
> Co-authored-by: Patrick Steinhardt <ps@pks.im>
> Signed-off-by: Michael Lohmann <git@lohmann.sh>

This is not in general the right place to make repo_config() call,
even though in the current shape of the program it happens to work.

This will start to matter once we start adding command line options
to the program.  We want the configured values read from the
configuration to populate the in-core variables first, and then call
parse_options() to allow command line arguments to override them.

In short, move the call above parse_options().

Another thing to consider is if we want to do this inside
cmd_reflog(), not here.  Once we add another subcommand that also
records who did what, other than "write", to the "reflog" command,
this starts to matter.

>  	ref = argv[0];
>  	if (!is_root_ref(ref) && check_refname_format(ref, 0))
>  		die(_("invalid reference name: %s"), ref);
> diff --git a/t/t1421-reflog-write.sh b/t/t1421-reflog-write.sh
> index 46df64c176..cf0e8608fe 100755
> --- a/t/t1421-reflog-write.sh
> +++ b/t/t1421-reflog-write.sh
> @@ -108,6 +108,25 @@ test_expect_success 'simple writes' '
>  	)
>  '
>  
> +test_expect_success 'uses user.name and user.email config' '
> +	test_when_finished "rm -rf repo" &&
> +	git init repo &&
> +	(
> +		cd repo &&
> +		test_commit initial &&
> +		COMMIT_OID=$(git rev-parse HEAD) &&
> +
> +		sane_unset GIT_COMMITTER_NAME &&
> +		sane_unset GIT_COMMITTER_EMAIL &&
> +		git config --local user.name "Author" &&
> +		git config --local user.email "a@uth.or" &&
> +		git reflog write refs/heads/something $ZERO_OID $COMMIT_OID first &&

It certainly is good to test _without_ environment.  Shouldn't we
also make sure that _with_ environment variables, these configured
values are overriden with a separate test?

> +		test_reflog_matches . refs/heads/something <<-EOF
> +		$ZERO_OID $COMMIT_OID Author <a@uth.or> 1112911993 -0700	first

This timestamp is from the above "test_commit", presumably?  If we
later add more tests _before_ this step and they used test_commit,
would that screw this test up?  It may make sense to say
$GIT_COMMITTER_DATE instead of that timestamp here.

> +		EOF
> +	)
> +'
> +
>  test_expect_success 'can write to root ref' '
>  	test_when_finished "rm -rf repo" &&
>  	git init repo &&
>
> base-commit: 821f583da6d30a84249f75f33501504d597bc16b

Thanks.

  reply	other threads:[~2025-09-30 17:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-29 11:11 git reflog write does not pick up user.name and user.email from config Michael
2025-09-29 23:57 ` Patrick Steinhardt
2025-09-30  9:14   ` [PATCH] builtin/reflog: respect user config in "write" subcommand gitmlko
2025-09-30 11:26     ` Patrick Steinhardt
2025-09-30 14:37       ` [PATCH v2] " git
2025-09-30 17:13         ` Junio C Hamano [this message]
2025-09-30 19:53           ` [PATCH v3] " Michael Lohmann
2025-10-01  7:37             ` Patrick Steinhardt
2025-10-01 16:50               ` 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

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

  git send-email \
    --in-reply-to=xmqqplb750f2.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@lohmann.sh \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    /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.
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 NNTP newsgroup(s).