Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Blame · server/history_test.go

Line attribution on main · 57 line(s)

67a308ba
Keenan Nemetz
15d ago
1 package server_test
2
3 import (
4 "os"
5 "path/filepath"
6 "strings"
7 "testing"
8 )
9
10 func TestFileHistoryAndBlame(t *testing.T) {
11 t.Parallel()
12 f := newFixture(t)
13 f.publish(f.repo)
14 work := workRepo(t, map[string]string{"readme.md": "v1 line\nkeep me\n"})
15 if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil {
16 t.Fatalf("initial push: %s", errs)
17 }
18 if err := os.WriteFile(filepath.Join(work, "readme.md"), []byte("v2 line\nkeep me\nbrand new\n"), 0o644); err != nil {
19 t.Fatal(err)
20 }
21 if _, errs, err := runGit(t, work, "commit", "-qam", "change the readme"); err != nil {
22 t.Fatalf("commit: %s", errs)
23 }
24 if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil {
25 t.Fatalf("second push: %s", errs)
26 }
27
ed03b3d1
Keenan Nemetz
4h ago
28 code, body := f.get("/" + f.repo + "/commits/main/readme.md")
67a308ba
Keenan Nemetz
15d ago
29 if code != 200 {
30 t.Fatalf("history = %d", code)
31 }
32 for _, want := range []string{"readme.md", "change the readme", "initial"} {
33 if !strings.Contains(body, want) {
34 t.Fatalf("history does not show %q:\n%s", want, body)
35 }
36 }
37
ed03b3d1
Keenan Nemetz
4h ago
38 code, body = f.get("/" + f.repo + "/blame/main/readme.md")
67a308ba
Keenan Nemetz
15d ago
39 if code != 200 {
40 t.Fatalf("blame = %d", code)
41 }
42 for _, want := range []string{"v2 line", "brand new", "keep me", "t"} {
43 if !strings.Contains(body, want) {
44 t.Fatalf("blame does not show %q:\n%s", want, body)
45 }
46 }
47
ed03b3d1
Keenan Nemetz
4h ago
48 if code, body := f.get("/" + f.repo + "/blob/main/readme.md"); code != 200 || !strings.Contains(body, "/blame/main/readme.md") || !strings.Contains(body, "/commits/main/readme.md") {
67a308ba
Keenan Nemetz
15d ago
49 t.Fatalf("blob page has no history/blame links: %d\n%s", code, body)
50 }
ed03b3d1
Keenan Nemetz
4h ago
51 if code, _ := f.get("/" + f.repo + "/commits/main/nope.md"); code != 404 {
67a308ba
Keenan Nemetz
15d ago
52 t.Fatalf("unknown file history = %d, want 404", code)
53 }
ed03b3d1
Keenan Nemetz
4h ago
54 if code, _ := f.get("/" + f.repo + "/blame/main/nope.md"); code != 404 {
67a308ba
Keenan Nemetz
15d ago
55 t.Fatalf("unknown blame = %d, want 404", code)
56 }
57 }