(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func 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 |
| 32 | HEAD d85cc9d281fa6ae1665c68365fc70e75e82a042d |
| 33 | branch 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 |
| 64 | HEAD d85cc9d281fa6ae1665c68365fc70e75e82a042d |
| 65 | branch refs/heads/mybranch |
| 66 | |
| 67 | worktree /path/to/repo-worktree |
| 68 | HEAD 775955775e79b8f5b4c4b56f82fbf657e2d5e4de |
| 69 | branch refs/heads/mybranch-worktree |
| 70 | `, |
nothing calls this directly
no test coverage detected