v0.32.0 53e25a3

commits_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import (
6	"errors"
7	"testing"
8
9	"github.com/stretchr/testify/assert"
10	"github.com/stretchr/testify/mock"
11	"github.com/stretchr/testify/require"
12
13	"bnema.dev/ermite/internal/domain"
14	"bnema.dev/ermite/internal/ports"
15	"bnema.dev/ermite/internal/ports/mocks"
16)
17
18func TestIsCommitID(t *testing.T) {
19	t.Parallel()
20	for _, s := range []string{"abcdef0", "0123456789abcdef0123456789abcdef01234567"} {
21		assert.True(t, isCommitID(s), s)
22	}
23	for _, s := range []string{"", "abcdef", "ABCDEF0", "main", "abcdefg", "0123456789abcdef0123456789abcdef012345678"} {
24		assert.False(t, isCommitID(s), s)
25	}
26}
27
28// The ref switcher marks the ref the page shows, whatever the page: a tag, a
29// branch other than the default one, or none for a commit.
30func TestPinRefMarksCurrent(t *testing.T) {
31	t.Parallel()
32	b, tag := domain.RefKindBranch, domain.RefKindTag
33	name, err := domain.ParseRepoName("demo")
34	require.NoError(t, err)
35	d := &repoData{
36		repo:     ports.RepoView{Repo: domain.Repo{Name: name}, DefaultBranch: "main"},
37		branches: []domain.Ref{ref(b, "main"), ref(b, "side")},
38		tags:     []domain.Ref{ref(tag, "v1")},
39	}
40	d.head = &d.branches[0]
41	// The list of the other repositories is not reachable: the layout does
42	// without it.
43	repos := mocks.NewRepoService(t)
44	repos.EXPECT().ListPage(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(ports.RepoPage{}, errors.New("no list"))
45	s, err := New(Config{
46		Repos: repos, Browse: mocks.NewBrowseService(t),
47		PublicURL: "https://forge.example", SourceURL: "https://forge.example/ermite", Version: "v1",
48	})
49	require.NoError(t, err)
50	current := func(items []RefItem) (names []string) {
51		for _, it := range items {
52			if it.Current {
53				names = append(names, it.Name)
54			}
55		}
56		return names
57	}
58	for _, tt := range []struct {
59		rest        string
60		heads, tags []string
61		ref, short  string
62	}{
63		{"", []string{"main"}, nil, "main", short(commitOf("main").String())},
64		{"v1", nil, []string{"v1"}, "v1", short(commitOf("v1").String())},
65		{"side", []string{"side"}, nil, "side", short(commitOf("side").String())},
66		{"abcdef0123", nil, nil, "detached", "abcdef0"},
67	} {
68		tg, ok := d.locate(tt.rest)
69		require.True(t, ok, tt.rest)
70		l := s.repoLayout(t.Context(), d, "commits")
71		pinRef(&l, tg)
72		assert.Equal(t, tt.heads, current(l.Heads), tt.rest)
73		assert.Equal(t, tt.tags, current(l.Tags), tt.rest)
74		assert.Equal(t, tt.ref, l.Ref, tt.rest)
75		assert.Equal(t, tt.short, l.Short, tt.rest)
76	}
77}

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