(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestCreateWorktree(t *testing.T) { |
| 14 | t.Parallel() |
| 15 | dir := bootstrapRepo(t) |
| 16 | root := t.TempDir() |
| 17 | |
| 18 | wt, err := Create(t.Context(), dir, "", WithRoot(root)) |
| 19 | require.NoError(t, err) |
| 20 | require.NotNil(t, wt) |
| 21 | |
| 22 | assert.DirExists(t, wt.Dir) |
| 23 | // A random name looks like "focused_turing" (adjective_surname). |
| 24 | assert.Regexp(t, `^[a-z]+_[a-z]+$`, wt.Name) |
| 25 | assert.Equal(t, "worktree-"+wt.Name, wt.Branch) |
| 26 | assert.Equal(t, filepath.Join(root, "worktrees", wt.Name), wt.Dir) |
| 27 | |
| 28 | // The worktree shares the repository's history: the initial commit's |
| 29 | // files must be present in the new working directory. |
| 30 | assert.FileExists(t, filepath.Join(wt.Dir, "a.txt")) |
| 31 | |
| 32 | // The checked-out branch must match the one reported by the worktree. |
| 33 | out := gitOut(t, wt.Dir, "rev-parse", "--abbrev-ref", "HEAD") |
| 34 | assert.Equal(t, wt.Branch, out) |
| 35 | } |
| 36 | |
| 37 | func TestCreateWithName(t *testing.T) { |
| 38 | t.Parallel() |
nothing calls this directly
no test coverage detected