fix(git): handle empty repositories gracefully and show empty state in UI
This commit is contained in:
@@ -72,7 +72,15 @@ def list_tree(repo_path: str, branch: str = "main", path: str = "") -> list[File
|
||||
except RuntimeError:
|
||||
# Try with HEAD if branch doesn't exist
|
||||
tree_path = f"HEAD:{path}" if path else "HEAD"
|
||||
output = _run_git_command(repo_path, "ls-tree", "-l", tree_path)
|
||||
try:
|
||||
output = _run_git_command(repo_path, "ls-tree", "-l", tree_path)
|
||||
except RuntimeError as e:
|
||||
# Check if this is an empty repository (no commits yet)
|
||||
error_msg = str(e).lower()
|
||||
if "not a valid object name" in error_msg or "does not exist" in error_msg:
|
||||
# Empty repository - return empty list
|
||||
return []
|
||||
raise
|
||||
|
||||
entries = []
|
||||
for line in output.strip().split("\n"):
|
||||
|
||||
@@ -364,6 +364,9 @@ const FileBrowser = ({
|
||||
<Icon name="folder" size="sm" /> ..
|
||||
</button>
|
||||
)}
|
||||
{entries.length === 0 && (
|
||||
<p className="muted">No files in this repository yet.</p>
|
||||
)}
|
||||
{entries.map((entry) => {
|
||||
const fileStatus = entry.type === "file" ? getFileStatus(entry.path) : null;
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user