v0.6.0 d5cc8fe

refs_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import (
6	"testing"
7
8	"github.com/stretchr/testify/assert"
9
10	pb "bnema.dev/ermite-api/gen/ermite"
11)
12
13func ref(kind pb.RefKind, short string) *pb.Ref {
14	return &pb.Ref{Name: "refs/x/" + short, ShortName: short, Kind: kind, CommitId: "c-" + short}
15}
16
17// AC3: a ref with slashes is found by the longest matching prefix.
18func TestResolveRef(t *testing.T) {
19	b, tag := pb.RefKind_REF_KIND_BRANCH, pb.RefKind_REF_KIND_TAG
20	refs := []*pb.Ref{
21		ref(b, "main"), ref(b, "feature"), ref(b, "feature/x"), ref(b, "feature/x/y"), ref(tag, "v1/rc"),
22		ref(pb.RefKind_REF_KIND_HEAD, "main"), ref(tag, "main"),
23	}
24	tests := []struct {
25		path, ref, rest string
26		kind            pb.RefKind
27		ok              bool
28	}{
29		{"main", "main", "", b, true},
30		{"main/src/a.go", "main", "src/a.go", b, true},
31		{"feature/x/y/z.txt", "feature/x/y", "z.txt", b, true},
32		{"feature/x/z.txt", "feature/x", "z.txt", b, true},
33		{"feature/other", "feature", "other", b, true},
34		{"/feature/x/", "feature/x", "", b, true},
35		{"v1/rc/README", "v1/rc", "README", tag, true},
36		{"v1/README", "", "", 0, false},
37		{"nope/main", "", "", 0, false},
38		{"", "", "", 0, false},
39	}
40	for _, tt := range tests {
41		t.Run(tt.path, func(t *testing.T) {
42			r, rest, ok := resolveRef(refs, tt.path)
43			assert.Equal(t, tt.ok, ok)
44			if !ok {
45				return
46			}
47			assert.Equal(t, tt.ref, r.GetShortName())
48			assert.Equal(t, tt.kind, r.GetKind(), "a branch wins over a tag of the same name")
49			assert.Equal(t, tt.rest, rest)
50		})
51	}
52}
53
54func TestRepoHref(t *testing.T) {
55	assert.Equal(t, "/demo", repoHref("demo"))
56	assert.Equal(t, "/demo/tree/feature/x/a%20b/c%23.go", repoHref("demo", "tree", "feature/x", "a b/c#.go"))
57	assert.Equal(t, "/demo/blob/main/%3Fq", repoHref("demo", "blob", "main", "", "?q"))
58}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 2

Tags 45

↑↓ moveenter openesc close