git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Michael <gitmlko@not-evil.de>
Cc: git@vger.kernel.org
Subject: Re: git reflog write does not pick up user.name and user.email from config
Date: Tue, 30 Sep 2025 01:57:40 +0200	[thread overview]
Message-ID: <aNsc9En-DjxVOLcV@pks.im> (raw)
In-Reply-To: <519E887F-2028-476E-B26D-85E23F7974A5@not-evil.de>

Hi Michael,

On Mon, Sep 29, 2025 at 01:11:56PM +0200, Michael wrote:
> Hi there!
> 
> I've been playing around with a toy project (an interactive step by step
> git tutorial that is just a repo) where I have been creating a reflog
> manually so far. I was happy to see the new `reflog write` feature and
> wanted to integrate it.
> 
> When comparing the results of my hand made reflog with the new
> `git reflog write` result I found some differences: It does not seem to
> pick up the "user.name" and "user.email" from the local git config.
> 
> Example:
> 
> ```bash
> git init example && cd example
> git config --local user.name "C O Mitter"
> git config --local user.email "committer@example.com"
> 
> message="hi"
> oid="0000000000000000000000000000000000000000"
> 
> # Setting env vars works as expected
> GIT_COMMITTER_NAME="$(git config --get user.name)" \
>   GIT_COMMITTER_EMAIL="$(git config --get user.email)" \
>   git reflog write "refs/test_vars" "$oid" "$oid" "$message"
> 
> # Picking up the information from the local config does not work
> unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
> git reflog write "refs/test_no_vars" "$oid" "$oid" "$message"
> 
> # Since setting the env variables to the config value, no diff expected
> # but:
> diff .git/logs/refs/test_*
> # 1c1
> # < 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 Michael <michael@mycomp.local> 1759142076 +0200	hi
> # ---
> # > 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 C O Mitter <committer@example.com> 1759142076 +0200	hi
> ```
> 
> Intuitively I would expect these values to be picked up from the local
> config instead of having to specify them in env variables. I didn't
> expect it to fall back to some system values, instead of git config. Is
> there a reason that this information is not used from the config? And if
> yes, could you set some config, so that it gets picked up?

Thanks for this great bug report!

You're definitely onto something. The problem indeed is that we don't
parse any of the configuration right now, but I agree a 100% that we
really should.

The reason why I never noticed this issue is that our test suite by
default sets both GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL. If set,
we'll end up writing those into the reflog as expected. So it's a bit of
a test gap we have.

> Unfortunately my ability to understand C is too limited to grasp how
> `git_committer_info` works…

You't typically call it with `repo_config()`. So if you want to work on
this, the below should work. Only thing that's missing would be a test
to verify that the gitconfig is parsed now as well as a proper commit
message to tie it all together.

Thanks!

Patrick

diff --git a/builtin/reflog.c b/builtin/reflog.c
index c8f6b93d60..40884787b9 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -422,6 +422,8 @@ static int cmd_reflog_write(int argc, const char **argv, const char *prefix,
 	if (argc != 4)
 		usage_with_options(reflog_write_usage, options);
 
+	repo_config(repo, git_ident_config, NULL);
+
 	ref = argv[0];
 	if (!is_root_ref(ref) && check_refname_format(ref, 0))
 		die(_("invalid reference name: %s"), ref);

  reply	other threads:[~2025-09-29 23:57 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 [this message]
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
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=aNsc9En-DjxVOLcV@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitmlko@not-evil.de \
    /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).