Skip to content

Commit a6626d9

Browse files
authored
fix: discover worktree-backed workspace primaries (#604)
1 parent 32c71e9 commit a6626d9

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

inc/Workspace/WorkspaceWorktreeLifecycle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ public function worktree_list( ?string $repo = null, ?string $state = null, arra
720720
continue;
721721
}
722722
$entry_path = $this->workspace_path . '/' . $entry;
723-
if ( ! is_dir($entry_path . '/.git') ) {
723+
if ( ! file_exists($entry_path . '/.git') ) {
724724
continue;
725725
}
726726
$primaries[] = $entry;

tests/smoke-worktree-lifecycle-metadata.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ function () use ( $tmp ): void {
321321
$run('git add README.md', $primary);
322322
$run('git commit -m initial', $primary);
323323
$run('git remote add origin https://github.com/acme/demo.git', $primary);
324+
$linked_primary = DATAMACHINE_WORKSPACE_PATH . '/linked-primary';
325+
$run('git worktree add ../linked-primary -b linked-primary HEAD', $primary);
326+
$assert(true, is_file($linked_primary . '/.git'), 'linked primary fixture uses a .git file');
324327
// Synthetic runtime registration so the env-driven session capture has a
325328
// runtime to scan. DMC enumerates no runtime IDs itself — the integration
326329
// layer (here, the test) declares them via the public filter.
@@ -334,6 +337,9 @@ function () use ( $tmp ): void {
334337

335338
$ws = new \DataMachineCode\Workspace\Workspace();
336339
$GLOBALS['wpdb'] = new DatamachineCodeLifecycleInventoryWpdb();
340+
$linked_list = $ws->worktree_list('linked-primary', null, array( 'include_status' => false, 'include_disk' => false ));
341+
$linked_items = array_values(array_filter($linked_list['worktrees'] ?? array(), fn( $wt ) => ( $wt['handle'] ?? '' ) === 'linked-primary'));
342+
$assert(1, count($linked_items), 'worktree_list discovers primary checkouts whose .git is a file');
337343

338344
$GLOBALS['datamachine_code_test_filters']['datamachine_worktree_disk_budget_thresholds'] = function ( array $thresholds ): array {
339345
$thresholds['refuse_free_bytes'] = PHP_INT_MAX;

0 commit comments

Comments
 (0)