phase 3 bug repositories fixes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user