Handle empty repositories during startup
272b954a351e69220be744cae67a22948fd1eb25
1 parent
6831e2e7
git_cli.go
+1 -1
| 89 | 89 | return branch |
|
| 90 | 90 | } |
|
| 91 | 91 | } |
|
| 92 | 92 | ||
| 93 | 93 | // Fall back to the first available branch. |
|
| 94 | - | branches, err := g.getBranches() |
|
| 94 | + | branches, err := g.getBranchRefs() |
|
| 95 | 95 | if err == nil && len(branches) > 0 { |
|
| 96 | 96 | return branches[0].Name |
|
| 97 | 97 | } |
|
| 98 | 98 | return "master" |
|
| 99 | 99 | } |
+0 -0
handler_test.go
+21 -0
| 1375 | 1375 | if repo.LastUpdated.IsZero() { |
|
| 1376 | 1376 | t.Error("expected non-zero LastUpdated") |
|
| 1377 | 1377 | } |
|
| 1378 | 1378 | } |
|
| 1379 | 1379 | ||
| 1380 | + | func TestScanRepositories_EmptyPublic(t *testing.T) { |
|
| 1381 | + | tmpDir := t.TempDir() |
|
| 1382 | + | repoDir := filepath.Join(tmpDir, "empty.git") |
|
| 1383 | + | gitRun(t, "", "init", "--bare", repoDir) |
|
| 1384 | + | if err := os.WriteFile(filepath.Join(repoDir, "public"), nil, 0644); err != nil { |
|
| 1385 | + | t.Fatal(err) |
|
| 1386 | + | } |
|
| 1387 | + | ||
| 1388 | + | repos, err := scanRepositories(tmpDir, false) |
|
| 1389 | + | if err != nil { |
|
| 1390 | + | t.Fatalf("scanRepositories: %v", err) |
|
| 1391 | + | } |
|
| 1392 | + | repo := repos["empty"] |
|
| 1393 | + | if repo == nil { |
|
| 1394 | + | t.Fatal("expected empty repository") |
|
| 1395 | + | } |
|
| 1396 | + | if !repo.LastUpdated.IsZero() { |
|
| 1397 | + | t.Error("expected zero LastUpdated") |
|
| 1398 | + | } |
|
| 1399 | + | } |
|
| 1400 | + | ||
| 1380 | 1401 | func TestScanRepositories_SkipsPrivate(t *testing.T) { |
|
| 1381 | 1402 | tmpDir := t.TempDir() |
|
| 1382 | 1403 | gitRun(t, "", "init", "--bare", filepath.Join(tmpDir, "private.git")) |
|
| 1383 | 1404 | repos, _ := scanRepositories(tmpDir, false) |
|
| 1384 | 1405 | if len(repos) != 0 { |
file.go
+0 -0
old.go
+0 -0
new.go
+0 -0
image.png
+0 -0
file.go
+0 -0
a.go
+0 -0
b.go
+0 -0