threads / discuss / 64224

git reflog write does not pick up user.name and user.email from config

Subject: git reflog write does not pick up user.name and user.email from config

## tl;dr

9 messages between Sep 29, 2025 and Oct 1, 2025.

replies: 8people: 4as markdown or json

Michael· Sep 29, 2025, 11:11 UTC · lore
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?

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

Thanks a lot for your work! Michael

Patrick Steinhardt· Sep 29, 2025, 23:57 UTC · re: Michael · lore

Re: git reflog write does not pick up user.name and user.email from config

Hi Michael,
On Mon, Sep 29, 2025 at 01:11:56PM +0200, Michael wrote:
Show 44 quoted lines
> 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);
gitmlko@not-evil.de· Sep 30, 2025, 09:14 UTC · re: Patrick Steinhardt · lore

[PATCH] builtin/reflog: respect user config in "write" subcommand

From: Michael Lohmann <git@lohmann.sh>

Previously, the reflog write command only recognized the environment variables GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL. It did not account for user.name and user.email settings from the Git configuration.

Since the test suite always sets these variables, it was unnoticed that not present, it would use the system config as defaults instead of the git config.

Co-Authored-By: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Michael Lohmann <git@lohmann.sh>
---
 builtin/reflog.c        |  2 ++
 t/t1421-reflog-write.sh | 11 ++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
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);
diff --git a/t/t1421-reflog-write.sh b/t/t1421-reflog-write.sh
index 46df64c176..65fc4cae93 100755
--- a/t/t1421-reflog-write.sh
+++ b/t/t1421-reflog-write.sh
@@ -101,10 +101,19 @@ test_expect_success 'simple writes' '
 		EOF
 
 		git reflog write refs/heads/something $COMMIT_OID $COMMIT_OID second &&
-		test_reflog_matches . refs/heads/something <<-EOF
+		test_reflog_matches . refs/heads/something <<-EOF &&
 		$ZERO_OID $COMMIT_OID $SIGNATURE	first
 		$COMMIT_OID $COMMIT_OID $SIGNATURE	second
 		EOF
+
+		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_new $ZERO_OID $COMMIT_OID first &&
+		test_reflog_matches . refs/heads/something_new <<-EOF
+		$ZERO_OID $COMMIT_OID Author <a@uth.or> 1112911993 -0700	first
+		EOF
 	)
 '
 

base-commit: 821f583da6d30a84249f75f33501504d597bc16b
-- 
2.51.GIT
Patrick Steinhardt· Sep 30, 2025, 11:26 UTC · re: gitmlko@not-evil.de · lore

Re: [PATCH] builtin/reflog: respect user config in "write" subcommand

On Tue, Sep 30, 2025 at 11:14:11AM +0200, gitmlko@not-evil.de wrote:
> From: Michael Lohmann <git@lohmann.sh>

Is there any specific reason why the originating mail address and the author information disagree with one another? It makes it hard for us to verify that these mail addresses actually map to the same person.

> Previously, the reflog write command only recognized the environment
> variables GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL. It did not account
> for user.name and user.email settings from the Git configuration.
Nit: we typically write our commit messages in the following style:
  - We describe the problem in the present tense.
  - We then proceed to describe why that problem exists. In our context,
    it's also relevant to explain why our tests didn't catch the issue.
  - Finally, we use imperative mood to say how the problem is fixed, as
    if instructing the code to change.
Happy to provide more guidance here as needed.
Show 5 quoted lines
> Since the test suite always sets these variables, it was unnoticed that
> not present, it would use the system config as defaults instead of the
> git config.
> 
> Co-Authored-By: Patrick Steinhardt <ps@pks.im>

Another tiny nit: This should be "Co-authored-by", with everything except the leading "C" being lower-case.

Show 24 quoted lines
> diff --git a/t/t1421-reflog-write.sh b/t/t1421-reflog-write.sh
> index 46df64c176..65fc4cae93 100755
> --- a/t/t1421-reflog-write.sh
> +++ b/t/t1421-reflog-write.sh
> @@ -101,10 +101,19 @@ test_expect_success 'simple writes' '
>  		EOF
>  
>  		git reflog write refs/heads/something $COMMIT_OID $COMMIT_OID second &&
> -		test_reflog_matches . refs/heads/something <<-EOF
> +		test_reflog_matches . refs/heads/something <<-EOF &&
>  		$ZERO_OID $COMMIT_OID $SIGNATURE	first
>  		$COMMIT_OID $COMMIT_OID $SIGNATURE	second
>  		EOF
> +
> +		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_new $ZERO_OID $COMMIT_OID first &&
> +		test_reflog_matches . refs/heads/something_new <<-EOF
> +		$ZERO_OID $COMMIT_OID Author <a@uth.or> 1112911993 -0700	first
> +		EOF
>  	)
>  '
I think it would be preferable to make this a separate test case.
Thanks for working on this!
Patrick
git@lohmann.sh· Sep 30, 2025, 14:37 UTC · re: Patrick Steinhardt · lore

[PATCH v2] builtin/reflog: respect user config in "write" subcommand

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.

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>
---
Thank you for your feedback! Is this better now or how could I improve
it?

The reason why I sent it from my other email address was that originally I didn't expect to submit a patch. Since I sent the first email from the other address, I wasn't sure if it was easier to keep the context, but I didn't have the other perspective. Now sent from the git email.

Change compared to last version:
- aligned commit message with style guide
- created a separate test case
Michael
 builtin/reflog.c        |  2 ++
 t/t1421-reflog-write.sh | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+)
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);
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 &&
+		test_reflog_matches . refs/heads/something <<-EOF
+		$ZERO_OID $COMMIT_OID Author <a@uth.or> 1112911993 -0700	first
+		EOF
+	)
+'
+
 test_expect_success 'can write to root ref' '
 	test_when_finished "rm -rf repo" &&
 	git init repo &&

base-commit: 821f583da6d30a84249f75f33501504d597bc16b
-- 
2.50.1 (Apple Git-155)
Junio C Hamano· Sep 30, 2025, 17:13 UTC · re: git@lohmann.sh · lore

Re: [PATCH v2] builtin/reflog: respect user config in "write" subcommand

git@lohmann.sh writes:
Show 5 quoted lines
> 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.

Show 7 quoted lines
> 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.

Show 24 quoted lines
>  	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.

Show 9 quoted lines
> +		EOF
> +	)
> +'
> +
>  test_expect_success 'can write to root ref' '
>  	test_when_finished "rm -rf repo" &&
>  	git init repo &&
>
> base-commit: 821f583da6d30a84249f75f33501504d597bc16b
Thanks.
Michael Lohmann· Sep 30, 2025, 19:53 UTC · re: Junio C Hamano · lore

[PATCH v3] builtin/reflog: respect user config in "write" subcommand

The reflog write recognizes only GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL environment variables, 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.

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>
---
- Improved commit message according to Junio Hamanos suggestion
- moved repo_config() call above parse_options() (I can't judge where
  the proper place would be)
- add test to check if env variables overwrite config
- use $GIT_COMMITTER_DATE instead of that timestamp in existing test
  case
 builtin/reflog.c        |  2 ++
 t/t1421-reflog-write.sh | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
diff --git a/builtin/reflog.c b/builtin/reflog.c
index c8f6b93d60..dcbfe89339 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -418,6 +418,8 @@ static int cmd_reflog_write(int argc, const char **argv, const char *prefix,
 	const char *ref, *message;
 	int ret;
 
+	repo_config(repo, git_ident_config, NULL);
+
 	argc = parse_options(argc, argv, prefix, options, reflog_write_usage, 0);
 	if (argc != 4)
 		usage_with_options(reflog_write_usage, options);
diff --git a/t/t1421-reflog-write.sh b/t/t1421-reflog-write.sh
index 46df64c176..603ec3f6ed 100755
--- a/t/t1421-reflog-write.sh
+++ b/t/t1421-reflog-write.sh
@@ -108,6 +108,42 @@ 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 &&
+		test_reflog_matches . refs/heads/something <<-EOF
+		$ZERO_OID $COMMIT_OID Author <a@uth.or> $GIT_COMMITTER_DATE	first
+		EOF
+	)
+'
+
+test_expect_success 'environment variables take precedence over config' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit initial &&
+		COMMIT_OID=$(git rev-parse HEAD) &&
+
+		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 &&
+		test_reflog_matches . refs/heads/something <<-EOF
+		$ZERO_OID $COMMIT_OID $SIGNATURE	first
+		EOF
+	)
+'
+
 test_expect_success 'can write to root ref' '
 	test_when_finished "rm -rf repo" &&
 	git init repo &&

base-commit: 821f583da6d30a84249f75f33501504d597bc16b
-- 
2.51.0.373.g6d4c29e8d5.dirty
Patrick Steinhardt· Oct 1, 2025, 07:37 UTC · re: Michael Lohmann · lore

Re: [PATCH v3] builtin/reflog: respect user config in "write" subcommand

On Tue, Sep 30, 2025 at 09:53:20PM +0200, Michael Lohmann wrote:
Show 12 quoted lines
> The reflog write recognizes only GIT_COMMITTER_NAME and
> GIT_COMMITTER_EMAIL environment variables, 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.
> 
> 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>
Thanks, this version looks good to me!
Patrick
Junio C Hamano· Oct 1, 2025, 16:50 UTC · re: Patrick Steinhardt · lore

Re: [PATCH v3] builtin/reflog: respect user config in "write" subcommand

Patrick Steinhardt <ps@pks.im> writes:
Show 15 quoted lines
> On Tue, Sep 30, 2025 at 09:53:20PM +0200, Michael Lohmann wrote:
>> The reflog write recognizes only GIT_COMMITTER_NAME and
>> GIT_COMMITTER_EMAIL environment variables, 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.
>> 
>> 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>
>
> Thanks, this version looks good to me!
Yup.  Will apply on top of the ps/reflog-migrate-fixes topic.
I didn't realize "reflog write" was so new ;-)
Thanks.

← back to recent threads