@joripspace/cli 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/start.js +66 -6
- package/package.json +1 -1
package/lib/start.js
CHANGED
|
@@ -150,7 +150,13 @@ async function startProject(options) {
|
|
|
150
150
|
);
|
|
151
151
|
const sourceSyncBlocking =
|
|
152
152
|
sourceSync &&
|
|
153
|
-
![
|
|
153
|
+
![
|
|
154
|
+
'synchronized',
|
|
155
|
+
'dirty_worktree',
|
|
156
|
+
'managed_worktree_preserved',
|
|
157
|
+
'empty_remote_ready',
|
|
158
|
+
'initialized_empty_remote',
|
|
159
|
+
].includes(sourceSync.status);
|
|
154
160
|
if (sourceSyncBlocking) {
|
|
155
161
|
return {
|
|
156
162
|
ok: false,
|
|
@@ -189,10 +195,21 @@ async function startProject(options) {
|
|
|
189
195
|
? deployments.deployments[0] || null
|
|
190
196
|
: null;
|
|
191
197
|
const deploymentMode = details?.deployment?.mode || 'direct';
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
const restorable =
|
|
199
|
+
latestDeployment?.status === 'success' &&
|
|
200
|
+
(latestDeployment.download_available || latestDeployment.rollback_available);
|
|
201
|
+
if (
|
|
202
|
+
deploymentMode === 'github_actions' &&
|
|
203
|
+
details?.deployment?.source_status === 'empty' &&
|
|
204
|
+
restorable &&
|
|
205
|
+
!existingWorkBeforeGuidance
|
|
206
|
+
) {
|
|
207
|
+
sourceSync = {
|
|
208
|
+
status: 'latest_deployment_restore_required',
|
|
209
|
+
deployment_id: latestDeployment.deployment_id,
|
|
210
|
+
repository_setup: sourceSync,
|
|
211
|
+
};
|
|
212
|
+
} else if (!sourceSync && deploymentMode !== 'github_actions') {
|
|
196
213
|
sourceSync =
|
|
197
214
|
restorable && !existingWorkBeforeGuidance
|
|
198
215
|
? {
|
|
@@ -208,7 +225,9 @@ async function startProject(options) {
|
|
|
208
225
|
}
|
|
209
226
|
const description = normalizedDescription(details?.description ?? accessible?.description);
|
|
210
227
|
const hasExistingWork = Boolean(
|
|
211
|
-
existingWorkBeforeGuidance ||
|
|
228
|
+
existingWorkBeforeGuidance ||
|
|
229
|
+
latestDeployment ||
|
|
230
|
+
(details?.deployment?.mode === 'github_actions' && details?.deployment?.source_status !== 'empty')
|
|
212
231
|
);
|
|
213
232
|
const warnings = [];
|
|
214
233
|
if (migration.backupRoot) {
|
|
@@ -293,6 +312,9 @@ function syncConnectedGithubRepository(workspace, deployment, gitCommand, option
|
|
|
293
312
|
return { status: 'invalid_configuration', repository, branch };
|
|
294
313
|
}
|
|
295
314
|
const expectedUrl = `https://github.com/${repository}.git`;
|
|
315
|
+
if (deployment.source_status === 'empty') {
|
|
316
|
+
return prepareEmptyGithubRepository(workspace, gitCommand, repository, branch, expectedUrl);
|
|
317
|
+
}
|
|
296
318
|
const inside = git(workspace, gitCommand, ['rev-parse', '--is-inside-work-tree']);
|
|
297
319
|
if (inside.status === 0 && inside.stdout.trim() === 'true') {
|
|
298
320
|
const remote = git(workspace, gitCommand, ['remote', 'get-url', 'origin']);
|
|
@@ -406,6 +428,44 @@ function syncConnectedGithubRepository(workspace, deployment, gitCommand, option
|
|
|
406
428
|
return { status: 'synchronized', operation: 'clone', repository, branch };
|
|
407
429
|
}
|
|
408
430
|
|
|
431
|
+
function prepareEmptyGithubRepository(workspace, gitCommand, repository, branch, expectedUrl) {
|
|
432
|
+
const inside = git(workspace, gitCommand, ['rev-parse', '--is-inside-work-tree']);
|
|
433
|
+
if (inside.status === 0 && inside.stdout.trim() === 'true') {
|
|
434
|
+
const remote = git(workspace, gitCommand, ['remote', 'get-url', 'origin']);
|
|
435
|
+
if (remote.status !== 0) {
|
|
436
|
+
const addRemote = git(workspace, gitCommand, ['remote', 'add', 'origin', expectedUrl]);
|
|
437
|
+
if (addRemote.status !== 0) return gitFailure('origin_add_failed', addRemote);
|
|
438
|
+
} else if (githubRepository(remote.stdout.trim()) !== repository.toLowerCase()) {
|
|
439
|
+
return {
|
|
440
|
+
status: 'wrong_repository',
|
|
441
|
+
expected_repository: repository,
|
|
442
|
+
actual_remote: redactGitDiagnostic(remote.stdout.trim()),
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
const currentBranch = git(workspace, gitCommand, ['symbolic-ref', '--quiet', '--short', 'HEAD']);
|
|
446
|
+
if (currentBranch.status !== 0) return gitFailure('branch_check_failed', currentBranch);
|
|
447
|
+
if (currentBranch.stdout.trim() !== branch) {
|
|
448
|
+
const head = git(workspace, gitCommand, ['rev-parse', '--verify', 'HEAD']);
|
|
449
|
+
if (head.status === 0) {
|
|
450
|
+
return {
|
|
451
|
+
status: 'wrong_branch',
|
|
452
|
+
expected_branch: branch,
|
|
453
|
+
actual_branch: currentBranch.stdout.trim(),
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
const setBranch = git(workspace, gitCommand, ['symbolic-ref', 'HEAD', `refs/heads/${branch}`]);
|
|
457
|
+
if (setBranch.status !== 0) return gitFailure('branch_setup_failed', setBranch);
|
|
458
|
+
}
|
|
459
|
+
return { status: 'empty_remote_ready', operation: 'existing_repository', repository, branch };
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const initialize = git(workspace, gitCommand, ['init', '--initial-branch', branch]);
|
|
463
|
+
if (initialize.status !== 0) return gitFailure('init_failed', initialize);
|
|
464
|
+
const addRemote = git(workspace, gitCommand, ['remote', 'add', 'origin', expectedUrl]);
|
|
465
|
+
if (addRemote.status !== 0) return gitFailure('origin_add_failed', addRemote);
|
|
466
|
+
return { status: 'initialized_empty_remote', operation: 'git_init', repository, branch };
|
|
467
|
+
}
|
|
468
|
+
|
|
409
469
|
function validGitBranch(value) {
|
|
410
470
|
if (
|
|
411
471
|
!value ||
|