@@ -112,6 +112,103 @@ def test_repo_git_remote_repo_and_sync(
112112 result .assert_outcomes (passed = 1 )
113113
114114
115+ def test_git_remote_repo (
116+ pytester : pytest .Pytester ,
117+ monkeypatch : pytest .MonkeyPatch ,
118+ tmp_path : pathlib .Path ,
119+ ) -> None :
120+ """Tests for libvcs pytest plugin git configuration."""
121+ monkeypatch .setenv ("HOME" , str (tmp_path ))
122+
123+ # Initialize variables
124+ pytester .plugins = ["pytest_plugin" ]
125+ pytester .makefile (
126+ ".ini" ,
127+ pytest = textwrap .dedent (
128+ """
129+ [pytest]
130+ addopts=-vv
131+ """ .strip (),
132+ ),
133+ )
134+ pytester .makeconftest (
135+ textwrap .dedent (
136+ r"""
137+ import pathlib
138+ import pytest
139+
140+ @pytest.fixture(scope="session")
141+ def vcs_email() -> str:
142+ return "custom_email@testemail.com"
143+
144+ @pytest.fixture(autouse=True)
145+ def setup(
146+ request: pytest.FixtureRequest,
147+ gitconfig: pathlib.Path,
148+ set_home: pathlib.Path,
149+ ) -> None:
150+ pass
151+ """ ,
152+ ),
153+ )
154+ tests_path = pytester .path / "tests"
155+ files = {
156+ "example.py" : textwrap .dedent (
157+ """
158+ import pathlib
159+
160+ from libvcs.sync.git import GitSync
161+ from libvcs.pytest_plugin import (
162+ CreateRepoPytestFixtureFn,
163+ git_remote_repo_single_commit_post_init
164+ )
165+
166+ def test_git_bare_repo_sync_and_commit(
167+ create_git_remote_bare_repo: CreateRepoPytestFixtureFn,
168+ projects_path: pathlib.Path,
169+ ) -> None:
170+ git_server = create_git_remote_bare_repo()
171+ git_repo_checkout_dir = projects_path / "my_git_checkout"
172+ git_repo = GitSync(path=str(git_repo_checkout_dir), url=f"file://{git_server!s}")
173+
174+ git_repo.obtain()
175+ git_repo.update_repo()
176+
177+ assert git_repo.get_revision() == "initial"
178+
179+ assert git_repo_checkout_dir.exists()
180+ assert pathlib.Path(git_repo_checkout_dir / ".git").exists()
181+
182+ git_remote_repo_single_commit_post_init(
183+ remote_repo_path=git_repo_checkout_dir
184+ )
185+
186+ assert git_repo.get_revision() != "initial"
187+
188+ last_committer_email = git_repo.cmd.run(["log", "-1", "--pretty=format:%ae"])
189+
190+ assert last_committer_email == "custom_email@testemail.com", (
191+ 'Email should use the override from the "vcs_email" fixture'
192+ )
193+ """ ,
194+ ),
195+ }
196+ first_test_key = next (iter (files .keys ()))
197+ first_test_filename = str (tests_path / first_test_key )
198+
199+ tests_path .mkdir ()
200+ for file_name , text in files .items ():
201+ test_file = tests_path / file_name
202+ test_file .write_text (
203+ text ,
204+ encoding = "utf-8" ,
205+ )
206+
207+ # Test
208+ result = pytester .runpytest (str (first_test_filename ))
209+ result .assert_outcomes (passed = 1 )
210+
211+
115212def test_gitconfig (
116213 gitconfig : pathlib .Path ,
117214 set_gitconfig : pathlib .Path ,
0 commit comments