repown 0.3.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 +109 -1
- package/README.md +11 -3
- 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 +64 -0
- package/dist/commands/scan.js +7 -6
- package/dist/commands/setup.js +7 -4
- package/dist/commands/start.js +6 -6
- package/dist/commands/status.js +66 -22
- package/dist/commands/use.js +14 -14
- package/dist/core/blockers.js +133 -0
- 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 +145 -12
- package/dist/core/guard/check.js +48 -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 +82 -0
- package/dist/core/push-state.js +109 -0
- package/dist/core/reauthor.js +145 -0
- package/dist/core/registry.js +1 -1
- package/dist/core/unpushed.js +112 -43
- package/dist/program.js +10 -9
- 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 +39 -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 +7 -4
- 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 +36 -14
- package/dist/wizard/setup-changes.js +11 -7
- package/dist/wizard/setup-context.js +31 -20
- package/dist/wizard/setup-flow.js +265 -56
- package/dist/wizard/setup-run.js +108 -40
- package/npm-shrinkwrap.json +378 -17
- package/package.json +3 -3
|
@@ -6,16 +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 {
|
|
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';
|
|
15
18
|
/** The "a new account" choice. Empty, so it can never be a real account's name. */
|
|
16
19
|
export const NEW_ACCOUNT = '';
|
|
17
20
|
/** A detected choice's value. The login grammar refuses '+', so a recorded account cannot collide. */
|
|
18
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
|
+
}
|
|
19
37
|
const lower = (value) => value.toLowerCase();
|
|
20
38
|
/** The account the answers are about: a recorded one, a detected login, or the new one typed in. */
|
|
21
39
|
export function accountOf(answers) {
|
|
@@ -53,9 +71,15 @@ function openingReview(ctx) {
|
|
|
53
71
|
function resumeAt(choice, ctx) {
|
|
54
72
|
if (choice === 'gh')
|
|
55
73
|
return { answers: ghAnswers(ctx), start: steps(ctx).length };
|
|
74
|
+
if (choice === 'reauthor')
|
|
75
|
+
return { answers: reauthorAnswers(ctx), start: steps(ctx).length };
|
|
56
76
|
const start = steps(ctx).findIndex((step) => step.id === 'account');
|
|
57
77
|
return { answers: { mode: 'recommended' }, start: start < 0 ? 0 : start };
|
|
58
78
|
}
|
|
79
|
+
/** The settled screen's Re-author them: the pinned account's answers, with that one step. */
|
|
80
|
+
function reauthorAnswers(ctx) {
|
|
81
|
+
return recommendedAnswers({ mode: 'recommended', account: ctx.pinned ?? '', reauthor: true }, ctx);
|
|
82
|
+
}
|
|
59
83
|
function ghAnswers(ctx) {
|
|
60
84
|
return recommendedAnswers({ mode: 'recommended', account: ctx.pinned ?? '', gh: true }, ctx);
|
|
61
85
|
}
|
|
@@ -84,6 +108,21 @@ function steps(ctx) {
|
|
|
84
108
|
return [
|
|
85
109
|
modeStep(),
|
|
86
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 [
|
|
87
126
|
{ id: 'host', kind: 'select', flag: '--host', message: 'Where is this account hosted?',
|
|
88
127
|
hint: 'on GitHub, repown also makes pushes sign in as this account', when: (answers) => isNew(answers),
|
|
89
128
|
choices: () => hostChoices(), initial: () => ctx.host },
|
|
@@ -95,9 +134,16 @@ function steps(ctx) {
|
|
|
95
134
|
hint: 'anyone who can see the repository can read it once you push', when: (answers) => isNew(answers), validate: required,
|
|
96
135
|
initial: async (answers) => (await ctx.suggest(accountOf(answers), hostOf(answers, ctx))).email,
|
|
97
136
|
detail: (answers) => emailDetail(answers, ctx) },
|
|
98
|
-
...choiceSteps(ctx),
|
|
99
137
|
];
|
|
100
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
|
+
}
|
|
101
147
|
function modeStep() {
|
|
102
148
|
return {
|
|
103
149
|
id: 'mode', kind: 'select', flag: '--step-by-step',
|
|
@@ -121,13 +167,13 @@ function accountSteps(ctx) {
|
|
|
121
167
|
when: () => Object.keys(ctx.recorded).length > 0 || ctx.detected.length > 0,
|
|
122
168
|
choices: () => accountChoices(ctx), initial: () => defaultAccount(ctx),
|
|
123
169
|
detail: () => (ctx.pinned ? 'right now this clone is pinned to ' + ctx.pinned : 'right now this clone isn\'t pinned to any account') },
|
|
124
|
-
{
|
|
125
|
-
hint: 'the name you sign in with, e.g. octocat; not your email address', when: (answers) => asksForLogin(answers),
|
|
126
|
-
validate: (value) => newAccountProblem(String(value), ctx), initial: () => ownerInitial(ctx) },
|
|
170
|
+
{ ...loginStep(ctx), when: (answers) => asksForLogin(answers), initial: () => ownerInitial(ctx) },
|
|
127
171
|
];
|
|
128
172
|
}
|
|
129
173
|
function choiceSteps(ctx) {
|
|
130
174
|
return [
|
|
175
|
+
repointStep(ctx),
|
|
176
|
+
fetchStep(ctx),
|
|
131
177
|
ghStep(ctx),
|
|
132
178
|
{ id: 'allowOwner', kind: 'confirm', flag: '--allow-owner', initial: () => true,
|
|
133
179
|
message: 'This repository belongs to "' + printable(ctx.owner ?? '') + '". Let this clone push to it?',
|
|
@@ -144,8 +190,50 @@ function choiceSteps(ctx) {
|
|
|
144
190
|
hint: 'undo any time: gh auth setup-git', initial: () => false, when: () => ctx.fixLines !== null,
|
|
145
191
|
detail: () => 'gh answers git\'s sign-in requests with its active account only, so clones of your other accounts ' +
|
|
146
192
|
'get password prompts. Yes hands that job back to Git Credential Manager, for every repository on this machine' },
|
|
193
|
+
reauthorStep(ctx),
|
|
147
194
|
];
|
|
148
195
|
}
|
|
196
|
+
/** Never answered by Recommended: only the user knows whether they made those commits. */
|
|
197
|
+
function reauthorStep(ctx) {
|
|
198
|
+
return {
|
|
199
|
+
id: 'reauthor', kind: 'confirm', flag: '--reauthor', initial: () => false,
|
|
200
|
+
message: (answers) => 'Re-author your unpushed commits by ' + printable(othersOf(answers, ctx).join(', ')) +
|
|
201
|
+
' as ' + printable(accountOf(answers)) + '?',
|
|
202
|
+
hint: 'only if you made them: they get this account\'s name and email. repown fetches first, rewrites only ' +
|
|
203
|
+
'what no remote has, keeps a backup, and never pushes',
|
|
204
|
+
when: (answers) => reauthorOffered(answers, ctx),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* `--repoint`, `--fetch` and `--reauthor` apply only where their step would be asked; elsewhere
|
|
209
|
+
* each is turned off with a note saying why. Read before any question, so a repoint not yet
|
|
210
|
+
* answered counts as the Yes Recommended gives it (a later No drops the fetch from the plan).
|
|
211
|
+
*/
|
|
212
|
+
export function keptFlags(given, ctx) {
|
|
213
|
+
const answers = { ...given };
|
|
214
|
+
const notes = [];
|
|
215
|
+
const drop = (key, note) => { answers[key] = false; notes.push('--' + key + ': ' + note); };
|
|
216
|
+
if (answers['repoint'] === true && !ctx.push.repoint)
|
|
217
|
+
drop('repoint', 'this branch does not push to a URL that a remote here names, so there is nothing to repoint');
|
|
218
|
+
if (answers['fetch'] === true && fetchTarget({ ...answers, repoint: answers['repoint'] ?? true }, ctx) === null)
|
|
219
|
+
drop('fetch', fetchDropped(answers, ctx));
|
|
220
|
+
if (answers['reauthor'] === true && !reauthorOffered(answers, ctx))
|
|
221
|
+
drop('reauthor', 'no unpushed commit here is by another address, so there is nothing to re-author');
|
|
222
|
+
return { answers, notes };
|
|
223
|
+
}
|
|
224
|
+
function fetchDropped(answers, ctx) {
|
|
225
|
+
if (answers['repoint'] === false && fetchTarget({ ...answers, repoint: true }, ctx) !== null) {
|
|
226
|
+
return 'this branch pushes to a URL, so fetching ' + printable(ctx.push.repoint.remote) + ' tells nothing about it: add --repoint';
|
|
227
|
+
}
|
|
228
|
+
return 'no commit by another address waits behind a remote this clone has never fetched, so there is nothing to fetch';
|
|
229
|
+
}
|
|
230
|
+
/** Some unpushed commits carry an address other than the chosen account's. */
|
|
231
|
+
export function reauthorOffered(answers, ctx) {
|
|
232
|
+
return othersOf(answers, ctx).length > 0;
|
|
233
|
+
}
|
|
234
|
+
function othersOf(answers, ctx) {
|
|
235
|
+
return foreignAddresses(ctx.unpushed, emailOf(answers, ctx) ?? '');
|
|
236
|
+
}
|
|
149
237
|
/** Labels for a newcomer; the providers' own labels stay as `repown` prints them elsewhere. */
|
|
150
238
|
const HOSTS = {
|
|
151
239
|
github: ['GitHub', 'name, email and the sign-in for pushes'],
|
|
@@ -158,23 +246,59 @@ function hostChoices() {
|
|
|
158
246
|
return { value: provider.id, label, ...(hint ? { hint } : {}) };
|
|
159
247
|
});
|
|
160
248
|
}
|
|
161
|
-
/**
|
|
162
|
-
|
|
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) {
|
|
163
254
|
if (hostOf(answers, ctx) !== 'github')
|
|
164
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)';
|
|
165
260
|
return 'tip: to keep your own address private, use the one GitHub gives you, shown at ' +
|
|
166
|
-
'github.com/settings/emails, like 1234+' +
|
|
261
|
+
'github.com/settings/emails, like 1234+' + account + '@users.noreply.github.com';
|
|
167
262
|
}
|
|
168
|
-
/**
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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))
|
|
172
270
|
return undefined;
|
|
173
|
-
|
|
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';
|
|
294
|
+
}
|
|
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;
|
|
174
298
|
}
|
|
175
|
-
/**
|
|
176
|
-
function emailDetail(answers, ctx) {
|
|
177
|
-
const tip =
|
|
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);
|
|
178
302
|
const line = addressDetail(answers, ctx);
|
|
179
303
|
if (tip && line)
|
|
180
304
|
return tip + '; ' + line;
|
|
@@ -184,7 +308,7 @@ function addressDetail(answers, ctx) {
|
|
|
184
308
|
const email = ctx.machineIdentity.email;
|
|
185
309
|
if (!isNew(answers) || !email)
|
|
186
310
|
return undefined;
|
|
187
|
-
return '
|
|
311
|
+
return 'your default git address here is ' + printable(email) + ': use it only if this account does too';
|
|
188
312
|
}
|
|
189
313
|
const UPSTREAM_HINT = 'sets push.autoSetupRemote in this clone only, so the first push of a branch without an upstream ' +
|
|
190
314
|
'creates it on origin; the guard still checks it';
|
|
@@ -199,6 +323,40 @@ function upstreamStep(ctx) {
|
|
|
199
323
|
when: () => offersUpstream(ctx), auto: isRecommended,
|
|
200
324
|
};
|
|
201
325
|
}
|
|
326
|
+
function repointStep(ctx) {
|
|
327
|
+
const target = ctx.push.repoint;
|
|
328
|
+
return {
|
|
329
|
+
id: 'repoint', kind: 'confirm', flag: '--repoint', initial: () => true, auto: isRecommended,
|
|
330
|
+
message: 'Push through ' + printable(target?.remote ?? '') + ' instead of the URL set for this branch?',
|
|
331
|
+
hint: 'that URL names the same repository as ' + printable(target?.remote ?? '') + ', but it can carry its own sign-in, so ' +
|
|
332
|
+
'pushes would not sign in as this account, and it is never fetched. Changes ' + printable(target?.key ?? '') + ', this clone only',
|
|
333
|
+
when: () => target !== null,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function fetchStep(ctx) {
|
|
337
|
+
return {
|
|
338
|
+
id: 'fetch', kind: 'confirm', flag: '--fetch', initial: () => true, auto: isRecommended,
|
|
339
|
+
message: (answers) => 'Fetch ' + printable(fetchTarget(answers, ctx) ?? '') + ' first?',
|
|
340
|
+
hint: (answers) => 'so repown can tell which of your unpushed commits ' + printable(fetchTarget(answers, ctx) ?? '') +
|
|
341
|
+
' already has; downloads only, moves none of your branches, and never asks for a password',
|
|
342
|
+
when: (answers) => fetchTarget(answers, ctx) !== null,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* The remote to fetch before counting: commits by another address, behind a remote no
|
|
347
|
+
* tracking ref reaches -- the destination itself, or the remote a repoint makes it.
|
|
348
|
+
*/
|
|
349
|
+
export function fetchTarget(answers, ctx) {
|
|
350
|
+
if (foreignCount(ctx.unpushed, emailOf(answers, ctx) ?? '') === 0)
|
|
351
|
+
return null;
|
|
352
|
+
const unknown = ctx.unpushed.unknown;
|
|
353
|
+
if (unknown?.kind === 'remote')
|
|
354
|
+
return unknown.name;
|
|
355
|
+
const repoint = ctx.push.repoint;
|
|
356
|
+
if (unknown?.kind !== 'url' || !repoint || repoint.tracked || answers['repoint'] !== true)
|
|
357
|
+
return null;
|
|
358
|
+
return repoint.remote;
|
|
359
|
+
}
|
|
202
360
|
const SWITCH_MESSAGE = 'Also make this account gh\'s active account?';
|
|
203
361
|
const SWITCH_HINT = 'gh is GitHub\'s command-line tool: this changes the account gh commands use, in every terminal; git is not affected';
|
|
204
362
|
function ghStep(ctx) {
|
|
@@ -381,13 +539,15 @@ export function planCommands(answers, ctx) {
|
|
|
381
539
|
const account = accountOf(answers);
|
|
382
540
|
const cwd = ctx.cwd ? ['--cwd=' + ctx.cwd] : [];
|
|
383
541
|
const planned = [
|
|
384
|
-
|
|
385
|
-
|
|
542
|
+
repointArgv(answers, ctx),
|
|
543
|
+
fetchArgv(answers, ctx),
|
|
544
|
+
isNew(answers) ? addAccountArgv(newAccountOf(answers, ctx)) : null,
|
|
386
545
|
answers['allowOwner'] === true && ctx.owner ? allowOwnerLine(ctx) : null,
|
|
387
546
|
answers['fix'] === true ? ['fix', '--yes', ...cwd] : null,
|
|
388
547
|
useArgv(answers, ctx),
|
|
389
548
|
answers['guard'] === true ? ['guard', 'on', ...cwd] : null,
|
|
390
549
|
upstreamArgv(answers, ctx),
|
|
550
|
+
answers['reauthor'] === true && reauthorOffered(answers, ctx) ? ['reauthor', '--yes', ...cwd] : null,
|
|
391
551
|
];
|
|
392
552
|
return planned.filter((argv) => argv !== null).map((argv) => ({ argv, what: whatOf(argv, answers, ctx) }));
|
|
393
553
|
}
|
|
@@ -407,8 +567,33 @@ function upstreamArgv(answers, ctx) {
|
|
|
407
567
|
return null;
|
|
408
568
|
return autoUpstreamLine(ctx);
|
|
409
569
|
}
|
|
570
|
+
function gitIn(ctx) {
|
|
571
|
+
return ['git', ...(ctx.cwd ? ['-C', ctx.cwd] : [])];
|
|
572
|
+
}
|
|
410
573
|
function autoUpstreamLine(ctx) {
|
|
411
|
-
return [
|
|
574
|
+
return [...gitIn(ctx), 'config', '--local', 'push.autoSetupRemote', 'true'];
|
|
575
|
+
}
|
|
576
|
+
function repointArgv(answers, ctx) {
|
|
577
|
+
const target = ctx.push.repoint;
|
|
578
|
+
if (answers['repoint'] !== true || !target)
|
|
579
|
+
return null;
|
|
580
|
+
return [...gitIn(ctx), 'config', '--local', target.key, target.remote];
|
|
581
|
+
}
|
|
582
|
+
function fetchArgv(answers, ctx) {
|
|
583
|
+
const remote = answers['fetch'] === true ? fetchTarget(answers, ctx) : null;
|
|
584
|
+
return remote ? [...gitIn(ctx), 'fetch', remote] : null;
|
|
585
|
+
}
|
|
586
|
+
export function gitStepOf(argv) {
|
|
587
|
+
const sub = argv[1] === '-C' ? argv.slice(3) : argv.slice(1);
|
|
588
|
+
if (sub[0] === 'fetch' && sub.length === 2)
|
|
589
|
+
return 'fetch';
|
|
590
|
+
if (sub[0] !== 'config' || sub[1] !== '--local')
|
|
591
|
+
return null;
|
|
592
|
+
if (sub[2] === '--add' && sub[3] === 'repown.allowOwner' && sub.length === 5)
|
|
593
|
+
return 'allowOwner';
|
|
594
|
+
if (sub[2] === 'push.autoSetupRemote' && sub.length === 4)
|
|
595
|
+
return 'upstream';
|
|
596
|
+
return sub.length === 4 ? 'repoint' : null;
|
|
412
597
|
}
|
|
413
598
|
/** What a planned command does, in words for someone who has never used repown. */
|
|
414
599
|
function whatOf(argv, answers, ctx) {
|
|
@@ -421,12 +606,19 @@ function whatOf(argv, answers, ctx) {
|
|
|
421
606
|
return 'Stop gh answering git\'s sign-in requests (whole machine)';
|
|
422
607
|
if (argv[0] === 'guard')
|
|
423
608
|
return 'Turn on the push guard: each push is checked first';
|
|
609
|
+
if (argv[0] === 'reauthor')
|
|
610
|
+
return 'Re-author your unpushed commits by other addresses as ' + account + ' (a backup is kept; nothing is pushed)';
|
|
424
611
|
if (answers['gh'] === true)
|
|
425
612
|
return ghWhat(account, ctx);
|
|
426
613
|
return 'Pin this clone to ' + account + (ctx.credentialPinned ? ': its commit name, email and push sign-in' : ': its commit name and email');
|
|
427
614
|
}
|
|
428
615
|
function gitWhat(argv, ctx) {
|
|
429
|
-
|
|
616
|
+
const step = gitStepOf(argv);
|
|
617
|
+
if (step === 'repoint')
|
|
618
|
+
return 'Push through ' + argv.at(-1) + ' instead of the URL in ' + argv.at(-2) + ' (this clone only)';
|
|
619
|
+
if (step === 'fetch')
|
|
620
|
+
return 'Fetch ' + argv.at(-1) + ', so repown can tell which commits it already has';
|
|
621
|
+
if (step === 'upstream')
|
|
430
622
|
return 'Push branches without -u: the first push sets the upstream (this clone only)';
|
|
431
623
|
return 'Let this clone push to ' + ctx.owner + '\'s repositories';
|
|
432
624
|
}
|
|
@@ -437,31 +629,33 @@ function ghWhat(account, ctx) {
|
|
|
437
629
|
return pin + 'sign ' + account + ' in to gh (opens your browser)';
|
|
438
630
|
}
|
|
439
631
|
function allowOwnerLine(ctx) {
|
|
440
|
-
return [
|
|
632
|
+
return [...gitIn(ctx), 'config', '--local', '--add', 'repown.allowOwner', ctx.owner];
|
|
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;
|
|
441
638
|
}
|
|
442
639
|
/**
|
|
443
640
|
* The command as you would type it: the account where it reads naturally, options
|
|
444
|
-
* 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).
|
|
445
643
|
*/
|
|
446
644
|
export function formatCommand(argv) {
|
|
447
645
|
if (argv[0] === 'git')
|
|
448
|
-
return printable(argv.map(
|
|
646
|
+
return printable(argv.map(wordOf).join(' '));
|
|
449
647
|
const end = argv.indexOf('--');
|
|
450
648
|
const head = end < 0 ? argv : argv.slice(0, end);
|
|
451
649
|
const positional = end < 0 ? [] : argv.slice(end + 1);
|
|
452
|
-
const path = head.filter((token) => !token.startsWith('-'));
|
|
453
|
-
const options = head.filter((token) => token.startsWith('-') && token !== '--host=github').flatMap(splitOption);
|
|
454
650
|
const dashed = positional.some((value) => value.startsWith('-'));
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
*/
|
|
462
|
-
export
|
|
463
|
-
return text.replace(/[\x00-\x1f\x7f-\x9f\u200b-\u200f\u202a-\u202e\u2066-\u2069]/g, (char) => '\\u' + char.charCodeAt(0).toString(16).padStart(4, '0'));
|
|
464
|
-
}
|
|
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(' '));
|
|
656
|
+
}
|
|
657
|
+
/** Setup's own importers read it from here; the one definition is in the output helpers. */
|
|
658
|
+
export { printable };
|
|
465
659
|
/** `--name=value` as `--name value`, unless the value starts with a dash and would read as an option. */
|
|
466
660
|
function splitOption(token) {
|
|
467
661
|
const at = token.indexOf('=');
|
|
@@ -498,9 +692,12 @@ function pendingReview(answers, ctx, steps, plan) {
|
|
|
498
692
|
}
|
|
499
693
|
function settledReview(answers, ctx, steps, plan) {
|
|
500
694
|
const offer = ghOffer(accountOf(answers), ctx);
|
|
695
|
+
const reauthor = reauthorOffered(answers, ctx) ? { reauthorOffer: 'Re-author them as ' + printable(accountOf(answers)) } : {};
|
|
501
696
|
const shown = {
|
|
697
|
+
...reauthor,
|
|
502
698
|
title: 'This clone is already set up', headline: settledLines(answers, ctx).map(printable), steps,
|
|
503
699
|
notes: [...noted(settledNotes(answers, ctx), answers, ctx, plan), ...ghNote(answers, ctx, true)], settled: true,
|
|
700
|
+
blocked: blockersOf(answers, ctx).some((blocker) => blocker.blocks),
|
|
504
701
|
};
|
|
505
702
|
return offer ? { ...shown, ghSignIn: offer } : shown;
|
|
506
703
|
}
|
|
@@ -515,11 +712,22 @@ function upstreamOffer(ctx) {
|
|
|
515
712
|
return null;
|
|
516
713
|
return 'optional: push branches without -u: repown setup --auto-upstream';
|
|
517
714
|
}
|
|
715
|
+
/** What blocks the next push first (ADR-026), then the step's own notes. */
|
|
518
716
|
function noted(lines, answers, ctx, plan) {
|
|
519
717
|
const gap = credentialGap(plan, answers, ctx);
|
|
520
|
-
const
|
|
718
|
+
const found = blockersOf(answers, ctx);
|
|
719
|
+
const upstream = found.some((blocker) => blocker.summary.endsWith('has no upstream')) ? null : upstreamNote(ctx);
|
|
720
|
+
const body = [...found.flatMap((blocker) => blocker.lines), ...lines, ...(upstream ? [upstream] : []), ...(gap ? [gap] : [])];
|
|
521
721
|
return body.map(printable);
|
|
522
722
|
}
|
|
723
|
+
/** The address depends on the account, so the commits were read once and are compared here. */
|
|
724
|
+
export function blockersOf(answers, ctx) {
|
|
725
|
+
const email = emailOf(answers, ctx) ?? '';
|
|
726
|
+
const unpushed = email || !ctx.unpushed.commits.ok ? ctx.unpushed : { ...ctx.unpushed, branch: null };
|
|
727
|
+
const autoUpstream = answers['upstream'] === true || ctx.upstream.enabled === true;
|
|
728
|
+
const guarded = answers['guard'] === true || ctx.guard !== 'off' || ctx.redirected;
|
|
729
|
+
return blockers({ ...ctx.push, unpushed }, { email, account: accountOf(answers), autoUpstream, guarded });
|
|
730
|
+
}
|
|
523
731
|
/** use's own line, said here only when this run will not run use. Mirrors use.ts credentialConcern. */
|
|
524
732
|
function credentialGap(plan, answers, ctx) {
|
|
525
733
|
if (plan.some((command) => command.argv[0] === 'use') || !ctx.credentialPinned || !ctx.stored?.ok)
|
|
@@ -529,17 +737,6 @@ function credentialGap(plan, answers, ctx) {
|
|
|
529
737
|
return null;
|
|
530
738
|
return 'No stored credential for ' + account + ' yet: the first push signs in once (your browser opens).';
|
|
531
739
|
}
|
|
532
|
-
function extraNotes(answers, ctx) {
|
|
533
|
-
const upstream = upstreamNote(ctx);
|
|
534
|
-
return [...(upstream ? [upstream] : []), ...unpushedNote(answers, ctx)];
|
|
535
|
-
}
|
|
536
|
-
/** The address depends on the account, so the commits were read once and are compared here. */
|
|
537
|
-
function unpushedNote(answers, ctx) {
|
|
538
|
-
const email = emailOf(answers, ctx) ?? '';
|
|
539
|
-
if (!email && ctx.unpushed.commits.ok)
|
|
540
|
-
return [];
|
|
541
|
-
return unpushedLines(ctx.unpushed, email);
|
|
542
|
-
}
|
|
543
740
|
/** Old git, or a version that could not be read: say the push the question would have replaced. */
|
|
544
741
|
function upstreamNote(ctx) {
|
|
545
742
|
if (ctx.upstream.supported)
|
|
@@ -642,8 +839,8 @@ function notes(answers, ctx) {
|
|
|
642
839
|
lines.push(guard);
|
|
643
840
|
const guarded = answers['guard'] === true || ctx.guard === 'on';
|
|
644
841
|
if (guarded && ownerForeign(account, ctx) && answers['allowOwner'] !== true) {
|
|
645
|
-
lines.push('Warning: the push guard will refuse pushes to "' + ctx.owner + '". To allow them later: ' +
|
|
646
|
-
|
|
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));
|
|
647
844
|
}
|
|
648
845
|
if (ctx.ghIsHelper && answers['fix'] !== true && ctx.credentialPinned) {
|
|
649
846
|
lines.push('Note: gh is still git\'s credential helper, so pushes sign in as gh\'s active account, not ' + account + '.');
|
|
@@ -684,6 +881,8 @@ export function changesOf(argv, answers, ctx) {
|
|
|
684
881
|
return fixChanges(ctx);
|
|
685
882
|
if (argv[0] === 'guard')
|
|
686
883
|
return [guardChange(ctx)];
|
|
884
|
+
if (argv[0] === 'reauthor')
|
|
885
|
+
return [reauthorChange(answers, ctx)];
|
|
687
886
|
return useChanges(argv, answers, ctx);
|
|
688
887
|
}
|
|
689
888
|
/** The confirmation shown before a step in step-by-step mode. */
|
|
@@ -703,10 +902,20 @@ function registryChange(answers) {
|
|
|
703
902
|
return 'this machine\'s account registry: ' + account + ' = ' + name + ' ' + email;
|
|
704
903
|
}
|
|
705
904
|
function gitChange(argv) {
|
|
706
|
-
|
|
905
|
+
const step = gitStepOf(argv);
|
|
906
|
+
if (step === 'repoint')
|
|
907
|
+
return argv.at(-2) + ' = ' + argv.at(-1);
|
|
908
|
+
if (step === 'fetch')
|
|
909
|
+
return 'refs/remotes/' + argv.at(-1) + '/*: updated from ' + argv.at(-1) + ' (none of your branches move)';
|
|
910
|
+
if (step === 'upstream')
|
|
707
911
|
return 'push.autoSetupRemote = true';
|
|
708
912
|
return 'repown.allowOwner += ' + (argv.at(-1) ?? '');
|
|
709
913
|
}
|
|
914
|
+
function reauthorChange(answers, ctx) {
|
|
915
|
+
const branch = ctx.unpushed.branch ?? 'this branch';
|
|
916
|
+
return branch + ': unpushed commits by ' + othersOf(answers, ctx).join(', ') + ' get ' + (emailOf(answers, ctx) ?? '') +
|
|
917
|
+
'; the original stays at refs/repown/backup/' + branch + '/<time>';
|
|
918
|
+
}
|
|
710
919
|
function fixChanges(ctx) {
|
|
711
920
|
return (ctx.fixLines ?? []).filter((line) => line.trim() !== '');
|
|
712
921
|
}
|