feat(cc): improve UI + branch detection
This commit is contained in:
+1269
-101
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,15 @@ import tempfile
|
|||||||
import unittest
|
import unittest
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from conflict_catcher import CheckError, check_conflicts, parse_branch_spec, run_git
|
from conflict_catcher import (
|
||||||
|
CheckError,
|
||||||
|
check_conflicts,
|
||||||
|
compare_freshness,
|
||||||
|
generate_report,
|
||||||
|
list_branches,
|
||||||
|
parse_branch_spec,
|
||||||
|
run_git,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def git(repo: Path, *args: str) -> None:
|
def git(repo: Path, *args: str) -> None:
|
||||||
@@ -59,6 +67,56 @@ class ConflictCatcherTests(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_lists_branches_and_reports_freshness(self) -> None:
|
||||||
|
with tempfile.TemporaryDirectory() as temp:
|
||||||
|
origin = Path(temp) / "origin.git"
|
||||||
|
repo = Path(temp) / "repo"
|
||||||
|
|
||||||
|
git(Path(temp), "init", "--bare", str(origin))
|
||||||
|
git(Path(temp), "clone", str(origin), str(repo))
|
||||||
|
git(repo, "checkout", "-b", "main")
|
||||||
|
git(repo, "config", "user.email", "test@example.com")
|
||||||
|
git(repo, "config", "user.name", "Test User")
|
||||||
|
write(repo / "note.txt", "base\n")
|
||||||
|
git(repo, "add", "note.txt")
|
||||||
|
git(repo, "commit", "-m", "base")
|
||||||
|
git(repo, "push", "-u", "origin", "main")
|
||||||
|
git(repo, "checkout", "-b", "develop")
|
||||||
|
|
||||||
|
branches = list_branches(repo)
|
||||||
|
self.assertEqual(branches["current"], "develop")
|
||||||
|
self.assertIn("main", branches["local"])
|
||||||
|
self.assertIn("develop", branches["local"])
|
||||||
|
self.assertIn("origin/main", branches["remote"])
|
||||||
|
|
||||||
|
freshness = compare_freshness(repo, "main", "develop")
|
||||||
|
self.assertEqual(freshness[0]["state"], "ok")
|
||||||
|
self.assertEqual(freshness[1]["state"], "unknown")
|
||||||
|
|
||||||
|
def test_generates_markdown_report(self) -> None:
|
||||||
|
report = generate_report(
|
||||||
|
{
|
||||||
|
"repo": "C:/repo",
|
||||||
|
"target": "main",
|
||||||
|
"source": "feature",
|
||||||
|
"targetSha": "abc123",
|
||||||
|
"sourceSha": "def456",
|
||||||
|
"freshness": [{"summary": "main is up to date with origin/main."}],
|
||||||
|
"checks": [
|
||||||
|
{
|
||||||
|
"ok": False,
|
||||||
|
"operation": "merge",
|
||||||
|
"summary": "feature would conflict when merged into main.",
|
||||||
|
"conflicts": [{"status": "UU", "meaning": "both modified", "path": "note.txt"}],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIn("# Conflict Catcher Report", report)
|
||||||
|
self.assertIn("Target/base: `main`", report)
|
||||||
|
self.assertIn("| UU | both modified | `note.txt` |", report)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user