repown 0.4.0 → 0.5.1

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +99 -1
  2. package/README.md +4 -1
  3. package/dist/cli.js +4 -4
  4. package/dist/commands/accounts.js +20 -14
  5. package/dist/commands/doctor.js +7 -5
  6. package/dist/commands/fix.js +5 -5
  7. package/dist/commands/guard.js +7 -5
  8. package/dist/commands/off.js +4 -4
  9. package/dist/commands/reauthor.js +5 -5
  10. package/dist/commands/scan.js +9 -7
  11. package/dist/commands/setup.js +3 -3
  12. package/dist/commands/start.js +6 -6
  13. package/dist/commands/status.js +20 -16
  14. package/dist/commands/use.js +18 -14
  15. package/dist/core/blockers.js +8 -7
  16. package/dist/core/config-snapshot.js +97 -0
  17. package/dist/core/credential/gcm.js +3 -3
  18. package/dist/core/credential/gh.js +14 -6
  19. package/dist/core/credential/repair.js +1 -1
  20. package/dist/core/git.js +27 -4
  21. package/dist/core/guard/check.js +44 -8
  22. package/dist/core/guard/hook.js +1 -1
  23. package/dist/core/hosts/github.js +43 -12
  24. package/dist/core/hosts/index.js +21 -3
  25. package/dist/core/identity.js +1 -1
  26. package/dist/core/inspect.js +19 -8
  27. package/dist/core/push-destination.js +1 -1
  28. package/dist/core/push-state.js +12 -8
  29. package/dist/core/reauthor.js +3 -3
  30. package/dist/core/registry.js +12 -5
  31. package/dist/core/unpushed.js +10 -9
  32. package/dist/program.js +10 -10
  33. package/dist/ui/args.js +3 -3
  34. package/dist/ui/command.js +1 -1
  35. package/dist/ui/dispatch.js +6 -6
  36. package/dist/ui/format.js +31 -0
  37. package/dist/ui/help.js +2 -2
  38. package/dist/ui/prompt.js +1 -1
  39. package/dist/wizard/clack.js +56 -21
  40. package/dist/wizard/engine.js +1 -1
  41. package/dist/wizard/home-context.js +23 -10
  42. package/dist/wizard/home-flow.js +33 -11
  43. package/dist/wizard/home-run.js +92 -44
  44. package/dist/wizard/home-text.js +18 -3
  45. package/dist/wizard/plain.js +2 -2
  46. package/dist/wizard/review-text.js +19 -4
  47. package/dist/wizard/setup-changes.js +2 -2
  48. package/dist/wizard/setup-context.js +22 -18
  49. package/dist/wizard/setup-flow.js +115 -35
  50. package/dist/wizard/setup-run.js +31 -28
  51. package/npm-shrinkwrap.json +378 -17
  52. package/package.json +3 -3
@@ -1,11 +1,13 @@
1
1
  // The words on the start screen, in one place, so the summary and both prompters
2
2
  // say the same thing. What is shown when comes from home-flow.ts.
3
- import { displayPath } from "../ui/format.js";
3
+ import { displayPath } from '../ui/format.js';
4
4
  export const WHAT_NEXT = 'What next?';
5
5
  export const WHICH_CLONE = 'Which clone?';
6
6
  export const SETUP_CLONE = 'Set up a clone found here';
7
7
  export const STOP_GH = 'Stop gh serving credentials';
8
8
  export const RECORD_ACCOUNT = 'Record an account';
9
+ export const REMOVE_ACCOUNT = 'Remove an account';
10
+ export const WHICH_ACCOUNT = 'Which account?';
9
11
  export const CHECK_MACHINE = 'Check this machine';
10
12
  export const SHOW_HELP = 'Show help';
11
13
  export const QUIT = 'Quit';
@@ -16,15 +18,24 @@ export const NONE_RECORDED = 'none recorded';
16
18
  export const HELPER_LINE = 'gh serves git\'s credentials: run repown fix';
17
19
  export const HINT_FIX = 'repown fix';
18
20
  export const HINT_ACCOUNT = 'repown accounts add';
21
+ export const HINT_REMOVE = 'repown accounts remove';
19
22
  export const HINT_DOCTOR = 'repown doctor';
20
23
  export const NOT_SET_UP = 'not set up';
21
24
  export const SET_UP = 'set up';
22
- export const LOGIN_MESSAGE = 'The account\'s user name (login)';
23
- export const LOGIN_HINT = 'the name you sign in with, e.g. octocat; not your email address';
24
25
  export const CANCELLED = 'Cancelled: nothing was changed.';
25
26
  export function homeTitle(cwd) {
26
27
  return 'repown · not a clone: ' + displayPath(cwd);
27
28
  }
29
+ /** What removing leaves as it was: said before the confirm, so nobody expects their clones to change. */
30
+ export function removeNote(login) {
31
+ return 'clones pinned to ' + login + ' keep their settings and the push guard; repown use ' + login + ' needs it recorded again';
32
+ }
33
+ export function removeQuestion(login) {
34
+ return 'Remove ' + login + ' from this machine?';
35
+ }
36
+ export function removeLabel(login) {
37
+ return 'Remove ' + login;
38
+ }
28
39
  export function recordedLine(names) {
29
40
  return names.length + ' recorded: ' + names.join(', ');
30
41
  }
@@ -33,6 +44,10 @@ export function unreadableLine(recorded, unreadable, path) {
33
44
  const tail = unreadable + ' unreadable in ' + path + ': run repown accounts list';
34
45
  return recorded === 0 ? tail : recorded + ' recorded, ' + tail;
35
46
  }
47
+ /** Said instead of the account questions when the answers could not be saved anyway. */
48
+ export function recordBlocked(reason) {
49
+ return 'Record an account needs an account list it can save: ' + reason.replace(/\.$/, '') + '. Nothing was asked.';
50
+ }
36
51
  export function couldNotRead(path) {
37
52
  return 'could not read ' + path;
38
53
  }
@@ -7,8 +7,8 @@
7
7
  // keeps carrying only what the commands themselves print. End of input or Ctrl-C at a
8
8
  // question is a cancel, never an answer.
9
9
  import { createInterface } from 'node:readline/promises';
10
- import { BACK, CANCEL } from "./engine.js";
11
- import { BACK_TO_REVIEW, PICK_QUESTION, RUN_THIS_STEP, reviewDefault, reviewLines, reviewOptions, reviewQuestion, stepConfirmLines, stepOptions, textWidth, wrap } from "./review-text.js";
10
+ import { BACK, CANCEL } from './engine.js';
11
+ import { BACK_TO_REVIEW, PICK_QUESTION, RUN_THIS_STEP, reviewDefault, reviewLines, reviewOptions, reviewQuestion, stepConfirmLines, stepOptions, textWidth, wrap } from './review-text.js';
12
12
  /** Typed at a text question, it means "go back" (never used for a real answer here). */
13
13
  export const BACK_WORD = '<';
14
14
  export function plainPrompter(streams) {
@@ -17,9 +17,14 @@ export function stepOptions() {
17
17
  { value: 'stop', label: 'Stop' },
18
18
  ];
19
19
  }
20
+ /**
21
+ * What starts a command line drawn to copy. Not `>`: pasted whole, that is a redirect in
22
+ * every shell and leaves a file named `repown`; `$` there is only a harmless error.
23
+ */
24
+ export const COMMAND_MARK = '$ ';
20
25
  /** What a step changes, why, and the command, in that order. */
21
26
  export function stepConfirmLines(brief) {
22
- return [...brief.changes, '', brief.why, '> ' + brief.command];
27
+ return [...brief.changes, '', brief.why, COMMAND_MARK + brief.command];
23
28
  }
24
29
  /** `fix` changes the whole machine; `reauthor` rewrites commits. */
25
30
  function needsDeliberateYes(command) {
@@ -31,8 +36,8 @@ function settledVerdict(review) {
31
36
  }
32
37
  /**
33
38
  * The body of the review, line by line, wrapped to `width`. `command` styles each
34
- * command line (dimmed where the prompter can draw colour), so the plain words stay
35
- * the eye's first stop.
39
+ * command line (cyan where the prompter can draw colour, ADR-027), so a command never
40
+ * reads as one of the plain words around it.
36
41
  */
37
42
  export function reviewLines(review, width = Infinity, command = (text) => text) {
38
43
  const words = (text) => wrap(text, width);
@@ -55,6 +60,16 @@ export const MAX_WIDTH = 72;
55
60
  export function textWidth(columns, margin) {
56
61
  return Math.max(24, Math.min(MAX_WIDTH, (columns ?? 80) - margin));
57
62
  }
63
+ /**
64
+ * What a wrapped line's continuation hangs under: any indent, then a "1. " step number or
65
+ * a "label " column (one or two words, then two spaces or more). Group 1 is the label.
66
+ */
67
+ const HANG = /^\s*(?:\d+\. |(\S+(?: \S+)? {2,}(?=\S)))?/;
68
+ /** The label column of a `label value` line, padding included; '' for any other line. */
69
+ export function labelOf(text) {
70
+ const found = HANG.exec(text);
71
+ return found[1] !== undefined && found[0] === found[1] ? found[1] : '';
72
+ }
58
73
  /**
59
74
  * One line, wrapped at spaces to `width`. Continuation lines line up under the text:
60
75
  * past any indent, a "1. " step number, or a "label " column.
@@ -62,7 +77,7 @@ export function textWidth(columns, margin) {
62
77
  export function wrap(text, width) {
63
78
  if (text.length <= width)
64
79
  return [text];
65
- const hang = ' '.repeat(/^\s*(?:\d+\. |\S+(?: \S+)? {2,})?/.exec(text)[0].length);
80
+ const hang = ' '.repeat(HANG.exec(text)[0].length);
66
81
  const lines = [];
67
82
  let line = '';
68
83
  for (const word of text.split(/(?<=\S) (?=\S)/)) {
@@ -1,8 +1,8 @@
1
1
  // What one setup run changed. The diff is pure. The read is this clone's local
2
2
  // config and the guard, through the Git wrapper. A credential helper is never
3
3
  // run: it can print a live password, and this report shows config values only.
4
- import { ACCOUNT_KEY, EMAIL_KEY, NAME_KEY, USE_CONFIG_ONLY_KEY } from "../core/identity.js";
5
- import { guardState } from "../core/guard/hook.js";
4
+ import { ACCOUNT_KEY, EMAIL_KEY, NAME_KEY, USE_CONFIG_ONLY_KEY } from '../core/identity.js';
5
+ import { guardState } from '../core/guard/hook.js';
6
6
  const ALLOW_OWNER = 'repown.allowOwner';
7
7
  const AUTO_UPSTREAM = 'push.autoSetupRemote';
8
8
  const LEADING = [NAME_KEY, EMAIL_KEY, USE_CONFIG_ONLY_KEY, ACCOUNT_KEY];
@@ -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 "../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 { 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 } from "./setup-flow.js";
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
- const repo = await inspectRepo(git);
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(git, repo, recorded, options);
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. */
@@ -200,11 +204,11 @@ function ghLogins(gh) {
200
204
  export async function askOwnerIsUser(repo, auth, options = {}) {
201
205
  if (options.classifyOwner === false)
202
206
  return null;
203
- if (repo.provider.id !== 'github' || !repo.owner)
207
+ if (repo.ownerProvider.id !== 'github' || !repo.owner)
204
208
  return null;
205
209
  if (signedIn(auth, repo.owner))
206
210
  return true;
207
- const ask = options.accountKind ?? repo.provider.accountKind;
211
+ const ask = options.accountKind ?? repo.ownerProvider.accountKind;
208
212
  if (!ask)
209
213
  return null;
210
214
  return asUser(await ask(repo.owner));
@@ -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?.resolveProfile?.(account) ?? Promise.resolve(null)).then((found) => found ?? {}));
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 "../commands/status.js";
10
- import { providers } from "../core/hosts/index.js";
11
- import { shellWord } from "../core/guard/check.js";
12
- import { printable } from "../ui/format.js";
13
- import { foreignAddresses, foreignCount } from "../core/unpushed.js";
14
- import { blockers } from "../core/blockers.js";
15
- import { pinWrites } from "../core/identity.js";
16
- import { stepDefault } from "./review-text.js";
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
- { id: 'newAccount', kind: 'text', flag: '<account>', message: 'The account\'s user name (login)',
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
- /** Where a GitHub account's private address comes from, for someone who has never looked. */
214
- function noreplyExample(answers, ctx) {
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+' + printable(accountOf(answers)) + '@users.noreply.github.com';
261
+ 'github.com/settings/emails, like 1234+' + account + '@users.noreply.github.com';
219
262
  }
220
- /** The machine's name, beside a new account. Never that account's initial value. */
221
- function nameDetail(answers, ctx) {
222
- const name = ctx.machineIdentity.name;
223
- if (!isNew(answers) || !name)
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
- return 'not this machine\'s default name (' + printable(name) + '), unless this account uses it';
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 gives no usable name for ' + printable(accountOf(answers)) + ', so this is the login' : 'this is the login';
226
294
  }
227
- /** Noreply tip first, then the machine address. Two sentences; both prompters wrap one detail. */
228
- function emailDetail(answers, ctx) {
229
- const tip = noreplyExample(answers, ctx);
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 'not this machine\'s default address (' + printable(email) + '), unless this account uses it';
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';
@@ -348,7 +420,7 @@ export const SOURCE_GH = 'signed in to gh';
348
420
  export const SOURCE_GCM = 'stored in Git Credential Manager';
349
421
  const OWNER_UNKNOWN = SOURCE_OWNS + '; may be an organisation';
350
422
  function accountChoices(ctx) {
351
- const recorded = Object.entries(ctx.recorded).map(([account, entry]) => ({ value: account, label: account, hint: entry.name + ' <' + entry.email + '>' }));
423
+ const recorded = Object.entries(ctx.recorded).map(([account, entry]) => ({ value: account, label: printable(account), hint: printable(entry.name + ' <' + entry.email + '>') }));
352
424
  const detected = ctx.detected.map((account) => detectedChoice(account, ctx));
353
425
  return [...recorded, ...detected, { value: NEW_ACCOUNT, label: 'a new account', hint: 'record another account on this machine' }];
354
426
  }
@@ -419,6 +491,8 @@ const LOGIN = /^[\w.@-]+$/;
419
491
  export function loginProblem(value) {
420
492
  if (!value.trim())
421
493
  return 'a value is required';
494
+ if (/^\.+$/.test(value))
495
+ return 'a login can\'t be only dots';
422
496
  return LOGIN.test(value) ? null : 'use letters, digits and . _ @ - only';
423
497
  }
424
498
  function newAccountProblem(value, ctx) {
@@ -469,8 +543,7 @@ export function planCommands(answers, ctx) {
469
543
  const planned = [
470
544
  repointArgv(answers, ctx),
471
545
  fetchArgv(answers, ctx),
472
- isNew(answers) ? ['accounts', 'add', '--name=' + String(answers['name']), '--email=' + String(answers['email']),
473
- '--host=' + hostOf(answers, ctx), '--', account] : null,
546
+ isNew(answers) ? addAccountArgv(newAccountOf(answers, ctx)) : null,
474
547
  answers['allowOwner'] === true && ctx.owner ? allowOwnerLine(ctx) : null,
475
548
  answers['fix'] === true ? ['fix', '--yes', ...cwd] : null,
476
549
  useArgv(answers, ctx),
@@ -560,21 +633,28 @@ function ghWhat(account, ctx) {
560
633
  function allowOwnerLine(ctx) {
561
634
  return [...gitIn(ctx), 'config', '--local', '--add', 'repown.allowOwner', ctx.owner];
562
635
  }
636
+ /** Shown in place of a word no quoting keeps literal in every shell (shellWord): it has run, or will, but don't paste it. */
637
+ export const UNQUOTABLE = '[value not safe to paste]';
638
+ function wordOf(value) {
639
+ return shellWord(value) ?? UNQUOTABLE;
640
+ }
563
641
  /**
564
642
  * 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.
643
+ * as `--name value`, and `--host github` left out because it's the default. A `--`
644
+ * before a dashed account comes out quoted (shellWord).
566
645
  */
567
646
  export function formatCommand(argv) {
568
647
  if (argv[0] === 'git')
569
- return printable(argv.map(shellWord).join(' '));
648
+ return printable(argv.map(wordOf).join(' '));
570
649
  const end = argv.indexOf('--');
571
650
  const head = end < 0 ? argv : argv.slice(0, end);
572
651
  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
652
  const dashed = positional.some((value) => value.startsWith('-'));
576
- const words = dashed ? [...path, ...options, '--', ...positional] : [...path, ...positional, ...options];
577
- return printable(['repown', ...words.map(shellWord)].join(' '));
653
+ const path = head.filter((token) => !token.startsWith('-')).map(wordOf);
654
+ const options = head.filter((token) => token.startsWith('-') && token !== '--host=github').flatMap(splitOption).map(wordOf);
655
+ const accounts = positional.map(wordOf);
656
+ const words = dashed ? [...path, ...options, wordOf('--'), ...accounts] : [...path, ...accounts, ...options];
657
+ return printable(['repown', ...words].join(' '));
578
658
  }
579
659
  /** Setup's own importers read it from here; the one definition is in the output helpers. */
580
660
  export { printable };
@@ -761,8 +841,8 @@ function notes(answers, ctx) {
761
841
  lines.push(guard);
762
842
  const guarded = answers['guard'] === true || ctx.guard === 'on';
763
843
  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
- 'git config --local --add repown.allowOwner ' + shellWord(ctx.owner));
844
+ lines.push('Warning: the push guard will refuse pushes to "' + printable(ctx.owner) + '". To allow them later: ' +
845
+ (allowOwnerCommand(ctx.owner) ?? ALLOW_OWNER_BY_HAND));
766
846
  }
767
847
  if (ctx.ghIsHelper && answers['fix'] !== true && ctx.credentialPinned) {
768
848
  lines.push('Note: gh is still git\'s credential helper, so pushes sign in as gh\'s active account, not ' + account + '.');
@@ -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 "../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 { blockers } from "../core/blockers.js";
26
- import { readPushFacts } from "../core/push-state.js";
27
- import { guardState, hookLocation } from "../core/guard/hook.js";
28
- import { readUnpushed } from "../core/unpushed.js";
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("./clack.js")).clackPrompter(streams);
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('> ' + formatCommand(planned.argv));
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(' ' + printable(line));
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) {