Skip to content

Commit 41e855c

Browse files
authored
test(git): Fixes (#335)
2 parents 2c8a916 + a6b80a1 commit 41e855c

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

libvcs/cmd/git.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,14 @@ def pull(
756756
>>> git_remote_repo = create_git_remote_repo()
757757
>>> git.pull()
758758
'Already up to date.'
759-
>>> git = Git(dir=git_local_clone.dir)
759+
760+
Fetch via ref:
761+
>>> git = Git(dir=tmp_path)
762+
>>> git.run(['init'])
763+
'Initialized ...'
760764
>>> git_remote_repo = create_git_remote_repo()
761765
>>> git.pull(reftag=f'file://{git_remote_repo}')
762-
'Already up to date.'
766+
''
763767
>>> git.dir.exists()
764768
True
765769
"""

libvcs/conftest.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,23 @@ def clean():
120120
return dir
121121

122122

123+
def unique_repo_name(
124+
faker: Faker, remote_repos_path: pathlib.Path, max_retries: int = 15
125+
) -> str:
126+
attempts = 1
127+
while True:
128+
if attempts > max_retries:
129+
raise Exception(
130+
f"Could not find unused repo destination (attempts: {attempts})"
131+
)
132+
remote_repo_name = faker.slug()
133+
suggestion = remote_repos_path / remote_repo_name
134+
if suggestion.exists():
135+
attempts += 1
136+
continue
137+
return remote_repo_name
138+
139+
123140
class CreateProjectCallbackProtocol(Protocol):
124141
def __call__(self, remote_repo_path: pathlib.Path):
125142
...
@@ -163,7 +180,7 @@ def fn(
163180
remote_repos_path=remote_repos_path,
164181
remote_repo_name=remote_repo_name
165182
if remote_repo_name is not None
166-
else faker.slug(),
183+
else unique_repo_name(faker=faker, remote_repos_path=remote_repos_path),
167184
remote_repo_post_init=remote_repo_post_init,
168185
)
169186

@@ -219,7 +236,7 @@ def fn(
219236
remote_repos_path=remote_repos_path,
220237
remote_repo_name=remote_repo_name
221238
if remote_repo_name is not None
222-
else faker.word(),
239+
else unique_repo_name(faker=faker, remote_repos_path=remote_repos_path),
223240
remote_repo_post_init=remote_repo_post_init,
224241
)
225242

@@ -277,7 +294,7 @@ def fn(
277294
remote_repos_path=remote_repos_path,
278295
remote_repo_name=remote_repo_name
279296
if remote_repo_name is not None
280-
else faker.word(),
297+
else unique_repo_name(faker=faker, remote_repos_path=remote_repos_path),
281298
remote_repo_post_init=remote_repo_post_init,
282299
)
283300

0 commit comments

Comments
 (0)