v0.10.1 e4c85c7

gitreader_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package app
4
5import (
6	"os"
7	"strings"
8	"testing"
9
10	"github.com/stretchr/testify/assert"
11	"github.com/stretchr/testify/require"
12
13	"bnema.dev/ermite/internal/config"
14	"bnema.dev/ermite/internal/domain"
15	"bnema.dev/ermite/internal/ports"
16)
17
18// The suite runs with the reader of ERMITE_GIT_READER (ermite-git by default).
19// This test says which one that is, so that a run cannot claim a reader it did
20// not exercise, and checks the read-after-push guarantee through the real
21// HTTP push path and the browse use case.
22func TestGitReaderOfTheForgeAndReadAfterPush(t *testing.T) {
23	h := newHarness(t, harnessOpts{})
24	want := os.Getenv(config.EnvGitReader)
25	if want == "" {
26		want = config.GitReaderErmiteGit
27	}
28	assert.Equal(t, want, h.forge.cfg.GitReader)
29	assert.Equal(t, want == config.GitReaderErmiteGit, h.forge.reader != nil, "the ermite-git adapter exists only for ermite-git")
30
31	_, err := h.forge.Repos.Create(h.ctx, domain.Root(), ports.CreateRepoParams{
32		Name: h.name("fresh"), Visibility: domain.VisibilityPublic,
33	})
34	require.NoError(t, err)
35	wt := h.t.TempDir()
36	h.mustGit(wt, "init", "-q", "--initial-branch=main")
37	remote := h.urlAuth(adminToken, "/fresh.git")
38	var last string
39	for _, content := range []string{"one\n", "two\n", "three\n"} {
40		h.writeFile(wt, "f.txt", []byte(content)) // commits
41		h.mustGit(wt, "push", "-q", remote, "main")
42		last = strings.TrimSpace(h.mustGit(wt, "rev-parse", "HEAD"))
43
44		// The very next read, no wait: the browse sees the push.
45		res, err := h.forge.Browse.ResolveRevision(h.ctx, domain.Root(), h.name("fresh"), domain.Revision{})
46		require.NoError(t, err)
47		assert.Equal(t, last, res.CommitID.String())
48		tree, err := h.forge.Browse.GetTree(h.ctx, domain.Root(), h.name("fresh"), domain.Revision{}, domain.TreePath{}, true)
49		require.NoError(t, err)
50		require.Len(t, tree.Entries, 1)
51		assert.Equal(t, last, tree.Entries[0].LastCommit.ID.String())
52	}
53
54	// Deleting the repository drops what the reader holds; a repository of the
55	// same name is a new one.
56	require.NoError(t, h.forge.Repos.Delete(h.ctx, domain.Root(), h.name("fresh")))
57	_, err = h.forge.Browse.ResolveRevision(h.ctx, domain.Root(), h.name("fresh"), domain.Revision{})
58	require.Error(t, err)
59}

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 4

Tags 45

↑↓ moveenter openesc close