This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-17 11:18:55 +02:00
1 parent bcfac08952
commit 08d2afffc5
4 files changed
+80 -21

No files matched your search

+31 -18
View File
@@ -68,7 +68,32 @@ async def status(root: str) -> dict[str, Any]:
ahead = 0
behind = 0
has_ab = False
files: list[dict] = []
files_by_path: dict[str, dict[str, Any]] = {}
def add_file(
path: str,
status_text: str,
*,
staged: bool = False,
unstaged: bool = False,
) -> None:
entry = files_by_path.setdefault(
path,
{
"path": path,
"status": status_text,
"staged": False,
"unstaged": False,
},
)
if staged:
entry["staged"] = True
entry["staged_status"] = status_text
if unstaged:
entry["unstaged"] = True
entry["unstaged_status"] = status_text
# Prefer the working-tree status for the row label when both sides exist.
entry["status"] = status_text
for line in out.splitlines():
if line.startswith("# branch.head "):
@@ -94,30 +119,18 @@ async def status(root: str) -> dict[str, Any]:
staged_code = xy[0]
unstaged_code = xy[1]
if staged_code != ".":
files.append(
{
"path": path,
"status": _status_char(staged_code),
"staged": True,
}
)
add_file(path, _status_char(staged_code), staged=True)
if unstaged_code != ".":
files.append(
{
"path": path,
"status": _status_char(unstaged_code),
"staged": False,
}
)
add_file(path, _status_char(unstaged_code), unstaged=True)
elif line.startswith("? "):
# Untracked
path = line[2:]
files.append({"path": path, "status": "untracked", "staged": False})
add_file(path, "untracked", unstaged=True)
elif line.startswith("u "):
# Unmerged
parts = line.split(" ", 10)
path = parts[-1]
files.append({"path": path, "status": "conflict", "staged": False})
add_file(path, "conflict", unstaged=True)
# upstream is set but remote branch doesn't exist yet (no ab line)
# — treat as unpublished so the frontend shows "Publish"
@@ -136,7 +149,7 @@ async def status(root: str) -> dict[str, Any]:
"remote_url": remote_url,
"ahead": ahead,
"behind": behind,
"files": files,
"files": list(files_by_path.values()),
}