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,9 +6,9 @@
|
|
|
6
6
|
export const PICK_QUESTION = 'Which answer do you want to change?';
|
|
7
7
|
export const BACK_TO_REVIEW = 'Back to the review';
|
|
8
8
|
export const RUN_THIS_STEP = 'Run this step?';
|
|
9
|
-
/** Yes, unless the command changes the whole machine: that needs a deliberate yes, as in the review. */
|
|
9
|
+
/** Yes, unless the command changes the whole machine or rewrites commits: that needs a deliberate yes, as in the review. */
|
|
10
10
|
export function stepDefault(command) {
|
|
11
|
-
return
|
|
11
|
+
return needsDeliberateYes(command) ? 'skip' : 'yes';
|
|
12
12
|
}
|
|
13
13
|
export function stepOptions() {
|
|
14
14
|
return [
|
|
@@ -17,24 +17,34 @@ 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,
|
|
27
|
+
return [...brief.changes, '', brief.why, COMMAND_MARK + brief.command];
|
|
28
|
+
}
|
|
29
|
+
/** `fix` changes the whole machine; `reauthor` rewrites commits. */
|
|
30
|
+
function needsDeliberateYes(command) {
|
|
31
|
+
return command.startsWith('repown fix') || command.startsWith('repown reauthor');
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
/** A settled clone's verdict: its settings are right; the notes say what else is not (ADR-026). */
|
|
34
|
+
function settledVerdict(review) {
|
|
35
|
+
return review.blocked ? 'Its settings need no change, but the next push will fail:' : 'Nothing needs to change.';
|
|
26
36
|
}
|
|
27
37
|
/**
|
|
28
38
|
* The body of the review, line by line, wrapped to `width`. `command` styles each
|
|
29
|
-
* command line (
|
|
30
|
-
* the
|
|
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.
|
|
31
41
|
*/
|
|
32
42
|
export function reviewLines(review, width = Infinity, command = (text) => text) {
|
|
33
43
|
const words = (text) => wrap(text, width);
|
|
34
44
|
// A command's continuation sits deeper, so it can't read as the next command.
|
|
35
45
|
const code = (text) => wrap(' ' + text, width - 2).map((line, index) => command(index ? ' ' + line : line));
|
|
36
46
|
if (review.settled)
|
|
37
|
-
return [...review.headline.flatMap(words), '',
|
|
47
|
+
return [...review.headline.flatMap(words), '', settledVerdict(review), ...notesOf(review).flatMap(words)];
|
|
38
48
|
const steps = review.steps.flatMap((step, index) => [
|
|
39
49
|
...words((index + 1) + '. ' + step.what),
|
|
40
50
|
...code(step.command),
|
|
@@ -50,6 +60,16 @@ export const MAX_WIDTH = 72;
|
|
|
50
60
|
export function textWidth(columns, margin) {
|
|
51
61
|
return Math.max(24, Math.min(MAX_WIDTH, (columns ?? 80) - margin));
|
|
52
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
|
+
}
|
|
53
73
|
/**
|
|
54
74
|
* One line, wrapped at spaces to `width`. Continuation lines line up under the text:
|
|
55
75
|
* past any indent, a "1. " step number, or a "label " column.
|
|
@@ -57,7 +77,7 @@ export function textWidth(columns, margin) {
|
|
|
57
77
|
export function wrap(text, width) {
|
|
58
78
|
if (text.length <= width)
|
|
59
79
|
return [text];
|
|
60
|
-
const hang = ' '.repeat(
|
|
80
|
+
const hang = ' '.repeat(HANG.exec(text)[0].length);
|
|
61
81
|
const lines = [];
|
|
62
82
|
let line = '';
|
|
63
83
|
for (const word of text.split(/(?<=\S) (?=\S)/)) {
|
|
@@ -88,7 +108,7 @@ export function reviewOptions(review) {
|
|
|
88
108
|
{ value: 'decline', label: 'Decline', hint: 'change nothing and exit' },
|
|
89
109
|
];
|
|
90
110
|
}
|
|
91
|
-
/** Done, then a way to pick another account
|
|
111
|
+
/** Done, then a way to pick another account, sign in to gh or re-author. Change an answer stays once questions were asked. */
|
|
92
112
|
function settledOptions(review) {
|
|
93
113
|
const options = [
|
|
94
114
|
{ value: 'done', label: 'Done', hint: 'change nothing' },
|
|
@@ -96,15 +116,17 @@ function settledOptions(review) {
|
|
|
96
116
|
];
|
|
97
117
|
if (review.ghSignIn)
|
|
98
118
|
options.push({ value: 'gh', label: review.ghSignIn });
|
|
119
|
+
if (review.reauthorOffer)
|
|
120
|
+
options.push({ value: 'reauthor', label: review.reauthorOffer, hint: 'only if you made them; a backup is kept' });
|
|
99
121
|
if (review.edits !== false)
|
|
100
122
|
options.push({ value: 'edit', label: 'Change an answer' });
|
|
101
123
|
return options;
|
|
102
124
|
}
|
|
103
125
|
/**
|
|
104
|
-
* The choice Enter takes: the first, unless a step changes the whole machine
|
|
105
|
-
* (`fix`), which, like its own question, needs a deliberate yes.
|
|
126
|
+
* The choice Enter takes: the first, unless a step changes the whole machine or rewrites commits
|
|
127
|
+
* (`fix`, `reauthor`), which, like its own question, needs a deliberate yes.
|
|
106
128
|
*/
|
|
107
129
|
export function reviewDefault(review) {
|
|
108
|
-
const
|
|
109
|
-
return !review.settled &&
|
|
130
|
+
const deliberate = review.steps.some((step) => needsDeliberateYes(step.command));
|
|
131
|
+
return !review.settled && deliberate ? 'decline' : reviewOptions(review)[0].value;
|
|
110
132
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
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
|
|
5
|
-
import { guardState } from
|
|
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];
|
|
9
|
-
export async function readCloneSnapshot(git,
|
|
10
|
-
const keys = [...LEADING, ...
|
|
9
|
+
export async function readCloneSnapshot(git, watched) {
|
|
10
|
+
const keys = [...LEADING, ...watched];
|
|
11
11
|
const found = await Promise.all(keys.map((key) => git.getConfig(key, 'local')));
|
|
12
12
|
const [allowOwner, autoUpstream, guard] = await Promise.all([
|
|
13
13
|
git.getAllConfig(ALLOW_OWNER, 'local'),
|
|
@@ -42,10 +42,14 @@ function valueChange(key, before, after) {
|
|
|
42
42
|
if (before === after)
|
|
43
43
|
return null;
|
|
44
44
|
if (before === null)
|
|
45
|
-
return ' ' + key + ': (added) ' + after;
|
|
45
|
+
return ' ' + key + ': (added) ' + shown(after);
|
|
46
46
|
if (after === null)
|
|
47
|
-
return ' ' + key + ': ' + before + ' -> (removed)';
|
|
48
|
-
return ' ' + key + ': ' + before + ' -> ' + after;
|
|
47
|
+
return ' ' + key + ': ' + shown(before) + ' -> (removed)';
|
|
48
|
+
return ' ' + key + ': ' + shown(before) + ' -> ' + shown(after);
|
|
49
|
+
}
|
|
50
|
+
/** A URL (`scheme://` or scp-style `user@host:`) can hold a token: the report names it, never shows it. */
|
|
51
|
+
function shown(value) {
|
|
52
|
+
return /^[a-z][\w+.-]*:\/\//i.test(value) || /^[^\s@/]+@[^\s:/]+:/.test(value) ? '(a URL)' : value;
|
|
49
53
|
}
|
|
50
54
|
function guardChange(before, after) {
|
|
51
55
|
if (before === after)
|
|
@@ -2,17 +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 {
|
|
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';
|
|
16
18
|
/**
|
|
17
19
|
* Candidate logins not already recorded, one entry each. The first spelling
|
|
18
20
|
* wins; every source joins it, in the order owner, gh, then Git Credential
|
|
@@ -83,9 +85,11 @@ export async function readContext(git, cwd, options = {}) {
|
|
|
83
85
|
const registry = await readRegistry();
|
|
84
86
|
if (!registry.ok)
|
|
85
87
|
return registry;
|
|
86
|
-
|
|
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);
|
|
87
91
|
const recorded = registry.value.accounts;
|
|
88
|
-
const facts = await readFacts(
|
|
92
|
+
const facts = await readFacts(view, repo, recorded, options);
|
|
89
93
|
return ok(assemble(cwd, recorded, repo, facts));
|
|
90
94
|
}
|
|
91
95
|
async function readFacts(git, repo, recorded, options) {
|
|
@@ -94,7 +98,7 @@ async function readFacts(git, repo, recorded, options) {
|
|
|
94
98
|
}
|
|
95
99
|
async function loadClone(git, repo, options) {
|
|
96
100
|
const authPromise = options.auth ? Promise.resolve(options.auth) : inspectAuth(git, repo.originUrl ?? undefined);
|
|
97
|
-
const [auth, pinned, allowed, planned, addresses, helpers, ownerIsUser, upstream, unpushed] = await Promise.all([
|
|
101
|
+
const [auth, pinned, allowed, planned, addresses, helpers, ownerIsUser, upstream, [unpushed, push]] = await Promise.all([
|
|
98
102
|
authPromise,
|
|
99
103
|
git.getConfig('repown.account', 'local'),
|
|
100
104
|
git.getAllConfig('repown.allowOwner', 'local'),
|
|
@@ -103,10 +107,16 @@ async function loadClone(git, repo, options) {
|
|
|
103
107
|
git.getAllConfigRaw('credential.helper'),
|
|
104
108
|
authPromise.then((auth) => askOwnerIsUser(repo, auth, options)),
|
|
105
109
|
readUpstream(git),
|
|
106
|
-
|
|
110
|
+
readUnpushedAndPush(git),
|
|
107
111
|
]);
|
|
108
112
|
const { machineName: name, machineEmail: email } = repo.identity;
|
|
109
|
-
return { auth, pinned, allowed, planned, addresses, unpushed, helpers, name, email, ownerIsUser, upstream };
|
|
113
|
+
return { auth, pinned, allowed, planned, addresses, unpushed, push, helpers, name, email, ownerIsUser, upstream };
|
|
114
|
+
}
|
|
115
|
+
/** The push facts reuse the unpushed read; `unpushed` stays its own field, as tests set it alone. */
|
|
116
|
+
async function readUnpushedAndPush(git) {
|
|
117
|
+
const unpushed = await readUnpushed(git);
|
|
118
|
+
const { unpushed: _, ...push } = await readPushFacts(git, unpushed);
|
|
119
|
+
return [unpushed, push];
|
|
110
120
|
}
|
|
111
121
|
/** Version, effective push.autoSetupRemote, the branch and its tracked ref. One read; nothing is written. */
|
|
112
122
|
async function readUpstream(git) {
|
|
@@ -127,7 +137,7 @@ function trackedOf(head, tracked) {
|
|
|
127
137
|
async function finishFacts(git, repo, recorded, loaded) {
|
|
128
138
|
const ghIsHelper = anyGhHelper(loaded.auth, loaded.planned, loaded.helpers);
|
|
129
139
|
return {
|
|
130
|
-
pinned: loaded.pinned, allowed: loaded.allowed, addresses: loaded.addresses, unpushed: loaded.unpushed,
|
|
140
|
+
pinned: loaded.pinned, allowed: loaded.allowed, addresses: loaded.addresses, unpushed: loaded.unpushed, push: loaded.push,
|
|
131
141
|
name: loaded.name, email: loaded.email, ownerIsUser: loaded.ownerIsUser, ghIsHelper, stored: loaded.auth.stored,
|
|
132
142
|
gh: loaded.auth.ghPresent ? loaded.auth.gh : null,
|
|
133
143
|
pinIntact: await pinIntact(git, loaded.pinned, recorded[loaded.pinned ?? ''], repo),
|
|
@@ -151,10 +161,11 @@ function assemble(cwd, recorded, repo, facts) {
|
|
|
151
161
|
guard: repo.guard,
|
|
152
162
|
redirected: repo.hook?.redirected ?? false, hookPath: repo.hook?.path ?? null,
|
|
153
163
|
fixLines: facts.fixLines,
|
|
154
|
-
addresses: facts.addresses, unpushed: facts.unpushed,
|
|
164
|
+
addresses: facts.addresses, unpushed: facts.unpushed, push: facts.push,
|
|
155
165
|
machineIdentity: { name: facts.name, email: facts.email },
|
|
156
166
|
upstream: facts.upstream, stored: facts.stored,
|
|
157
167
|
suggest: suggester(),
|
|
168
|
+
signedIn: async () => signedInLogins(facts.gh, facts.stored),
|
|
158
169
|
};
|
|
159
170
|
}
|
|
160
171
|
/** gh anywhere in the helper list may answer sign-ins: git asks the helpers in order. */
|
|
@@ -243,13 +254,13 @@ async function gitUses(git, values, repo) {
|
|
|
243
254
|
return name === values.name && email === values.email && user === values.account;
|
|
244
255
|
}
|
|
245
256
|
/** Profile lookups are network calls: one per account and host, however often a step is re-asked. */
|
|
246
|
-
function suggester() {
|
|
257
|
+
export function suggester() {
|
|
247
258
|
const cache = new Map();
|
|
248
259
|
return (account, host) => {
|
|
249
260
|
const key = host + '\n' + account;
|
|
250
261
|
if (!cache.has(key)) {
|
|
251
262
|
const provider = providers().find((candidate) => candidate.id === host);
|
|
252
|
-
cache.set(key, (provider
|
|
263
|
+
cache.set(key, lookUpProfile(provider, account).then((found) => ({ ...found.profile, problem: found.problem })));
|
|
253
264
|
}
|
|
254
265
|
return cache.get(key);
|
|
255
266
|
};
|