Demonstrate that the recent repos menu shows ".invalid" for a reftable repo

A repo that keeps its refs in a reftable shows ".invalid" in the branch
column. Git stores the real HEAD in a binary table there and leaves
"ref: refs/heads/.invalid" in the HEAD file, so that anything still
reading the HEAD file fails loudly instead of getting a stale answer.
We read that file and take the placeholder for a branch name.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller 2026-09-14 10:29:32 +02:00
parent 93713b5401
commit 7b5c6f4e12
3 changed files with 54 additions and 0 deletions

View file

@ -66,6 +66,19 @@ func TestReadHeadInfo(t *testing.T) {
expected: headInfo{branch: "mybranch"},
expectedOk: true,
},
{
name: "repo that keeps its refs in a reftable, so HEAD holds a placeholder",
files: map[string]string{
"repo/.git/HEAD": "ref: refs/heads/.invalid\n",
},
/* EXPECTED:
repoPath: "repo",
expectedOk: false,
ACTUAL: */
repoPath: "repo",
expected: headInfo{branch: ".invalid"},
expectedOk: true,
},
{
name: "directory without a .git entry",
repoPath: "notarepo",

View file

@ -0,0 +1,40 @@
package misc
import (
"path/filepath"
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var RecentReposReftableRepo = NewIntegrationTest(NewIntegrationTestArgs{
Description: "The recent repositories menu shows the branch of a repo that keeps its refs in a reftable",
ExtraCmdArgs: []string{},
ExtraEnvVars: map[string]string{
"SHOW_RECENT_REPOS": "true",
},
Skip: false,
GitVersion: AtLeast("2.45.0"),
SetupConfig: func(cfg *config.AppConfig) {
// the first entry is the repo we're in, so it isn't offered
current, _ := filepath.Abs(".")
reftable, _ := filepath.Abs("../reftable")
cfg.GetAppState().RecentRepos = []string{current, reftable}
},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("one")
shell.RunCommand([]string{"git", "clone", "--ref-format=reftable", ".", "../reftable"})
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.ExpectPopup().Menu().
Title(Equals("Recent repositories")).
Lines(
/* EXPECTED:
Contains("reftable").Contains("master").IsSelected(),
ACTUAL: */
Contains("reftable").Contains(".invalid").IsSelected(),
Contains("Cancel"),
).
Cancel()
},
})

View file

@ -368,6 +368,7 @@ var tests = []*components.IntegrationTest{
misc.RecentReposBranchColumn,
misc.RecentReposColumnWidths,
misc.RecentReposOnLaunch,
misc.RecentReposReftableRepo,
misc.RecentReposWithLongNames,
misc.StartInGitDir,
patch_building.Apply,