@@ -712,13 +712,28 @@ public function remove_repo( string $handle ): array|\WP_Error {
712712 * @return array{success: bool, name?: string, path?: string, branch?: string, remote?: string, commit?: string, dirty?: int}|\WP_Error
713713 */
714714 public function show_repo ( string $ handle ): array |\WP_Error {
715- $ context_policy = WorkspaceAliasResolver::context_policy_for ($ handle );
715+ $ requested_handle = $ handle ;
716+ $ context_policy = null ;
717+ $ parsed = $ this ->parse_handle ($ handle );
718+ $ repo_path = $ this ->workspace_path . '/ ' . $ parsed ['dir_name ' ];
719+ $ inspection = WorkspaceTargetInspector::inspect ($ repo_path , $ parsed ['dir_name ' ]);
720+ if ( is_wp_error ($ inspection ) ) {
721+ return $ inspection ;
722+ }
723+
724+ if ( empty ($ inspection ['exists ' ]) ) {
725+ $ context_policy = WorkspaceAliasResolver::context_policy_for ($ handle );
726+ }
716727 if ( null !== $ context_policy ) {
717728 $ target = (string ) ( $ context_policy ['target ' ] ?? $ handle );
718729 $ parsed = $ this ->parse_handle ($ target );
719730 $ repo_path = $ this ->workspace_path . '/ ' . $ parsed ['dir_name ' ];
720731 $ ref = (string ) ( $ context_policy ['ref ' ] ?? '' );
721- if ( ! is_dir ($ repo_path ) ) {
732+ $ inspection = WorkspaceTargetInspector::inspect ($ repo_path , $ handle );
733+ if ( is_wp_error ($ inspection ) ) {
734+ return $ inspection ;
735+ }
736+ if ( empty ($ inspection ['exists ' ]) ) {
722737 return array (
723738 'success ' => true ,
724739 'name ' => (string ) $ context_policy ['alias ' ],
@@ -736,35 +751,37 @@ public function show_repo( string $handle ): array|\WP_Error {
736751 $ handle = $ target ;
737752 }
738753
739- $ resolved_handle = $ this ->resolve_primary_repo_name ($ handle );
740- if ( ! is_wp_error ($ resolved_handle ) ) {
741- $ handle = $ resolved_handle ;
754+ if ( empty ($ inspection ['exists ' ]) && null === $ context_policy ) {
755+ $ resolved_handle = $ this ->resolve_primary_repo_name ($ handle );
756+ if ( ! is_wp_error ($ resolved_handle ) && $ resolved_handle !== $ handle ) {
757+ $ handle = $ resolved_handle ;
758+ $ parsed = $ this ->parse_handle ($ handle );
759+ $ repo_path = $ this ->workspace_path . '/ ' . $ parsed ['dir_name ' ];
760+ $ inspection = WorkspaceTargetInspector::inspect ($ repo_path , $ parsed ['dir_name ' ]);
761+ if ( is_wp_error ($ inspection ) ) {
762+ return $ inspection ;
763+ }
764+ }
742765 }
743766
744- $ parsed = $ this ->parse_handle ($ handle );
745- $ repo_path = $ this ->workspace_path . '/ ' . $ parsed ['dir_name ' ];
746-
747- if ( ! is_dir ($ repo_path ) ) {
748- return new \WP_Error ('repo_not_found ' , sprintf ('Workspace handle "%s" not found. ' , $ parsed ['dir_name ' ]), array ( 'status ' => 404 ));
767+ if ( empty ($ inspection ['exists ' ]) ) {
768+ return new \WP_Error ('repo_not_found ' , sprintf ('Workspace handle "%s" not found. ' , $ requested_handle ), array ( 'status ' => 404 ));
749769 }
750770
751- $ branch = GitRunner::current_branch ($ repo_path );
752- $ remote = GitRunner::remote_url ($ repo_path );
753- $ commit = GitRunner::latest_commit_summary ($ repo_path );
754- $ status = GitRunner::dirty_count ($ repo_path );
755-
756771 $ result = array (
757772 'success ' => true ,
758773 'name ' => null !== $ context_policy ? (string ) $ context_policy ['alias ' ] : $ parsed ['dir_name ' ],
759774 'repo ' => $ parsed ['repo ' ],
760775 'is_worktree ' => $ parsed ['is_worktree ' ],
761776 'is_context ' => null !== $ context_policy ,
762777 'path ' => $ repo_path ,
763- 'branch ' => $ branch ,
764- 'remote ' => $ remote ,
765- 'commit ' => $ commit ,
766- 'dirty ' => $ status ,
767- 'primary_freshness ' => ! $ parsed ['is_worktree ' ] ? $ this ->build_primary_freshness_report ($ repo_path , $ parsed ['dir_name ' ]) : null ,
778+ 'branch ' => $ inspection ['branch ' ] ?? null ,
779+ 'remote ' => $ inspection ['remote ' ] ?? null ,
780+ 'commit ' => $ inspection ['commit ' ] ?? null ,
781+ 'dirty ' => (int ) ( $ inspection ['dirty ' ] ?? 0 ),
782+ 'primary_freshness ' => ! $ parsed ['is_worktree ' ] && is_string ($ inspection ['branch_status ' ] ?? null )
783+ ? $ this ->build_primary_freshness_report_from_status_output ((string ) $ inspection ['branch_status ' ], $ parsed ['dir_name ' ])
784+ : null ,
768785 );
769786 if ( null !== $ context_policy ) {
770787 $ result ['workspace_policy ' ] = WorkspaceAliasResolver::policy_attestation ($ handle );
0 commit comments