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

From: [email-masked]
Date: Tue, 30 Sep 2025 16:37:41 +0200

From: Michael Lohmann <[email-masked]>

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 <[email-masked]>
Signed-off-by: Michael Lohmann <[email-masked]>
---
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 "[email-masked]" &&
+		git reflog write refs/heads/something $ZERO_OID $COMMIT_OID first &&
+		test_reflog_matches . refs/heads/something <<-EOF
+		$ZERO_OID $COMMIT_OID Author <[email-masked]> 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)