This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-06 01:12:39 -04:00
1 parent cdbd446813
commit d21a3bcf86
13 files changed
+628 -26

No files matched your search

+23 -2
View File
@@ -204,10 +204,31 @@ async def unstage(root: str, files: list[str]) -> None:
async def discard(root: str, files: list[str]) -> None:
"""Discard unstaged changes in files."""
"""Discard changes in files. Tracked files are restored via git checkout;
untracked files are deleted from disk."""
if not files:
return
await _run("checkout", "--", *files, cwd=root)
# Determine which files are untracked
_, st_out, _ = await _run(
"status", "--porcelain=v2", "--untracked-files=all",
cwd=root, check=False,
)
untracked = set()
for line in st_out.splitlines():
if line.startswith("? "):
untracked.add(line[2:])
tracked = [f for f in files if f not in untracked]
to_delete = [f for f in files if f in untracked]
if tracked:
await _run("checkout", "--", *tracked, cwd=root)
for f in to_delete:
full = os.path.join(root, f)
if os.path.isfile(full):
os.remove(full)
async def commit(root: str, message: str) -> dict[str, str]: