@@ -22,6 +22,7 @@ class RemoteWorkspaceBackend
2222 {
2323 public static array $ show_input = array ();
2424 public static array $ worktree_input = array ();
25+ public static bool $ worktree_returns_remote_success = false ;
2526
2627 public static function should_handle (): bool
2728 {
@@ -37,9 +38,17 @@ public function show( string $handle ): \WP_Error
3738 );
3839 }
3940
40- public function worktree_add ( string $ repo_name , string $ branch , ?string $ from = null ): \WP_Error
41+ public function worktree_add ( string $ repo_name , string $ branch , ?string $ from = null ): array | \WP_Error
4142 {
4243 self ::$ worktree_input = compact ('repo_name ' , 'branch ' , 'from ' );
44+ if ( self ::$ worktree_returns_remote_success ) {
45+ return array (
46+ 'success ' => true ,
47+ 'handle ' => $ repo_name . '@ ' . str_replace ('/ ' , '- ' , $ branch ),
48+ 'path ' => 'github://Automattic/ ' . $ repo_name . '# ' . $ branch ,
49+ );
50+ }
51+
4352 return new \WP_Error (
4453 'remote_workspace_repo_not_found ' ,
4554 'Remote workspace repository "wpcom-codebox" is not registered. Call workspace_clone first. '
@@ -156,6 +165,8 @@ function is_wp_error( $value ): bool
156165 $ assert ('local show fallback attempted ' , 'wpcom-codebox ' === ( \DataMachineCode \Workspace \Workspace::$ show_input ['handle ' ] ?? '' ));
157166 $ assert ('show returns local listed primary ' , is_array ($ show ) && '/Users/chubes/Developer/wpcom-codebox ' === ( $ show ['path ' ] ?? '' ));
158167
168+ \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ worktree_returns_remote_success = true ;
169+ \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ worktree_input = array ();
159170 $ worktree = \DataMachineCode \Abilities \WorkspaceAbilities::worktreeAdd (
160171 array (
161172 'repo ' => 'wpcom-codebox ' ,
@@ -171,12 +182,13 @@ function is_wp_error( $value ): bool
171182 )
172183 );
173184
174- $ assert ('remote worktree add attempted first ' , ' wpcom-codebox ' === ( \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ worktree_input[ ' repo_name ' ] ?? '' ) );
185+ $ assert ('remote github worktree row is ignored when local primary exists ' , array () === \DataMachineCode \Workspace \RemoteWorkspaceBackend::$ worktree_input );
175186 $ assert ('local worktree add fallback attempted ' , 'wpcom-codebox ' === ( \DataMachineCode \Workspace \Workspace::$ worktree_input ['repo ' ] ?? '' ));
176187 $ assert ('worktree add preserves base ref ' , 'origin/main ' === ( \DataMachineCode \Workspace \Workspace::$ worktree_input ['from ' ] ?? '' ));
177188 $ assert ('worktree add preserves local options ' , false === ( \DataMachineCode \Workspace \Workspace::$ worktree_input ['inject_context ' ] ?? null ) && true === ( \DataMachineCode \Workspace \Workspace::$ worktree_input ['allow_stale ' ] ?? null ));
178189 $ assert ('worktree add preserves task metadata ' , 'Extra-Chill/data-machine-code#635 ' === ( \DataMachineCode \Workspace \Workspace::$ worktree_input ['task ' ]['task_ref ' ] ?? '' ));
179190 $ assert ('worktree add returns local worktree result ' , is_array ($ worktree ) && 'wpcom-codebox@fix-listed-primary-resolution ' === ( $ worktree ['handle ' ] ?? '' ));
191+ $ assert ('worktree add returns editable local path ' , is_array ($ worktree ) && '/Users/chubes/Developer/wpcom-codebox@fix-listed-primary-resolution ' === ( $ worktree ['path ' ] ?? '' ));
180192
181193 if ( $ failures ) {
182194 echo "\nFailures: \n" ;
0 commit comments