1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package readertest
4
5import "testing"
6
7// History is the repository of the read tests: three commits on main, a
8// branch with a slash, a merge, lightweight and annotated tags.
9type History struct {
10 *Fixture
11 C1, C2, C3, Side, Merge string
12}
13
14func NewHistory(t *testing.T, data string) *History {
15 t.Helper()
16 f := NewFixture(t, data, "hist")
17 h := &History{Fixture: f}
18 f.Write("a.txt", "one\ntwo\nthree\n").
19 WriteBytes("bin", []byte{0, 1}).
20 Write("d/f", "hi\n").
21 Write("d/sub/g", "deep\n").
22 Write("we:ird*.txt", "x").
23 Write("README.md", "# hello\n").
24 Write("empty", "")
25 h.C1 = f.Commit("first\n\nbody of the first commit\n")
26
27 f.Mv("a.txt", "b.txt").Write("b.txt", "one\ntwo\nthree\nfour\n").
28 WriteBytes("bin", []byte{0, 2}).
29 Chmod("d/f", 0o755).
30 Write("n.txt", "new\nnonl").
31 Remove("README.md")
32 h.C2 = f.Commit("second")
33
34 f.Remove("n.txt").Symlink("b.txt", "n.txt")
35 h.C3 = f.Commit("third: type change")
36
37 f.CheckoutNew("feature/x")
38 f.Write("side.txt", "s\n")
39 h.Side = f.Commit("side work")
40 f.Checkout("main")
41 f.Write("main.txt", "m\n")
42 f.Commit("main work")
43 h.Merge = f.Merge("feature/x")
44
45 f.Git("tag", "v1", h.C1)
46 f.Git("tag", "-a", "-m", "release two", "v2", h.C2)
47 f.Git("tag", "-a", "-m", "tag of a tag", "v2-again", "v2")
48 f.Git("tag", "-a", "-m", "tag of a tree", "tree-tag", h.Merge+"^{tree}")
49 f.Git("branch", "release/1.0", h.C2)
50 f.Git("branch", "rel/1", h.C1)
51 f.Git("tag", "rel/1/x", h.C3)
52 return h
53}