Skip to content

Commit 63e2347

Browse files
committed
!squash more
1 parent 24e099e commit 63e2347

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

src/libvcs/pytest_plugin.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ def vcs_user(vcs_name: str, vcs_email: str) -> str:
6969
return f"{vcs_name} <{vcs_email}>"
7070

7171

72+
@pytest.fixture(scope="session")
73+
def git_commit_envvars(vcs_name: str, vcs_email: str) -> "_ENV":
74+
"""Return environment variables for `git commit`.
75+
76+
For some reason, `GIT_CONFIG` via {func}`set_gitconfig` doesn't work for `git
77+
commit`."""
78+
return {
79+
"GIT_AUTHOR_NAME": vcs_name,
80+
"GIT_AUTHOR_EMAIL": vcs_email,
81+
"GIT_COMMITTER_NAME": vcs_name,
82+
"GIT_COMMITTER_EMAIL": vcs_email,
83+
}
84+
85+
7286
class RandomStrSequence:
7387
"""Create a random string sequence."""
7488

@@ -290,6 +304,7 @@ def _create_git_remote_repo(
290304
remote_repo_path: pathlib.Path,
291305
remote_repo_post_init: Optional[CreateRepoPostInitFn] = None,
292306
init_cmd_args: InitCmdArgs = DEFAULT_GIT_REMOTE_REPO_CMD_ARGS,
307+
env: "_ENV | None" = None,
293308
) -> pathlib.Path:
294309
if init_cmd_args is None:
295310
init_cmd_args = []
@@ -299,7 +314,7 @@ def _create_git_remote_repo(
299314
)
300315

301316
if remote_repo_post_init is not None and callable(remote_repo_post_init):
302-
remote_repo_post_init(remote_repo_path=remote_repo_path)
317+
remote_repo_post_init(remote_repo_path=remote_repo_path, env=env)
303318

304319
return remote_repo_path
305320

@@ -444,20 +459,14 @@ def git_remote_repo_single_commit_post_init(
444459
def git_remote_repo(
445460
create_git_remote_repo: CreateRepoPytestFixtureFn,
446461
gitconfig: pathlib.Path,
447-
vcs_email: str,
448-
vcs_name: str,
462+
git_commit_envvars: "_ENV",
449463
) -> pathlib.Path:
450464
"""Copy the session-scoped Git repository to a temporary directory."""
451465
# TODO: Cache the effect of of this in a session-based repo
452466
repo_path = create_git_remote_repo()
453467
git_remote_repo_single_commit_post_init(
454468
remote_repo_path=repo_path,
455-
env={
456-
"GIT_AUTHOR_NAME": vcs_name,
457-
"GIT_AUTHOR_EMAIL": vcs_email,
458-
"GIT_COMMITTER_NAME": vcs_name,
459-
"GIT_COMMITTER_EMAIL": vcs_email,
460-
},
469+
env=git_commit_envvars,
461470
)
462471
return repo_path
463472

@@ -772,6 +781,8 @@ def add_doctest_fixtures(
772781
doctest_namespace: dict[str, Any],
773782
tmp_path: pathlib.Path,
774783
set_home: pathlib.Path,
784+
git_commit_envvars: "_ENV",
785+
hgconfig: pathlib.Path,
775786
create_git_remote_repo: CreateRepoPytestFixtureFn,
776787
create_svn_remote_repo: CreateRepoPytestFixtureFn,
777788
create_hg_remote_repo: CreateRepoPytestFixtureFn,
@@ -786,7 +797,9 @@ def add_doctest_fixtures(
786797
if shutil.which("git"):
787798
doctest_namespace["create_git_remote_repo"] = functools.partial(
788799
create_git_remote_repo,
789-
remote_repo_post_init=git_remote_repo_single_commit_post_init,
800+
remote_repo_post_init=functools.partial(
801+
git_remote_repo_single_commit_post_init, env=git_commit_envvars
802+
),
790803
init_cmd_args=None,
791804
)
792805
doctest_namespace["create_git_remote_repo_bare"] = create_git_remote_repo
@@ -801,5 +814,8 @@ def add_doctest_fixtures(
801814
doctest_namespace["create_hg_remote_repo_bare"] = create_hg_remote_repo
802815
doctest_namespace["create_hg_remote_repo"] = functools.partial(
803816
create_hg_remote_repo,
804-
remote_repo_post_init=hg_remote_repo_single_commit_post_init,
817+
remote_repo_post_init=functools.partial(
818+
hg_remote_repo_single_commit_post_init,
819+
env={"HGRCPATH": str(hgconfig)},
820+
),
805821
)

0 commit comments

Comments
 (0)