v0.3.0 9fdf386

commits_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import (
6	"errors"
7	"net/http"
8	"testing"
9
10	"github.com/stretchr/testify/assert"
11	"github.com/stretchr/testify/require"
12
13	pb "bnema.dev/ermite-api/gen/ermite"
14	"bnema.dev/ermite-api/gen/ermite/ermiteconnect"
15)
16
17func TestIsCommitID(t *testing.T) {
18	for _, s := range []string{"abcdef0", "0123456789abcdef0123456789abcdef01234567"} {
19		assert.True(t, isCommitID(s), s)
20	}
21	for _, s := range []string{"", "abcdef", "ABCDEF0", "main", "abcdefg", "0123456789abcdef0123456789abcdef012345678"} {
22		assert.False(t, isCommitID(s), s)
23	}
24}
25
26// The ref switcher marks the ref the page shows, whatever the page: a tag, a
27// branch other than the default one, or none for a commit.
28func TestPinRefMarksCurrent(t *testing.T) {
29	b, tag := pb.RefKind_REF_KIND_BRANCH, pb.RefKind_REF_KIND_TAG
30	d := &repoData{
31		repo:     &pb.Repo{Name: "demo", DefaultBranch: "main"},
32		branches: []*pb.Ref{ref(b, "main"), ref(b, "side")},
33		tags:     []*pb.Ref{ref(tag, "v1")},
34	}
35	d.head = d.branches[0]
36	s, err := New(Config{
37		Repos: failing{err: errors.New("no list")}, Git: ermiteconnect.NewGitServiceClient(http.DefaultClient, "http://unused.invalid"),
38		PublicURL: "https://forge.example", SourceURL: "https://forge.example/ermite", Version: "v1",
39	})
40	require.NoError(t, err)
41	current := func(items []RefItem) (names []string) {
42		for _, it := range items {
43			if it.Current {
44				names = append(names, it.Name)
45			}
46		}
47		return names
48	}
49	for _, tt := range []struct {
50		rest        string
51		heads, tags []string
52		ref, short  string
53	}{
54		{"", []string{"main"}, nil, "main", "c-main"},
55		{"v1", nil, []string{"v1"}, "v1", "c-v1"},
56		{"side", []string{"side"}, nil, "side", "c-side"},
57		{"abcdef0123", nil, nil, "detached", "abcdef0"},
58	} {
59		tg, ok := d.locate(tt.rest)
60		require.True(t, ok, tt.rest)
61		l := s.repoLayout(t.Context(), d, "commits")
62		pinRef(&l, tg)
63		assert.Equal(t, tt.heads, current(l.Heads), tt.rest)
64		assert.Equal(t, tt.tags, current(l.Tags), tt.rest)
65		assert.Equal(t, tt.ref, l.Ref, tt.rest)
66		assert.Equal(t, tt.short, l.Short, tt.rest)
67	}
68}

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