1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package server
import (
"os"
"os/exec"
"path/filepath"
"testing"
"custard/internal/config"
"custard/internal/gitread"
)
func gitRun(t *testing.T, dir string, args ...string) {
t.Helper()
c := exec.Command("git", args...)
c.Dir = dir
c.Env = append(c.Environ(),
"GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@x", "GIT_AUTHOR_DATE=2026-01-01T00:00:00",
"GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@x", "GIT_COMMITTER_DATE=2026-01-01T00:00:00")
if out, err := c.CombinedOutput(); err != nil {
t.Fatalf("git %v: %v: %s", args, err, out)
}
}
// bookmarkRepo builds a bare "proj.git" in bookmark mode with one release branch.
func bookmarkRepo(t *testing.T) *Server {
t.Helper()
root := t.TempDir()
work := filepath.Join(root, "work")
gitRun(t, root, "init", "-q", "-b", "main", "work")
if err := os.WriteFile(filepath.Join(work, ".custard.yaml"),
[]byte("brew:\n enabled: true\n source: bookmark\n"), 0o644); err != nil {
t.Fatal(err)
}
gitRun(t, work, "add", ".")
gitRun(t, work, "commit", "-q", "-m", "init")
gitRun(t, work, "checkout", "-q", "-b", "release/v1.2.3")
gitRun(t, work, "commit", "-q", "--allow-empty", "-m", "ship v1.2.3")
gitRun(t, work, "checkout", "-q", "main")
gitRun(t, work, "clone", "-q", "--bare", work, filepath.Join(root, "proj.git"))
return &Server{store: gitread.New(root), cfg: config.Config{ReposPath: root}}
}
func TestLatestReleaseBookmarkMode(t *testing.T) {
s := bookmarkRepo(t)
ref, ok := s.latestRelease("proj")
if !ok || ref.Name != "v1.2.3" {
t.Fatalf("latestRelease = %q,%v; want v1.2.3,true", ref.Name, ok)
}
if ref.Message != "ship v1.2.3" {
t.Errorf("label = %q, want tip subject", ref.Message)
}
}
|