s
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package gitcmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEmptyRepoReturnsEmpty(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
repoPath := filepath.Join(dir, "empty.git")
|
||||
if err := os.MkdirAll(repoPath, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if out, err := exec.Command("git", "init", "--bare", repoPath).CombinedOutput(); err != nil {
|
||||
t.Fatalf("git init --bare: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
r, err := OpenRepository(context.Background(), repoPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if empty, err := r.IsEmpty(); err != nil || !empty {
|
||||
t.Fatalf("IsEmpty() = (%v, %v), want (true, nil)", empty, err)
|
||||
}
|
||||
|
||||
commits, err := r.ListCommits("HEAD", 20)
|
||||
if err != nil {
|
||||
t.Fatalf("ListCommits on empty repo: %v", err)
|
||||
}
|
||||
if len(commits) != 0 {
|
||||
t.Fatalf("ListCommits = %d items, want 0", len(commits))
|
||||
}
|
||||
|
||||
tree, err := r.GetTree("HEAD", "")
|
||||
if err != nil {
|
||||
t.Fatalf("GetTree on empty repo: %v", err)
|
||||
}
|
||||
if len(tree.Entries) != 0 {
|
||||
t.Fatalf("GetTree = %d entries, want 0", len(tree.Entries))
|
||||
}
|
||||
|
||||
contribs, err := r.GetContributors("HEAD")
|
||||
if err != nil {
|
||||
t.Fatalf("GetContributors on empty repo: %v", err)
|
||||
}
|
||||
if len(contribs) != 0 {
|
||||
t.Fatalf("GetContributors = %d items, want 0", len(contribs))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user