Skip to content

Commit abd7565

Browse files
fix: satisfy workspace guard lint
1 parent 094bacc commit abd7565

2 files changed

Lines changed: 44 additions & 40 deletions

File tree

inc/Abilities/WorkspaceAbilities.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,23 @@ private function registerAbilities(): void {
238238
'input_schema' => array(
239239
'type' => 'object',
240240
'properties' => array(
241-
'repo' => array(
241+
'repo' => array(
242242
'type' => 'string',
243243
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
244244
),
245-
'path' => array(
245+
'path' => array(
246246
'type' => 'string',
247247
'description' => 'Relative file path within the repo.',
248248
),
249-
'max_size' => array(
249+
'max_size' => array(
250250
'type' => 'integer',
251251
'description' => 'Maximum file size in bytes (default 1 MB).',
252252
),
253-
'offset' => array(
253+
'offset' => array(
254254
'type' => 'integer',
255255
'description' => 'Line number to start reading from (1-indexed).',
256256
),
257-
'limit' => array(
257+
'limit' => array(
258258
'type' => 'integer',
259259
'description' => 'Maximum number of lines to return.',
260260
),
@@ -291,11 +291,11 @@ private function registerAbilities(): void {
291291
'input_schema' => array(
292292
'type' => 'object',
293293
'properties' => array(
294-
'repo' => array(
294+
'repo' => array(
295295
'type' => 'string',
296296
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
297297
),
298-
'path' => array(
298+
'path' => array(
299299
'type' => 'string',
300300
'description' => 'Relative directory path within the repo (omit for root).',
301301
),
@@ -340,27 +340,27 @@ private function registerAbilities(): void {
340340
'input_schema' => array(
341341
'type' => 'object',
342342
'properties' => array(
343-
'repo' => array(
343+
'repo' => array(
344344
'type' => 'string',
345345
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
346346
),
347-
'pattern' => array(
347+
'pattern' => array(
348348
'type' => 'string',
349349
'description' => 'Regular expression pattern to search for.',
350350
),
351-
'path' => array(
351+
'path' => array(
352352
'type' => 'string',
353353
'description' => 'Optional relative file or directory path to search within.',
354354
),
355-
'include' => array(
355+
'include' => array(
356356
'type' => 'string',
357357
'description' => 'Optional glob pattern to limit matching file paths.',
358358
),
359-
'max_results' => array(
359+
'max_results' => array(
360360
'type' => 'integer',
361361
'description' => 'Maximum number of matches to return (default 100, max 500).',
362362
),
363-
'context_lines' => array(
363+
'context_lines' => array(
364364
'type' => 'integer',
365365
'description' => 'Number of surrounding lines to include for each match (default 0, max 10).',
366366
),
@@ -986,11 +986,11 @@ private function registerAbilities(): void {
986986
'input_schema' => array(
987987
'type' => 'object',
988988
'properties' => array(
989-
'name' => array(
989+
'name' => array(
990990
'type' => 'string',
991991
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
992992
),
993-
'message' => array(
993+
'message' => array(
994994
'type' => 'string',
995995
'description' => 'Commit message.',
996996
),
@@ -1025,27 +1025,27 @@ private function registerAbilities(): void {
10251025
'input_schema' => array(
10261026
'type' => 'object',
10271027
'properties' => array(
1028-
'name' => array(
1028+
'name' => array(
10291029
'type' => 'string',
10301030
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
10311031
),
1032-
'remote' => array(
1032+
'remote' => array(
10331033
'type' => 'string',
10341034
'description' => 'Remote name (default origin).',
10351035
),
1036-
'branch' => array(
1036+
'branch' => array(
10371037
'type' => 'string',
10381038
'description' => 'Branch override.',
10391039
),
10401040
'allow_dangerous_primary_mutation' => array(
10411041
'type' => 'boolean',
10421042
'description' => 'Permit pushing from a primary checkout. Use only for an explicitly approved primary mutation.',
10431043
),
1044-
'force_with_lease' => array(
1044+
'force_with_lease' => array(
10451045
'type' => 'boolean',
10461046
'description' => 'Use git push --force-with-lease. Refuses protected base/fixed branches.',
10471047
),
1048-
'expected_sha' => array(
1048+
'expected_sha' => array(
10491049
'type' => 'string',
10501050
'description' => 'Optional expected remote branch SHA for --force-with-lease.',
10511051
),
@@ -1115,23 +1115,23 @@ private function registerAbilities(): void {
11151115
'input_schema' => array(
11161116
'type' => 'object',
11171117
'properties' => array(
1118-
'name' => array(
1118+
'name' => array(
11191119
'type' => 'string',
11201120
'description' => 'Workspace handle: `<repo>` or `<repo>@<branch-slug>`.',
11211121
),
1122-
'onto' => array(
1122+
'onto' => array(
11231123
'type' => 'string',
11241124
'description' => 'Base ref to rebase onto. Defaults to origin/HEAD or origin/<branch>.',
11251125
),
1126-
'interactive' => array(
1126+
'interactive' => array(
11271127
'type' => 'boolean',
11281128
'description' => 'Reserved; interactive rebases are not supported.',
11291129
),
1130-
'strategy_option' => array(
1130+
'strategy_option' => array(
11311131
'type' => 'string',
11321132
'description' => 'Optional git strategy option such as theirs or ours.',
11331133
),
1134-
'continue' => array(
1134+
'continue' => array(
11351135
'type' => 'boolean',
11361136
'description' => 'Continue an in-progress rebase after conflicts were resolved and staged.',
11371137
),
@@ -1158,20 +1158,20 @@ private function registerAbilities(): void {
11581158
'input_schema' => array(
11591159
'type' => 'object',
11601160
'properties' => array(
1161-
'name' => array(
1161+
'name' => array(
11621162
'type' => 'string',
11631163
'description' => 'Workspace handle: `<repo>` or `<repo>@<branch-slug>`.',
11641164
),
1165-
'mode' => array(
1165+
'mode' => array(
11661166
'type' => 'string',
11671167
'enum' => array( 'soft', 'mixed', 'hard' ),
11681168
'description' => 'Reset mode. Default mixed.',
11691169
),
1170-
'target' => array(
1170+
'target' => array(
11711171
'type' => 'string',
11721172
'description' => 'Target ref or commit. Defaults to origin/HEAD or origin/<branch>.',
11731173
),
1174-
'allow_destructive' => array(
1174+
'allow_destructive' => array(
11751175
'type' => 'boolean',
11761176
'description' => 'Required for hard reset.',
11771177
),
@@ -1241,19 +1241,19 @@ private function registerAbilities(): void {
12411241
'input_schema' => array(
12421242
'type' => 'object',
12431243
'properties' => array(
1244-
'name' => array(
1244+
'name' => array(
12451245
'type' => 'string',
12461246
'description' => 'Workspace handle.',
12471247
),
1248-
'pr' => array(
1248+
'pr' => array(
12491249
'type' => array( 'string', 'integer' ),
12501250
'description' => 'PR number or URL. Defaults to the current branch PR.',
12511251
),
1252-
'squash' => array(
1252+
'squash' => array(
12531253
'type' => 'boolean',
12541254
'description' => 'Squash rebased commits into one PR-title commit before pushing.',
12551255
),
1256-
'drop_paths' => array(
1256+
'drop_paths' => array(
12571257
'type' => 'array',
12581258
'items' => array( 'type' => 'string' ),
12591259
'description' => 'Glob patterns to resolve by taking the base version during rebase conflicts.',

inc/Workspace/WorkspaceCoreUtilities.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ private function normalize_git_remote_url( string $url ): string {
511511
$url = 'ssh://' . $matches[2] . '/' . $matches[3];
512512
}
513513

514+
// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url -- wp_parse_url() is unavailable in pure-PHP smoke tests.
514515
$parts = function_exists('wp_parse_url') ? wp_parse_url($url) : parse_url($url);
515516
if ( is_array($parts) && ! empty($parts['host']) ) {
516517
$host = strtolower( (string) $parts['host']);
@@ -592,21 +593,21 @@ private function build_primary_freshness_report( string $repo_path, string $hand
592593
);
593594
}
594595

595-
$header = strtok((string) ( $status_result['output'] ?? '' ), "\n");
596+
$header = strtok( (string) ( $status_result['output'] ?? '' ), "\n");
596597
$header = false === $header ? '' : trim($header);
597598
$branch = null;
598599
$detached = false;
599-
$upstream = null;
600+
$upstream = null;
600601
$behind = 0;
601602
$ahead = 0;
602603
$status = 'unknown';
603604

604605
if ( preg_match('/^## HEAD \(no branch\)/', $header) ) {
605606
$detached = true;
606-
$status = 'detached';
607+
$status = 'detached';
607608
} elseif ( preg_match('/^## (.+?)(?:\.\.\.([^\s\[]+))?(?: \[(.+)\])?$/', $header, $matches) ) {
608-
$branch = trim((string) $matches[1]);
609-
$upstream = isset($matches[2]) && '' !== $matches[2] ? trim((string) $matches[2]) : null;
609+
$branch = trim( (string) $matches[1]);
610+
$upstream = isset($matches[2]) && '' !== $matches[2] ? trim( (string) $matches[2]) : null;
610611
$divergence = isset($matches[3]) ? (string) $matches[3] : '';
611612

612613
if ( preg_match('/behind (\d+)/', $divergence, $behind_match) ) {
@@ -685,15 +686,18 @@ public function ensure_primary_read_allowed( string $handle, bool $allow_stale_p
685686
return true;
686687
}
687688

689+
$behind_value = $freshness['behind'] ?? null;
690+
$ahead_value = $freshness['ahead'] ?? null;
691+
688692
return new \WP_Error(
689693
'stale_primary_read_blocked',
690694
sprintf(
691695
'Primary checkout "%s" is %s and may not reflect the current remote. Refresh with `%s`, read a fresh worktree, or pass allow_stale_primary=true to opt in. Behind: %s. Ahead: %s.',
692696
$parsed['repo'],
693697
$status,
694698
(string) ( $freshness['suggested_command'] ?? $this->primary_refresh_command($parsed['dir_name']) ),
695-
null === ( $freshness['behind'] ?? null ) ? '-' : (string) $freshness['behind'],
696-
null === ( $freshness['ahead'] ?? null ) ? '-' : (string) $freshness['ahead']
699+
null === $behind_value ? '-' : (string) $behind_value,
700+
null === $ahead_value ? '-' : (string) $ahead_value
697701
),
698702
array(
699703
'status' => 409,

0 commit comments

Comments
 (0)