]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/reflog: respect user config in "write" subcommand
authorMichael Lohmann <git@lohmann.sh>
Tue, 30 Sep 2025 19:53:20 +0000 (21:53 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Oct 2025 16:49:05 +0000 (09:49 -0700)
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>
builtin/reflog.c
t/t1421-reflog-write.sh

index a1b4e02204178f3ccdfc4eb733be7b2627e34c20..a17b5fa69e4cb100e7d26a2a938cd92440847258 100644 (file)
@@ -415,6 +415,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);
index 46df64c1761b40d18366c81a0fabc010e1d40750..603ec3f6ed7ace646b8075cb910ec3df9b5e6538 100755 (executable)
@@ -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 &&