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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Lohmann committed
Sep 30, 2025 at 21:53 UTC
4a72736d1993d5702d074ea1a92e584633b20f54
2 files changed
+38
builtin/reflog.c
+2
@@ -415,6 +415,8 @@ static int cmd_reflog_write(int argc, const char **argv, const char *prefix,
415
const char *ref, *message;
416
int ret;
417
418
+ repo_config(repo, git_ident_config, NULL);
419
+
420
argc = parse_options(argc, argv, prefix, options, reflog_write_usage, 0);
421
if (argc != 4)
422
usage_with_options(reflog_write_usage, options);
t/t1421-reflog-write.sh
+36
@@ -108,6 +108,42 @@ test_expect_success 'simple writes' '
108
)
109
'
110
111
+test_expect_success 'uses user.name and user.email config' '
112
+ test_when_finished "rm -rf repo" &&
113
+ git init repo &&
114
+ (
115
+ cd repo &&
116
+ test_commit initial &&
117
+ COMMIT_OID=$(git rev-parse HEAD) &&
118
+
119
+ sane_unset GIT_COMMITTER_NAME &&
120
+ sane_unset GIT_COMMITTER_EMAIL &&
121
+ git config --local user.name "Author" &&
122
+ git config --local user.email "a@uth.or" &&
123
+ git reflog write refs/heads/something $ZERO_OID $COMMIT_OID first &&
124
+ test_reflog_matches . refs/heads/something <<-EOF
125
+ $ZERO_OID $COMMIT_OID Author <a@uth.or> $GIT_COMMITTER_DATE first
126
+ EOF
127
+ )
128
+'
129
+
130
+test_expect_success 'environment variables take precedence over config' '
131
+ test_when_finished "rm -rf repo" &&
132
+ git init repo &&
133
+ (
134
+ cd repo &&
135
+ test_commit initial &&
136
+ COMMIT_OID=$(git rev-parse HEAD) &&
137
+
138
+ git config --local user.name "Author" &&
139
+ git config --local user.email "a@uth.or" &&
140
+ git reflog write refs/heads/something $ZERO_OID $COMMIT_OID first &&
141
+ test_reflog_matches . refs/heads/something <<-EOF
142
+ $ZERO_OID $COMMIT_OID $SIGNATURE first
143
+ EOF
144
+ )
145
+'
146
+
147
test_expect_success 'can write to root ref' '
148
test_when_finished "rm -rf repo" &&
149
git init repo &&