Skip to content

Commit ac26ec9

Browse files
authored
Merge pull request #4 from OpenNeuroOrg/fix/github-mirror-errors
fix: distinguish error cases in list_refs
2 parents 68cf92e + f50d7ae commit ac26ec9

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/ondiagnostics/tasks/git.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,29 @@ async def check_remote(dataset: Dataset) -> Dataset | None:
6666
return dataset
6767

6868

69-
async def list_refs(repo_url: str) -> GitRefs | None:
69+
async def list_refs(repo_url: str) -> GitRefs | str:
7070
"""Run git ls-remote --symref and return structured ref map.
7171
72-
Returns None if the repository is not found or the command fails.
72+
Returns a string sentinel on failure:
73+
- ``"repo-not-found"`` – the remote repository does not exist.
74+
- ``"command-failed"`` – git ls-remote exited with a non-zero status.
75+
- ``"repo-empty"`` – the repository exists but has no refs.
7376
"""
7477
log = logger.bind(repo_url=repo_url)
7578

7679
result = await git("ls-remote", "--symref", repo_url)
7780

7881
if result.returncode:
79-
if b"Repository not found" in result.stderr:
82+
if b"fatal:" in result.stderr and b"not found" in result.stderr:
8083
log.error("Missing repository")
84+
return "repo-not-found"
8185
else:
8286
log.error("git ls-remote failed", returncode=result.returncode)
83-
return None
87+
return "command-failed"
8488

8589
if not result.stdout.strip():
8690
log.error("Empty response from git ls-remote")
87-
return None
91+
return "repo-empty"
8892

8993
lines = result.stdout.decode().strip().split("\n")
9094
head_ref = None

tests/test_tasks_git.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,32 +238,32 @@ async def test_list_refs_no_symref() -> None:
238238

239239

240240
async def test_list_refs_empty_response() -> None:
241-
"""Test that an empty response returns None."""
241+
"""Test that an empty response returns correct string."""
242242
with patch("ondiagnostics.tasks.git.git") as mock_git:
243243
mock_git.return_value = SubprocessResult((), 0, b" ", b"")
244244

245245
result = await list_refs("https://github.com/example/repo.git")
246246

247-
assert result is None
247+
assert result == 'repo-empty'
248248

249249

250250
async def test_list_refs_repository_not_found() -> None:
251-
"""Test that a missing repository returns None."""
251+
"""Test that a missing repository returns correct string."""
252252
with patch("ondiagnostics.tasks.git.git") as mock_git:
253253
mock_git.return_value = SubprocessResult(
254-
(), 128, b"", b"Repository not found."
254+
(), 128, b"", b"fatal: Repository not found."
255255
)
256256

257257
result = await list_refs("https://github.com/example/missing.git")
258258

259-
assert result is None
259+
assert result == 'repo-not-found'
260260

261261

262262
async def test_list_refs_nonzero_exit_code() -> None:
263-
"""Test that a non-zero exit code returns None."""
263+
"""Test that a non-zero exit code returns correct string."""
264264
with patch("ondiagnostics.tasks.git.git") as mock_git:
265265
mock_git.return_value = SubprocessResult((), 1, b"", b"some error")
266266

267267
result = await list_refs("https://github.com/example/repo.git")
268268

269-
assert result is None
269+
assert result == 'command-failed'

0 commit comments

Comments
 (0)