fix: resolve the --changed base in one place

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:02:11 +01:00
1 parent 30113783c9
commit d3d82dd296
5 files changed
+75 -25

No files matched your search

+46
View File
@@ -65,6 +65,52 @@ class GitThatCannotAnswer(unittest.TestCase):
self.assertIn("untracked files only", proc.stderr)
class AProjectMainThatCannotBeFetched(unittest.TestCase):
"""profile_sync --changed ended on a RuntimeError traceback where
validate_pr printed one line, in a clone with a non-project remote and
no way to fetch the project's main."""
def test_both_tools_print_one_error_line(self):
import contextlib
import io
import profile_sync
from core import cli, gitclone
def unreachable() -> None:
raise gitclone.MainLineUnreachable("no main")
with mock.patch.object(gitclone, "project_main_line", side_effect=unreachable):
err = io.StringIO()
with contextlib.redirect_stderr(err), self.assertRaises(SystemExit) as ended:
cli.run_cli(profile_sync.project_base)
self.assertEqual(ended.exception.code, 1)
self.assertEqual(err.getvalue(), "ERROR: no main\n")
import validate_pr
with self.assertRaises(RuntimeError):
validate_pr.get_changed_files()
def test_both_tools_compare_against_the_same_line(self):
import profile_sync
import validate_pr
from core import gitclone
diffs: list[tuple[str, ...]] = []
def lines(*args: str) -> list[str] | None:
if args[:3] == ("rev-parse", "--verify", "--quiet"):
return ["x"] if args[3] == "origin/main" else None
diffs.append(args)
return []
with mock.patch.object(gitclone, "project_main_line", return_value=None), \
mock.patch.object(gitclone, "git_lines", side_effect=lines), \
mock.patch.object(validate_pr, "git_lines", side_effect=lines):
self.assertEqual(profile_sync.project_base(), "origin/main")
validate_pr.get_changed_files()
self.assertIn(("diff", "--name-only", "origin/main...HEAD"), diffs)
class ChangesNotYetCommittedAreRead(unittest.TestCase):
"""--changed read only `git diff origin/main...HEAD`: a file copied into
bios/ before any commit, as CONTRIBUTING has it, or committed on a