Skip to content

Commit 4a72736

Browse files
miallopks-t
authored andcommitted
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 <[email protected]> Signed-off-by: Michael Lohmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 465eff8 commit 4a72736

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

builtin/reflog.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ static int cmd_reflog_write(int argc, const char **argv, const char *prefix,
415415
const char *ref, *message;
416416
int ret;
417417

418+
repo_config(repo, git_ident_config, NULL);
419+
418420
argc = parse_options(argc, argv, prefix, options, reflog_write_usage, 0);
419421
if (argc != 4)
420422
usage_with_options(reflog_write_usage, options);

t/t1421-reflog-write.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,42 @@ test_expect_success 'simple writes' '
108108
)
109109
'
110110

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 "[email protected]" &&
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 <[email protected]> $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 "[email protected]" &&
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+
111147
test_expect_success 'can write to root ref' '
112148
test_when_finished "rm -rf repo" &&
113149
git init repo &&

0 commit comments

Comments
 (0)