Write-tree delete all before read
This commit is contained in:
parent
40a19615aa
commit
c72370f930
21
ugit/base.py
21
ugit/base.py
@ -1,4 +1,5 @@
|
||||
from pathlib import Path, PurePath
|
||||
import os
|
||||
|
||||
from . import data
|
||||
|
||||
@ -48,7 +49,27 @@ def get_tree(oid, base_path=""):
|
||||
return result
|
||||
|
||||
|
||||
def _empty_current_directory():
|
||||
for root, dirnames, filenames in os.walk(".", topdown=False):
|
||||
for filename in filenames:
|
||||
path = PurePath.relative_to(f"{root}/{filename}")
|
||||
if is_ignored(path) or not Path.is_file(path):
|
||||
continue
|
||||
Path.unlink(path)
|
||||
for dirname in dirnames:
|
||||
path = PurePath.relative_to(f"{root}/{dirname}")
|
||||
if is_ignored(path):
|
||||
continue
|
||||
try:
|
||||
Path.rmdir(path)
|
||||
except (FileNotFoundError, OSError):
|
||||
# Deletion might fail if the directory contains ignored files,
|
||||
# so it's OK
|
||||
pass
|
||||
|
||||
|
||||
def read_tree(tree_oid):
|
||||
_empty_current_directory()
|
||||
for path, oid in get_tree(tree_oid, base_path="./").items():
|
||||
Path.mkdir(PurePath.parent(path), exist_ok=True)
|
||||
with open(path, "wb") as f:
|
||||
|
Loading…
Reference in New Issue
Block a user