MCPcopy Create free account
hub / github.com/cli/cli / TestClientWorktreePruneRemovesMissingWorktreeMetadata

Function TestClientWorktreePruneRemovesMissingWorktreeMetadata

git/client_test.go:2067–2084  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2065}
2066
2067func TestClientWorktreePruneRemovesMissingWorktreeMetadata(t *testing.T) {
2068 // Given a linked worktree whose directory was removed outside Git
2069 repo := newTestRepo(t)
2070 repo.run(t, "commit", "--quiet", "--allow-empty", "-m", "initial commit")
2071 repo.run(t, "branch", "feature")
2072 worktreeDir := filepath.Join(t.TempDir(), "feature")
2073 repo.run(t, "worktree", "add", "--quiet", worktreeDir, "feature")
2074 require.NoError(t, os.RemoveAll(worktreeDir))
2075
2076 // When stale worktree metadata is pruned
2077 err := repo.client.WorktreePrune(t.Context())
2078
2079 // Then the missing worktree is no longer listed
2080 require.NoError(t, err)
2081 worktrees, listErr := repo.client.Worktrees(t.Context())
2082 require.NoError(t, listErr)
2083 assert.Nil(t, WorktreeForBranch(worktrees, "feature"))
2084}

Callers

nothing calls this directly

Calls 6

newTestRepoFunction · 0.85
WorktreeForBranchFunction · 0.85
JoinMethod · 0.80
WorktreePruneMethod · 0.80
WorktreesMethod · 0.65
runMethod · 0.45

Tested by

no test coverage detected