This commit is contained in:
@@ -38,8 +38,11 @@ def test_run_git_diff_falls_back_to_origin_refs_after_fetch():
|
||||
def fake_run(cmd, check=False, capture_output=False, text=False): # type: ignore[override]
|
||||
nonlocal fetched
|
||||
if cmd[3] == "diff":
|
||||
diff_attempts.append(cmd[4])
|
||||
spec = cmd[4]
|
||||
if len(cmd) == 7:
|
||||
spec = cmd[4]
|
||||
else:
|
||||
spec = " ".join(cmd[4:6])
|
||||
diff_attempts.append(spec)
|
||||
if spec == "origin/base...origin/head" and fetched:
|
||||
return _completed(cmd, 0, stdout="remote-ok")
|
||||
return _completed(cmd, 128, stderr="missing ref")
|
||||
@@ -55,3 +58,29 @@ def test_run_git_diff_falls_back_to_origin_refs_after_fetch():
|
||||
assert "origin/base...origin/head" in diff_attempts
|
||||
# Ensure the fallback only succeeds after fetch.
|
||||
assert diff_attempts.index("origin/base...origin/head") > diff_attempts.index("base...head")
|
||||
|
||||
|
||||
def test_run_git_diff_fallbacks_to_two_dot_when_merge_base_missing():
|
||||
fetched = False
|
||||
diff_attempts: list[str] = []
|
||||
|
||||
def fake_run(cmd, check=False, capture_output=False, text=False): # type: ignore[override]
|
||||
nonlocal fetched
|
||||
if cmd[3] == "diff":
|
||||
if len(cmd) == 7:
|
||||
spec = cmd[4]
|
||||
diff_attempts.append(f"sym:{spec}")
|
||||
return _completed(cmd, 128, stderr="fatal: origin/main...origin/head: no merge base")
|
||||
spec = " ".join(cmd[4:6])
|
||||
diff_attempts.append(f"two:{spec}")
|
||||
return _completed(cmd, 0, stdout="linear-diff")
|
||||
if cmd[3] == "fetch":
|
||||
fetched = True
|
||||
return _completed(cmd, 0)
|
||||
raise AssertionError("unexpected git invocation")
|
||||
|
||||
with patch("ai_reviewer.diff.subprocess.run", side_effect=fake_run):
|
||||
output = run_git_diff(".", "base", "head")
|
||||
|
||||
assert output == "linear-diff"
|
||||
assert any(attempt.startswith("two:") for attempt in diff_attempts)
|
||||
|
||||
Reference in New Issue
Block a user