repown 0.4.0 → 0.5.0
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/CHANGELOG.md +72 -1
- package/README.md +4 -1
- package/dist/cli.js +4 -4
- package/dist/commands/accounts.js +19 -13
- package/dist/commands/doctor.js +7 -5
- package/dist/commands/fix.js +5 -5
- package/dist/commands/guard.js +7 -5
- package/dist/commands/off.js +4 -4
- package/dist/commands/reauthor.js +5 -5
- package/dist/commands/scan.js +7 -6
- package/dist/commands/setup.js +3 -3
- package/dist/commands/start.js +6 -6
- package/dist/commands/status.js +19 -15
- package/dist/commands/use.js +11 -11
- package/dist/core/blockers.js +8 -7
- package/dist/core/config-snapshot.js +97 -0
- package/dist/core/credential/gcm.js +2 -2
- package/dist/core/credential/gh.js +12 -5
- package/dist/core/credential/repair.js +1 -1
- package/dist/core/git.js +9 -4
- package/dist/core/guard/check.js +44 -8
- package/dist/core/guard/hook.js +1 -1
- package/dist/core/hosts/github.js +11 -5
- package/dist/core/hosts/index.js +21 -3
- package/dist/core/identity.js +1 -1
- package/dist/core/inspect.js +6 -6
- package/dist/core/push-destination.js +1 -1
- package/dist/core/push-state.js +5 -5
- package/dist/core/reauthor.js +3 -3
- package/dist/core/registry.js +1 -1
- package/dist/core/unpushed.js +10 -9
- package/dist/program.js +10 -10
- package/dist/ui/args.js +3 -3
- package/dist/ui/command.js +1 -1
- package/dist/ui/dispatch.js +6 -6
- package/dist/ui/format.js +31 -0
- package/dist/ui/help.js +2 -2
- package/dist/ui/prompt.js +1 -1
- package/dist/wizard/clack.js +56 -21
- package/dist/wizard/engine.js +1 -1
- package/dist/wizard/home-context.js +23 -10
- package/dist/wizard/home-flow.js +33 -11
- package/dist/wizard/home-run.js +85 -44
- package/dist/wizard/home-text.js +14 -3
- package/dist/wizard/plain.js +2 -2
- package/dist/wizard/review-text.js +19 -4
- package/dist/wizard/setup-changes.js +2 -2
- package/dist/wizard/setup-context.js +20 -16
- package/dist/wizard/setup-flow.js +112 -34
- package/dist/wizard/setup-run.js +31 -28
- package/npm-shrinkwrap.json +378 -17
- package/package.json +3 -3
|
@@ -2,18 +2,19 @@
|
|
|
2
2
|
// read-only: the registry, this clone (origin, owner, pin, hook, push.autoSetupRemote),
|
|
3
3
|
// and the machine (gh, the credential helper, the global identity, git's version).
|
|
4
4
|
// Nothing here writes.
|
|
5
|
-
import { gitSupportsAutoUpstream } from
|
|
6
|
-
import { inspectRepo, inspectAuth } from
|
|
7
|
-
import { pinHolds } from
|
|
8
|
-
import { loadRegistry } from
|
|
9
|
-
import { planRepair } from
|
|
10
|
-
import { isGh } from
|
|
11
|
-
import { providers } from
|
|
12
|
-
import { ok, err } from
|
|
13
|
-
import { previewLines } from
|
|
14
|
-
import { readUnpushed } from
|
|
15
|
-
import { readPushFacts } from
|
|
16
|
-
import { SOURCE_GCM, SOURCE_GH, SOURCE_OWNS } from
|
|
5
|
+
import { gitSupportsAutoUpstream } from '../core/version.js';
|
|
6
|
+
import { inspectRepo, inspectAuth } from '../core/inspect.js';
|
|
7
|
+
import { pinHolds } from '../core/identity.js';
|
|
8
|
+
import { loadRegistry } from '../core/registry.js';
|
|
9
|
+
import { planRepair } from '../core/credential/repair.js';
|
|
10
|
+
import { isGh } from '../core/credential/gh.js';
|
|
11
|
+
import { lookUpProfile, providers } from '../core/hosts/index.js';
|
|
12
|
+
import { ok, err } from '../core/result.js';
|
|
13
|
+
import { previewLines } from '../commands/fix.js';
|
|
14
|
+
import { readUnpushed } from '../core/unpushed.js';
|
|
15
|
+
import { readPushFacts } from '../core/push-state.js';
|
|
16
|
+
import { SOURCE_GCM, SOURCE_GH, SOURCE_OWNS, signedInLogins } from './setup-flow.js';
|
|
17
|
+
import { snapshotOf } from '../core/config-snapshot.js';
|
|
17
18
|
/**
|
|
18
19
|
* Candidate logins not already recorded, one entry each. The first spelling
|
|
19
20
|
* wins; every source joins it, in the order owner, gh, then Git Credential
|
|
@@ -84,9 +85,11 @@ export async function readContext(git, cwd, options = {}) {
|
|
|
84
85
|
const registry = await readRegistry();
|
|
85
86
|
if (!registry.ok)
|
|
86
87
|
return registry;
|
|
87
|
-
|
|
88
|
+
// Read-only: one list per scope answers every config read of this context (ADR-029).
|
|
89
|
+
const view = snapshotOf(git);
|
|
90
|
+
const repo = await inspectRepo(view);
|
|
88
91
|
const recorded = registry.value.accounts;
|
|
89
|
-
const facts = await readFacts(
|
|
92
|
+
const facts = await readFacts(view, repo, recorded, options);
|
|
90
93
|
return ok(assemble(cwd, recorded, repo, facts));
|
|
91
94
|
}
|
|
92
95
|
async function readFacts(git, repo, recorded, options) {
|
|
@@ -162,6 +165,7 @@ function assemble(cwd, recorded, repo, facts) {
|
|
|
162
165
|
machineIdentity: { name: facts.name, email: facts.email },
|
|
163
166
|
upstream: facts.upstream, stored: facts.stored,
|
|
164
167
|
suggest: suggester(),
|
|
168
|
+
signedIn: async () => signedInLogins(facts.gh, facts.stored),
|
|
165
169
|
};
|
|
166
170
|
}
|
|
167
171
|
/** gh anywhere in the helper list may answer sign-ins: git asks the helpers in order. */
|
|
@@ -250,13 +254,13 @@ async function gitUses(git, values, repo) {
|
|
|
250
254
|
return name === values.name && email === values.email && user === values.account;
|
|
251
255
|
}
|
|
252
256
|
/** Profile lookups are network calls: one per account and host, however often a step is re-asked. */
|
|
253
|
-
function suggester() {
|
|
257
|
+
export function suggester() {
|
|
254
258
|
const cache = new Map();
|
|
255
259
|
return (account, host) => {
|
|
256
260
|
const key = host + '\n' + account;
|
|
257
261
|
if (!cache.has(key)) {
|
|
258
262
|
const provider = providers().find((candidate) => candidate.id === host);
|
|
259
|
-
cache.set(key, (provider
|
|
263
|
+
cache.set(key, lookUpProfile(provider, account).then((found) => ({ ...found.profile, problem: found.problem })));
|
|
260
264
|
}
|
|
261
265
|
return cache.get(key);
|
|
262
266
|
};
|
|
@@ -6,18 +6,34 @@
|
|
|
6
6
|
//
|
|
7
7
|
// Pure: no I/O. What the clone and the machine look like arrives as a SetupContext
|
|
8
8
|
// (src/wizard/setup-context.ts), read before the first question.
|
|
9
|
-
import { ghAdvice, upstreamText } from
|
|
10
|
-
import { providers } from
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
9
|
+
import { ghAdvice, upstreamText } from '../commands/status.js';
|
|
10
|
+
import { providers } from '../core/hosts/index.js';
|
|
11
|
+
import { isNoreplyAddress } from '../core/hosts/github.js';
|
|
12
|
+
import { ALLOW_OWNER_BY_HAND, allowOwnerCommand, shellWord } from '../core/guard/check.js';
|
|
13
|
+
import { printable } from '../ui/format.js';
|
|
14
|
+
import { foreignAddresses, foreignCount } from '../core/unpushed.js';
|
|
15
|
+
import { blockers } from '../core/blockers.js';
|
|
16
|
+
import { pinWrites } from '../core/identity.js';
|
|
17
|
+
import { stepDefault } from './review-text.js';
|
|
17
18
|
/** The "a new account" choice. Empty, so it can never be a real account's name. */
|
|
18
19
|
export const NEW_ACCOUNT = '';
|
|
19
20
|
/** A detected choice's value. The login grammar refuses '+', so a recorded account cannot collide. */
|
|
20
21
|
export const DETECTED_PREFIX = '+';
|
|
22
|
+
/**
|
|
23
|
+
* Every github.com login gh or Git Credential Manager is signed in as, once each (any
|
|
24
|
+
* case). Null when neither could be read: a skipped read is never "signed in as nobody".
|
|
25
|
+
*/
|
|
26
|
+
export function signedInLogins(gh, stored) {
|
|
27
|
+
const lists = [gh?.ok ? gh.value.accounts.map((account) => account.login) : null, stored?.ok ? stored.value : null];
|
|
28
|
+
const read = lists.filter((list) => list !== null);
|
|
29
|
+
if (read.length === 0)
|
|
30
|
+
return null;
|
|
31
|
+
const byCase = new Map();
|
|
32
|
+
for (const login of read.flat())
|
|
33
|
+
if (!byCase.has(login.toLowerCase()))
|
|
34
|
+
byCase.set(login.toLowerCase(), login);
|
|
35
|
+
return [...byCase.values()];
|
|
36
|
+
}
|
|
21
37
|
const lower = (value) => value.toLowerCase();
|
|
22
38
|
/** The account the answers are about: a recorded one, a detected login, or the new one typed in. */
|
|
23
39
|
export function accountOf(answers) {
|
|
@@ -92,6 +108,21 @@ function steps(ctx) {
|
|
|
92
108
|
return [
|
|
93
109
|
modeStep(),
|
|
94
110
|
...accountSteps(ctx),
|
|
111
|
+
...profileSteps(ctx),
|
|
112
|
+
...choiceSteps(ctx),
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
/** A new account's login, refused when already recorded. The start screen asks it too. */
|
|
116
|
+
export function loginStep(ctx) {
|
|
117
|
+
return {
|
|
118
|
+
id: 'newAccount', kind: 'text', flag: '<account>', message: 'The account\'s user name (login)',
|
|
119
|
+
hint: 'the name you sign in with, e.g. octocat; not your email address',
|
|
120
|
+
validate: (value) => newAccountProblem(String(value), ctx),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** Where a new account is hosted, and its commit name and email. The start screen asks these too. */
|
|
124
|
+
export function profileSteps(ctx) {
|
|
125
|
+
return [
|
|
95
126
|
{ id: 'host', kind: 'select', flag: '--host', message: 'Where is this account hosted?',
|
|
96
127
|
hint: 'on GitHub, repown also makes pushes sign in as this account', when: (answers) => isNew(answers),
|
|
97
128
|
choices: () => hostChoices(), initial: () => ctx.host },
|
|
@@ -103,9 +134,16 @@ function steps(ctx) {
|
|
|
103
134
|
hint: 'anyone who can see the repository can read it once you push', when: (answers) => isNew(answers), validate: required,
|
|
104
135
|
initial: async (answers) => (await ctx.suggest(accountOf(answers), hostOf(answers, ctx))).email,
|
|
105
136
|
detail: (answers) => emailDetail(answers, ctx) },
|
|
106
|
-
...choiceSteps(ctx),
|
|
107
137
|
];
|
|
108
138
|
}
|
|
139
|
+
/** A new account from the answers that ask for one. */
|
|
140
|
+
export function newAccountOf(answers, ctx) {
|
|
141
|
+
return { login: accountOf(answers), name: String(answers['name']), email: String(answers['email']), host: hostOf(answers, ctx) };
|
|
142
|
+
}
|
|
143
|
+
/** `accounts add` with every answer as a flag, so it asks nothing; `--` keeps a dashed login the account. */
|
|
144
|
+
export function addAccountArgv(account) {
|
|
145
|
+
return ['accounts', 'add', '--name=' + account.name, '--email=' + account.email, '--host=' + account.host, '--', account.login];
|
|
146
|
+
}
|
|
109
147
|
function modeStep() {
|
|
110
148
|
return {
|
|
111
149
|
id: 'mode', kind: 'select', flag: '--step-by-step',
|
|
@@ -129,9 +167,7 @@ function accountSteps(ctx) {
|
|
|
129
167
|
when: () => Object.keys(ctx.recorded).length > 0 || ctx.detected.length > 0,
|
|
130
168
|
choices: () => accountChoices(ctx), initial: () => defaultAccount(ctx),
|
|
131
169
|
detail: () => (ctx.pinned ? 'right now this clone is pinned to ' + ctx.pinned : 'right now this clone isn\'t pinned to any account') },
|
|
132
|
-
{
|
|
133
|
-
hint: 'the name you sign in with, e.g. octocat; not your email address', when: (answers) => asksForLogin(answers),
|
|
134
|
-
validate: (value) => newAccountProblem(String(value), ctx), initial: () => ownerInitial(ctx) },
|
|
170
|
+
{ ...loginStep(ctx), when: (answers) => asksForLogin(answers), initial: () => ownerInitial(ctx) },
|
|
135
171
|
];
|
|
136
172
|
}
|
|
137
173
|
function choiceSteps(ctx) {
|
|
@@ -210,23 +246,59 @@ function hostChoices() {
|
|
|
210
246
|
return { value: provider.id, label, ...(hint ? { hint } : {}) };
|
|
211
247
|
});
|
|
212
248
|
}
|
|
213
|
-
/**
|
|
214
|
-
|
|
249
|
+
/**
|
|
250
|
+
* On GitHub: the private address when that is what the email starts as, else where to
|
|
251
|
+
* find it, for someone who has never looked.
|
|
252
|
+
*/
|
|
253
|
+
async function noreplyNote(answers, ctx) {
|
|
215
254
|
if (hostOf(answers, ctx) !== 'github')
|
|
216
255
|
return undefined;
|
|
256
|
+
const account = printable(accountOf(answers));
|
|
257
|
+
const { email } = await ctx.suggest(accountOf(answers), 'github');
|
|
258
|
+
if (email && isNoreplyAddress(email) && typeof answers['email'] !== 'string')
|
|
259
|
+
return 'prefilled with the private address GitHub gives ' + account + ' (github.com/settings/emails)';
|
|
217
260
|
return 'tip: to keep your own address private, use the one GitHub gives you, shown at ' +
|
|
218
|
-
'github.com/settings/emails, like 1234+' +
|
|
261
|
+
'github.com/settings/emails, like 1234+' + account + '@users.noreply.github.com';
|
|
219
262
|
}
|
|
220
|
-
/**
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
263
|
+
/**
|
|
264
|
+
* First what the host said about the login (no such account, an organisation), so Back
|
|
265
|
+
* can fix a typo before anything is recorded; else whether this machine is signed in as
|
|
266
|
+
* someone else, and whether the name starts as the login; then the machine's name, never this account's initial value.
|
|
267
|
+
*/
|
|
268
|
+
async function nameDetail(answers, ctx) {
|
|
269
|
+
if (!isNew(answers))
|
|
224
270
|
return undefined;
|
|
225
|
-
|
|
271
|
+
const found = await ctx.suggest(accountOf(answers), hostOf(answers, ctx));
|
|
272
|
+
const leads = found.problem ? [printable(found.problem)] : [await notSignedIn(answers, ctx), loginPrefill(answers, found, ctx)];
|
|
273
|
+
const parts = [...leads, machineName(ctx)].filter((part) => part);
|
|
274
|
+
return parts.length > 0 ? parts.join('; ') : undefined;
|
|
275
|
+
}
|
|
276
|
+
/** On GitHub, when this machine is signed in as other logins only: perhaps not this person's account. */
|
|
277
|
+
async function notSignedIn(answers, ctx) {
|
|
278
|
+
if (hostOf(answers, ctx) !== 'github')
|
|
279
|
+
return null;
|
|
280
|
+
const logins = await ctx.signedIn();
|
|
281
|
+
const login = accountOf(answers);
|
|
282
|
+
if (!logins || logins.length === 0 || logins.some((other) => other.toLowerCase() === login.toLowerCase()))
|
|
283
|
+
return null;
|
|
284
|
+
const shown = printable(login);
|
|
285
|
+
return 'signed in as ' + logins.map(printable).join(', ') + ', not ' + shown + ': if ' + shown +
|
|
286
|
+
' isn\'t your account, go back; otherwise the first push asks you to sign in as it';
|
|
287
|
+
}
|
|
288
|
+
/** Said when the name question starts as the login: no profile name was found. */
|
|
289
|
+
function loginPrefill(answers, found, ctx) {
|
|
290
|
+
if (found.name || typeof answers['name'] === 'string')
|
|
291
|
+
return null;
|
|
292
|
+
const answered = found.email !== undefined && hostOf(answers, ctx) === 'github';
|
|
293
|
+
return answered ? 'GitHub shows no name for ' + printable(accountOf(answers)) + ', so this is the login' : 'this is the login';
|
|
226
294
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
295
|
+
function machineName(ctx) {
|
|
296
|
+
const name = ctx.machineIdentity.name;
|
|
297
|
+
return name ? 'your default git name here is ' + printable(name) + ': use it only if this account does too' : null;
|
|
298
|
+
}
|
|
299
|
+
/** The private-address note first, then the machine address. Two sentences; both prompters wrap one detail. */
|
|
300
|
+
async function emailDetail(answers, ctx) {
|
|
301
|
+
const tip = await noreplyNote(answers, ctx);
|
|
230
302
|
const line = addressDetail(answers, ctx);
|
|
231
303
|
if (tip && line)
|
|
232
304
|
return tip + '; ' + line;
|
|
@@ -236,7 +308,7 @@ function addressDetail(answers, ctx) {
|
|
|
236
308
|
const email = ctx.machineIdentity.email;
|
|
237
309
|
if (!isNew(answers) || !email)
|
|
238
310
|
return undefined;
|
|
239
|
-
return '
|
|
311
|
+
return 'your default git address here is ' + printable(email) + ': use it only if this account does too';
|
|
240
312
|
}
|
|
241
313
|
const UPSTREAM_HINT = 'sets push.autoSetupRemote in this clone only, so the first push of a branch without an upstream ' +
|
|
242
314
|
'creates it on origin; the guard still checks it';
|
|
@@ -469,8 +541,7 @@ export function planCommands(answers, ctx) {
|
|
|
469
541
|
const planned = [
|
|
470
542
|
repointArgv(answers, ctx),
|
|
471
543
|
fetchArgv(answers, ctx),
|
|
472
|
-
isNew(answers) ?
|
|
473
|
-
'--host=' + hostOf(answers, ctx), '--', account] : null,
|
|
544
|
+
isNew(answers) ? addAccountArgv(newAccountOf(answers, ctx)) : null,
|
|
474
545
|
answers['allowOwner'] === true && ctx.owner ? allowOwnerLine(ctx) : null,
|
|
475
546
|
answers['fix'] === true ? ['fix', '--yes', ...cwd] : null,
|
|
476
547
|
useArgv(answers, ctx),
|
|
@@ -560,21 +631,28 @@ function ghWhat(account, ctx) {
|
|
|
560
631
|
function allowOwnerLine(ctx) {
|
|
561
632
|
return [...gitIn(ctx), 'config', '--local', '--add', 'repown.allowOwner', ctx.owner];
|
|
562
633
|
}
|
|
634
|
+
/** Shown in place of a word no quoting keeps literal in every shell (shellWord): it has run, or will, but don't paste it. */
|
|
635
|
+
export const UNQUOTABLE = '[value not safe to paste]';
|
|
636
|
+
function wordOf(value) {
|
|
637
|
+
return shellWord(value) ?? UNQUOTABLE;
|
|
638
|
+
}
|
|
563
639
|
/**
|
|
564
640
|
* The command as you would type it: the account where it reads naturally, options
|
|
565
|
-
* as `--name value`, and `--host github` left out because it's the default.
|
|
641
|
+
* as `--name value`, and `--host github` left out because it's the default. A `--`
|
|
642
|
+
* before a dashed account comes out quoted (shellWord).
|
|
566
643
|
*/
|
|
567
644
|
export function formatCommand(argv) {
|
|
568
645
|
if (argv[0] === 'git')
|
|
569
|
-
return printable(argv.map(
|
|
646
|
+
return printable(argv.map(wordOf).join(' '));
|
|
570
647
|
const end = argv.indexOf('--');
|
|
571
648
|
const head = end < 0 ? argv : argv.slice(0, end);
|
|
572
649
|
const positional = end < 0 ? [] : argv.slice(end + 1);
|
|
573
|
-
const path = head.filter((token) => !token.startsWith('-'));
|
|
574
|
-
const options = head.filter((token) => token.startsWith('-') && token !== '--host=github').flatMap(splitOption);
|
|
575
650
|
const dashed = positional.some((value) => value.startsWith('-'));
|
|
576
|
-
const
|
|
577
|
-
|
|
651
|
+
const path = head.filter((token) => !token.startsWith('-')).map(wordOf);
|
|
652
|
+
const options = head.filter((token) => token.startsWith('-') && token !== '--host=github').flatMap(splitOption).map(wordOf);
|
|
653
|
+
const accounts = positional.map(wordOf);
|
|
654
|
+
const words = dashed ? [...path, ...options, wordOf('--'), ...accounts] : [...path, ...accounts, ...options];
|
|
655
|
+
return printable(['repown', ...words].join(' '));
|
|
578
656
|
}
|
|
579
657
|
/** Setup's own importers read it from here; the one definition is in the output helpers. */
|
|
580
658
|
export { printable };
|
|
@@ -761,8 +839,8 @@ function notes(answers, ctx) {
|
|
|
761
839
|
lines.push(guard);
|
|
762
840
|
const guarded = answers['guard'] === true || ctx.guard === 'on';
|
|
763
841
|
if (guarded && ownerForeign(account, ctx) && answers['allowOwner'] !== true) {
|
|
764
|
-
lines.push('Warning: the push guard will refuse pushes to "' + ctx.owner + '". To allow them later: ' +
|
|
765
|
-
|
|
842
|
+
lines.push('Warning: the push guard will refuse pushes to "' + printable(ctx.owner) + '". To allow them later: ' +
|
|
843
|
+
(allowOwnerCommand(ctx.owner) ?? ALLOW_OWNER_BY_HAND));
|
|
766
844
|
}
|
|
767
845
|
if (ctx.ghIsHelper && answers['fix'] !== true && ctx.credentialPinned) {
|
|
768
846
|
lines.push('Note: gh is still git\'s credential helper, so pushes sign in as gh\'s active account, not ' + account + '.');
|
package/dist/wizard/setup-run.js
CHANGED
|
@@ -4,28 +4,29 @@
|
|
|
4
4
|
// path, not a wizard's copy of it.
|
|
5
5
|
//
|
|
6
6
|
// Nothing is written before the commands run. Cancelling exits 130, declining 1.
|
|
7
|
-
import { ghAdvice } from
|
|
8
|
-
import { handingOver } from
|
|
9
|
-
import { ok, err } from
|
|
10
|
-
import { inspectAuth } from
|
|
11
|
-
import { flagBool, flagString, gitFor, parseArgs } from
|
|
12
|
-
import { specFor } from
|
|
13
|
-
import * as out from
|
|
14
|
-
import { useColour } from
|
|
15
|
-
import useCommand, { NEXT_GUARD } from
|
|
16
|
-
import fixCommand from
|
|
17
|
-
import reauthorCommand from
|
|
18
|
-
import guardGroup from
|
|
19
|
-
import accountsGroup from
|
|
20
|
-
import { wizard, refusedGiven } from
|
|
21
|
-
import { setupFlow, planCommands, formatCommand, gitStepOf, keptFlags, briefOf, missingFlags, printable, dropFixPrefix, NEW_ACCOUNT, accountOf, pinUnchanged, ghNoted } from
|
|
22
|
-
import { cloneChangeLines, machineChangeLines, readCloneSnapshot } from
|
|
23
|
-
import { readContext, readRegistry } from
|
|
24
|
-
import { plainPrompter } from
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
7
|
+
import { ghAdvice } from '../commands/status.js';
|
|
8
|
+
import { handingOver } from '../core/exec.js';
|
|
9
|
+
import { ok, err } from '../core/result.js';
|
|
10
|
+
import { inspectAuth } from '../core/inspect.js';
|
|
11
|
+
import { flagBool, flagString, gitFor, parseArgs } from '../ui/args.js';
|
|
12
|
+
import { specFor } from '../ui/command.js';
|
|
13
|
+
import * as out from '../ui/format.js';
|
|
14
|
+
import { useColour } from '../ui/format.js';
|
|
15
|
+
import useCommand, { NEXT_GUARD } from '../commands/use.js';
|
|
16
|
+
import fixCommand from '../commands/fix.js';
|
|
17
|
+
import reauthorCommand from '../commands/reauthor.js';
|
|
18
|
+
import guardGroup from '../commands/guard.js';
|
|
19
|
+
import accountsGroup from '../commands/accounts.js';
|
|
20
|
+
import { wizard, refusedGiven } from './engine.js';
|
|
21
|
+
import { setupFlow, planCommands, formatCommand, gitStepOf, keptFlags, briefOf, missingFlags, printable, dropFixPrefix, NEW_ACCOUNT, accountOf, pinUnchanged, ghNoted } from './setup-flow.js';
|
|
22
|
+
import { cloneChangeLines, machineChangeLines, readCloneSnapshot } from './setup-changes.js';
|
|
23
|
+
import { readContext, readRegistry } from './setup-context.js';
|
|
24
|
+
import { plainPrompter } from './plain.js';
|
|
25
|
+
import { COMMAND_MARK } from './review-text.js';
|
|
26
|
+
import { blockers } from '../core/blockers.js';
|
|
27
|
+
import { readPushFacts } from '../core/push-state.js';
|
|
28
|
+
import { guardState, hookLocation } from '../core/guard/hook.js';
|
|
29
|
+
import { readUnpushed } from '../core/unpushed.js';
|
|
29
30
|
const CANCELLED = 130;
|
|
30
31
|
export async function runSetup(args, deps) {
|
|
31
32
|
const registry = await readRegistry();
|
|
@@ -239,7 +240,7 @@ export async function choosePrompter() {
|
|
|
239
240
|
if (!useColour(process.stderr) || process.env['TERM'] === 'dumb')
|
|
240
241
|
return plainPrompter(streams);
|
|
241
242
|
try {
|
|
242
|
-
return (await import(
|
|
243
|
+
return (await import('./clack.js')).clackPrompter(streams);
|
|
243
244
|
}
|
|
244
245
|
catch (cause) {
|
|
245
246
|
out.detail('plain prompts: the richer prompter could not load (' + (cause instanceof Error ? cause.message : String(cause)) + ')');
|
|
@@ -296,7 +297,7 @@ async function offer(plan, index, planned, confirm) {
|
|
|
296
297
|
process.stderr.write('\n');
|
|
297
298
|
out.detail('step ' + (index + 1) + ' of ' + plan.length + ': ' + printable(planned.what));
|
|
298
299
|
if (!confirm) {
|
|
299
|
-
out.detail(
|
|
300
|
+
out.detail(out.accent(process.stderr, COMMAND_MARK + formatCommand(planned.argv)));
|
|
300
301
|
return 'yes';
|
|
301
302
|
}
|
|
302
303
|
return confirm(planned);
|
|
@@ -324,7 +325,7 @@ function halt(remaining, code, why) {
|
|
|
324
325
|
if (remaining.length > 0)
|
|
325
326
|
out.detail('not run:');
|
|
326
327
|
for (const planned of remaining)
|
|
327
|
-
out.detail(' ' + formatCommand(planned.argv));
|
|
328
|
+
out.detail(' ' + out.accent(process.stderr, formatCommand(planned.argv)));
|
|
328
329
|
return code;
|
|
329
330
|
}
|
|
330
331
|
/** On stderr, like the step lines: stdout carries only what the commands themselves print. */
|
|
@@ -354,10 +355,12 @@ function closing(account, found) {
|
|
|
354
355
|
const blocking = found.filter((blocker) => blocker.blocks);
|
|
355
356
|
const more = blocking.length > 1 ? ' (and ' + (blocking.length - 1) + ' more below)' : '';
|
|
356
357
|
const [first] = blocking;
|
|
357
|
-
out.detail(first ? 'set up for ' + printable(account) + '; the next push will fail: ' + printable(first.summary) + more
|
|
358
|
-
: 'done: this clone is set up for ' + printable(account));
|
|
358
|
+
out.detail(first ? out.marked('warn', process.stderr, 'set up for ' + printable(account) + '; the next push will fail: ' + printable(first.summary) + more)
|
|
359
|
+
: out.marked('ok', process.stderr, 'done: this clone is set up for ' + printable(account)));
|
|
360
|
+
// A mark pushes the closing words two columns right; the blockers stay two deeper still.
|
|
361
|
+
const indent = useColour(process.stderr) ? ' ' : ' ';
|
|
359
362
|
for (const line of found.flatMap((blocker) => blocker.lines))
|
|
360
|
-
out.detail(
|
|
363
|
+
out.detail(indent + printable(line));
|
|
361
364
|
}
|
|
362
365
|
/** Re-read after the run: a step may have fixed what the review showed, or not. */
|
|
363
366
|
async function blockersNow(git, account) {
|