v0.28.1 cc7ba64

revision_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain_test
4
5import (
6	"strings"
7	"testing"
8
9	"github.com/stretchr/testify/assert"
10	"github.com/stretchr/testify/require"
11
12	"bnema.dev/ermite/internal/domain"
13)
14
15func TestRevisionCandidates(t *testing.T) {
16	full := strings.Repeat("a", 40)
17	ref := func(s string) domain.RevisionCandidate {
18		return domain.RevisionCandidate{Kind: domain.RevisionCandidateRef, Name: s}
19	}
20	branches := func(s string) []domain.RevisionCandidate {
21		return []domain.RevisionCandidate{ref("refs/heads/" + s), ref("refs/tags/" + s)}
22	}
23	for _, tt := range []struct {
24		name, text string
25		want       []domain.RevisionCandidate
26	}{
27		{"zero HEAD", "", []domain.RevisionCandidate{{Kind: domain.RevisionCandidateHead, Name: "HEAD"}}},
28		{"explicit HEAD", "HEAD", []domain.RevisionCandidate{{Kind: domain.RevisionCandidateHead, Name: "HEAD"}}},
29		{"full object first", full, append([]domain.RevisionCandidate{{Kind: domain.RevisionCandidateObject, Name: full}}, branches(full)...)},
30		{"full branch ref last", "refs/heads/main", append(branches("refs/heads/main"), ref("refs/heads/main"))},
31		{"full tag ref last", "refs/tags/v1", append(branches("refs/tags/v1"), ref("refs/tags/v1"))},
32		{"other full ref last", "refs/custom/x", append(branches("refs/custom/x"), ref("refs/custom/x"))},
33		{"minimum abbreviation last", "abc1234", append(branches("abc1234"), domain.RevisionCandidate{Kind: domain.RevisionCandidateAbbrevID, Name: "abc1234"})},
34		{"maximum abbreviation last", full[:39], append(branches(full[:39]), domain.RevisionCandidate{Kind: domain.RevisionCandidateAbbrevID, Name: full[:39]})},
35		{"short hex is ref", "abc123", branches("abc123")},
36		{"uppercase hex is ref", "ABC1234", branches("ABC1234")},
37		{"ordinary name", "main", branches("main")},
38		{"slash name", "feature/x", branches("feature/x")},
39	} {
40		t.Run(tt.name, func(t *testing.T) {
41			r, err := domain.ParseRevision(tt.text)
42			require.NoError(t, err)
43			assert.Equal(t, tt.want, r.Candidates())
44		})
45	}
46}
47
48func TestRevisionCandidateResolvedRef(t *testing.T) {
49	for _, tc := range []struct {
50		kind domain.RevisionCandidateKind
51		want string
52	}{
53		{domain.RevisionCandidateHead, ""}, {domain.RevisionCandidateObject, ""},
54		{domain.RevisionCandidateRef, "refs/heads/main"}, {domain.RevisionCandidateAbbrevID, ""},
55	} {
56		assert.Equal(t, tc.want, (domain.RevisionCandidate{Kind: tc.kind, Name: "refs/heads/main"}).ResolvedRef())
57	}
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 44

↑↓ moveenter openesc close