phase 3 bug repositories fixes

This commit is contained in:
2026-05-07 01:15:32 +02:00
parent 200c4f43ea
commit 44359c1bb0
29 changed files with 1223 additions and 51 deletions
+12
View File
@@ -45,6 +45,14 @@ func run(repoPath string, args ...string) ([]byte, error) {
return out, nil
}
// IsEmpty returns true when the repo has no commits yet.
// Must use --verify: without it, rev-parse exits 0 in a bare empty repo
// because HEAD is a valid symbolic ref even before the first commit.
func IsEmpty(repoPath string) bool {
_, err := run(repoPath, "rev-parse", "--verify", "HEAD")
return err != nil
}
func Init(path string) error {
// git init --bare works even if the directory doesn't exist yet
cmd := exec.Command("git", "init", "--bare", path)
@@ -101,6 +109,10 @@ type TreeEntry struct {
}
func TreeLS(repoPath, ref, subPath string) ([]TreeEntry, error) {
// Short-circuit for repos with no commits yet.
if IsEmpty(repoPath) {
return nil, nil
}
treeRef := ref
if subPath != "" {
treeRef = ref + ":" + subPath