mirror of
https://github.com/open-webui/computer.git
synced 2026-11-22 21:50:43 -05:00
refac
This commit is contained in:
1 parent
bcfac08952
commit
08d2afffc5
4 files changed
+80
-21
No files matched your search
+31
-18
@@ -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()),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user