From d696383ba5e39a04626847587a12737a70fb970b Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Sun, 7 Jun 2026 20:56:14 -0400 Subject: [PATCH] fix: discover worktree-backed workspace primaries --- inc/Workspace/WorkspaceWorktreeLifecycle.php | 2 +- tests/smoke-worktree-lifecycle-metadata.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/inc/Workspace/WorkspaceWorktreeLifecycle.php b/inc/Workspace/WorkspaceWorktreeLifecycle.php index 76bb40ed..731b4d52 100644 --- a/inc/Workspace/WorkspaceWorktreeLifecycle.php +++ b/inc/Workspace/WorkspaceWorktreeLifecycle.php @@ -720,7 +720,7 @@ public function worktree_list( ?string $repo = null, ?string $state = null, arra continue; } $entry_path = $this->workspace_path . '/' . $entry; - if ( ! is_dir($entry_path . '/.git') ) { + if ( ! file_exists($entry_path . '/.git') ) { continue; } $primaries[] = $entry; diff --git a/tests/smoke-worktree-lifecycle-metadata.php b/tests/smoke-worktree-lifecycle-metadata.php index e8240255..4097929b 100644 --- a/tests/smoke-worktree-lifecycle-metadata.php +++ b/tests/smoke-worktree-lifecycle-metadata.php @@ -321,6 +321,9 @@ function () use ( $tmp ): void { $run('git add README.md', $primary); $run('git commit -m initial', $primary); $run('git remote add origin https://github.com/acme/demo.git', $primary); + $linked_primary = DATAMACHINE_WORKSPACE_PATH . '/linked-primary'; + $run('git worktree add ../linked-primary -b linked-primary HEAD', $primary); + $assert(true, is_file($linked_primary . '/.git'), 'linked primary fixture uses a .git file'); // Synthetic runtime registration so the env-driven session capture has a // runtime to scan. DMC enumerates no runtime IDs itself — the integration // layer (here, the test) declares them via the public filter. @@ -334,6 +337,9 @@ function () use ( $tmp ): void { $ws = new \DataMachineCode\Workspace\Workspace(); $GLOBALS['wpdb'] = new DatamachineCodeLifecycleInventoryWpdb(); + $linked_list = $ws->worktree_list('linked-primary', null, array( 'include_status' => false, 'include_disk' => false )); + $linked_items = array_values(array_filter($linked_list['worktrees'] ?? array(), fn( $wt ) => ( $wt['handle'] ?? '' ) === 'linked-primary')); + $assert(1, count($linked_items), 'worktree_list discovers primary checkouts whose .git is a file'); $GLOBALS['datamachine_code_test_filters']['datamachine_worktree_disk_budget_thresholds'] = function ( array $thresholds ): array { $thresholds['refuse_free_bytes'] = PHP_INT_MAX;