Merge branch 'ml/reflog-write-committer-info-fix' into jch

"git reflog write" did not honor the configured user.name/email
which has been corrected.

* ml/reflog-write-committer-info-fix:
  builtin/reflog: respect user config in "write" subcommand
Junio C Hamano 2025-10-06 10:25:21 -07:00
commit 7f48a27946
2 changed files with 38 additions and 0 deletions

View File

@ -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);

View File

@ -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 &&