MCPcopy
hub / github.com/jesseduffield/lazygit / TestGetWorktrees

Function TestGetWorktrees

pkg/commands/git_commands/worktree_loader_test.go:13–267  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestGetWorktrees(t *testing.T) {
14 type scenario struct {
15 testName string
16 repoPaths *RepoPaths
17 before func(runner *oscommands.FakeCmdObjRunner, fs afero.Fs, getRevParseArgs argFn)
18 expectedWorktrees []*models.Worktree
19 expectedErr string
20 }
21
22 scenarios := []scenario{
23 {
24 testName: "Single worktree (main)",
25 repoPaths: &RepoPaths{
26 repoPath: "/path/to/repo",
27 worktreePath: "/path/to/repo",
28 },
29 before: func(runner *oscommands.FakeCmdObjRunner, fs afero.Fs, getRevParseArgs argFn) {
30 runner.ExpectGitArgs([]string{"worktree", "list", "--porcelain"},
31 `worktree /path/to/repo
32HEAD d85cc9d281fa6ae1665c68365fc70e75e82a042d
33branch refs/heads/mybranch
34`,
35 nil)
36
37 gitArgsMainWorktree := append(append([]string{"-C", "/path/to/repo"}, getRevParseArgs()...), "--absolute-git-dir")
38 runner.ExpectGitArgs(gitArgsMainWorktree, "/path/to/repo/.git", nil)
39 _ = fs.MkdirAll("/path/to/repo/.git", 0o755)
40 },
41 expectedWorktrees: []*models.Worktree{
42 {
43 IsMain: true,
44 IsCurrent: true,
45 Path: "/path/to/repo",
46 IsPathMissing: false,
47 GitDir: "/path/to/repo/.git",
48 Branch: "mybranch",
49 Head: "d85cc9d281fa6ae1665c68365fc70e75e82a042d",
50 Name: "repo",
51 },
52 },
53 expectedErr: "",
54 },
55 {
56 testName: "Multiple worktrees (main + linked)",
57 repoPaths: &RepoPaths{
58 repoPath: "/path/to/repo",
59 worktreePath: "/path/to/repo",
60 },
61 before: func(runner *oscommands.FakeCmdObjRunner, fs afero.Fs, getRevParseArgs argFn) {
62 runner.ExpectGitArgs([]string{"worktree", "list", "--porcelain"},
63 `worktree /path/to/repo
64HEAD d85cc9d281fa6ae1665c68365fc70e75e82a042d
65branch refs/heads/mybranch
66
67worktree /path/to/repo-worktree
68HEAD 775955775e79b8f5b4c4b56f82fbf657e2d5e4de
69branch refs/heads/mybranch-worktree
70`,

Callers

nothing calls this directly

Calls 9

GetWorktreesMethod · 0.95
NewFakeRunnerFunction · 0.92
NewDummyOSCommandFunction · 0.92
GetGitVersionFunction · 0.85
buildGitCommonFunction · 0.85
ExpectGitArgsMethod · 0.80
RunMethod · 0.65
NewMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected