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
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
// "Could not be queried" is a THIRD STATE, distinct both from "gh is not
|
|
21
21
|
// installed" and from "gh is active as nobody". Collapsing it into either is the
|
|
22
22
|
// bug this shape exists to prevent.
|
|
23
|
-
import { run, inherit, succeeded, notInstalled, output } from
|
|
24
|
-
import { ok, err } from
|
|
25
|
-
import { versionAtLeast } from
|
|
23
|
+
import { run, inherit, succeeded, notInstalled, output } from '../exec.js';
|
|
24
|
+
import { ok, err } from '../result.js';
|
|
25
|
+
import { versionAtLeast } from '../version.js';
|
|
26
26
|
/**
|
|
27
27
|
* A credential-helper value that `gh auth setup-git` wrote -- `!gh auth
|
|
28
28
|
* git-credential`, or with gh's path, quoted on Windows -- and nothing more. A
|
|
@@ -104,9 +104,16 @@ export function ghProfileArgs(login, field) {
|
|
|
104
104
|
}
|
|
105
105
|
/** A profile field from github.com, or null. Absence here is unremarkable. */
|
|
106
106
|
export async function ghProfileField(login, field) {
|
|
107
|
-
|
|
107
|
+
return (await ghProfileLookup(login, field)).value;
|
|
108
|
+
}
|
|
109
|
+
export async function ghProfileLookup(login, field) {
|
|
110
|
+
return profileLookupFrom(await run('gh', ghProfileArgs(login, field)));
|
|
111
|
+
}
|
|
112
|
+
/** Only github.com's own 404 means missing: offline, refused or no gh is unknown. */
|
|
113
|
+
export function profileLookupFrom(result) {
|
|
108
114
|
const value = output(result);
|
|
109
|
-
|
|
115
|
+
const missing = !succeeded(result) && /\(HTTP 404\)/.test(result.stderr);
|
|
116
|
+
return { value: value && value !== 'null' ? value : null, missing };
|
|
110
117
|
}
|
|
111
118
|
export async function ghSwitch(login) {
|
|
112
119
|
const result = await run('gh', ['auth', 'switch', '-u', login]);
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
// vanished from the report and a partial repair read as a smaller successful one.
|
|
26
26
|
// The system scope is the realistic case: reading it needs nothing, editing it is
|
|
27
27
|
// machine-wide and needs an elevated shell.
|
|
28
|
-
import { isGh } from
|
|
28
|
+
import { isGh } from './gh.js';
|
|
29
29
|
const SCOPES = ['local', 'global', 'system'];
|
|
30
30
|
const HOSTS = ['https://github.com', 'https://gist.github.com'];
|
|
31
31
|
/**
|
package/dist/core/git.js
CHANGED
|
@@ -17,19 +17,24 @@ import { existsSync } from 'node:fs';
|
|
|
17
17
|
import { join, resolve } from 'node:path';
|
|
18
18
|
import { tmpdir } from 'node:os';
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
|
-
import { run, succeeded, output, lines } from
|
|
21
|
-
import { ok, err } from
|
|
20
|
+
import { run, succeeded, output, lines } from './exec.js';
|
|
21
|
+
import { ok, err } from './result.js';
|
|
22
22
|
export class Git {
|
|
23
23
|
cwd;
|
|
24
24
|
constructor(cwd = process.cwd()) {
|
|
25
25
|
this.cwd = cwd;
|
|
26
26
|
}
|
|
27
|
+
/** Every short git call. A ConfigSnapshot answers plain config reads here instead (ADR-029). */
|
|
28
|
+
exec(args, input) {
|
|
29
|
+
return this.spawnGit(args, input);
|
|
30
|
+
}
|
|
27
31
|
/**
|
|
32
|
+
* Starts the git child for exec() (execLong starts its own, for fetch and ls-remote).
|
|
28
33
|
* --no-replace-objects on every call: `git replace` changes what git SHOWS for
|
|
29
34
|
* an object, never what a push SENDS, so a replaced foreign commit read as the
|
|
30
35
|
* clean replacement while the original was published.
|
|
31
36
|
*/
|
|
32
|
-
|
|
37
|
+
spawnGit(args, input) {
|
|
33
38
|
const full = ['--no-replace-objects', ...args];
|
|
34
39
|
return input === undefined
|
|
35
40
|
? run('git', full, { cwd: this.cwd })
|
|
@@ -143,11 +148,11 @@ export class Git {
|
|
|
143
148
|
async setConfig(key, value, scope = 'local') {
|
|
144
149
|
return succeeded(await this.exec(this.scoped(scope, [key, value])));
|
|
145
150
|
}
|
|
146
|
-
/** True when the key is gone afterwards -- including when it was never set. */
|
|
147
151
|
/** Appends one more value to a multi-valued key. */
|
|
148
152
|
async addConfig(key, value, scope) {
|
|
149
153
|
return succeeded(await this.exec(this.scoped(scope, ['--add', key, value])));
|
|
150
154
|
}
|
|
155
|
+
/** True when the key is gone afterwards -- including when it was never set. */
|
|
151
156
|
async unsetConfig(key, scope = 'local') {
|
|
152
157
|
const result = await this.exec(this.scoped(scope, ['--unset-all', key]));
|
|
153
158
|
return succeeded(result) || result.code === 5; // 5 = the key did not exist
|
package/dist/core/guard/check.js
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
//
|
|
15
15
|
// which is exactly the set of commits about to be published. The previous design
|
|
16
16
|
// read that and threw it away.
|
|
17
|
-
import { parseGitUrl } from
|
|
18
|
-
import { providerFor } from
|
|
19
|
-
import { readIdentity, legacyAccountKey } from
|
|
17
|
+
import { parseGitUrl } from '../url.js';
|
|
18
|
+
import { providerFor } from '../hosts/index.js';
|
|
19
|
+
import { readIdentity, legacyAccountKey } from '../identity.js';
|
|
20
20
|
/** The null object id: 40 zeros, or 64 in a SHA-256 repository. */
|
|
21
21
|
const isZero = (sha) => /^0+$/.test(sha);
|
|
22
22
|
const MIRROR_KEY = 'repown.mirrorBranch';
|
|
@@ -108,7 +108,7 @@ function checkDestination({ url, owner, allowed }, onNote) {
|
|
|
108
108
|
'destination: ' + printable(redacted(url.raw)),
|
|
109
109
|
'allowed here: ' + allowed.join(', '),
|
|
110
110
|
'if that owner is legitimate -- an organisation you belong to, say:',
|
|
111
|
-
'
|
|
111
|
+
' ' + (allowOwnerCommand(owner) ?? ALLOW_OWNER_BY_HAND),
|
|
112
112
|
],
|
|
113
113
|
}];
|
|
114
114
|
}
|
|
@@ -232,9 +232,12 @@ function unreadableHint(error) {
|
|
|
232
232
|
function matches(actual, expected) {
|
|
233
233
|
return actual.toLowerCase() === expected.toLowerCase();
|
|
234
234
|
}
|
|
235
|
-
/**
|
|
235
|
+
/**
|
|
236
|
+
* Text a commit's author or a remote URL chose: control characters could rewrite the
|
|
237
|
+
* terminal around the refusal, and bidi or zero-width ones show one owner as another.
|
|
238
|
+
*/
|
|
236
239
|
function printable(text) {
|
|
237
|
-
return text.replace(/[\x00-\x1f\x7f-\x9f]/g, '?');
|
|
240
|
+
return text.replace(/[\x00-\x1f\x7f-\x9f\u200b-\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g, '?');
|
|
238
241
|
}
|
|
239
242
|
/**
|
|
240
243
|
* A URL as it may be shown: the WHOLE userinfo is replaced. A token is often the
|
|
@@ -243,7 +246,40 @@ function printable(text) {
|
|
|
243
246
|
function redacted(raw) {
|
|
244
247
|
return raw.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^/]*@/i, '$1***@');
|
|
245
248
|
}
|
|
246
|
-
/**
|
|
249
|
+
/**
|
|
250
|
+
* A word of a command printed to copy, as sh, bash, dash, zsh, fish, PowerShell and cmd all
|
|
251
|
+
* read it (test/paste.test.ts runs each). Bare when no shell treats any of it specially: a
|
|
252
|
+
* leading `@` is a PowerShell splat, and PowerShell splits a dashed word at `.` or `:`.
|
|
253
|
+
* `--` is quoted, since PowerShell drops a bare one from the `$args` of repown.ps1.
|
|
254
|
+
* Otherwise double quotes, unless they would expand or end early somewhere: `$` and a
|
|
255
|
+
* backtick (POSIX, PowerShell), `%` and `!` (cmd), a curly double quote (PowerShell), a
|
|
256
|
+
* backslash that escapes (`\\`, or one before the closing quote), a control character, or
|
|
257
|
+
* nothing at all (Windows PowerShell drops `""`). Then it is null and the caller prints no
|
|
258
|
+
* command: single quotes are no quotes in cmd, and PowerShell would run the rest of a
|
|
259
|
+
* POSIX `'\''` as code.
|
|
260
|
+
*/
|
|
247
261
|
export function shellWord(value) {
|
|
248
|
-
|
|
262
|
+
if (value === '--')
|
|
263
|
+
return '"--"';
|
|
264
|
+
if (/^(?:-[\w-]*|[\w./][\w.@+/:-]*)$/.test(value))
|
|
265
|
+
return value;
|
|
266
|
+
if (value === '' || /["$`%!“”„\x00-\x1f\x7f-\x9f]|\\\\|\\$/.test(value))
|
|
267
|
+
return null;
|
|
268
|
+
return '"' + value + '"';
|
|
269
|
+
}
|
|
270
|
+
/** A whole command to copy, or null when one of its words can't be printed safely (shellWord). */
|
|
271
|
+
export function copyableCommand(words) {
|
|
272
|
+
const quoted = words.map(shellWord);
|
|
273
|
+
return quoted.every((word) => word !== null) ? quoted.join(' ') : null;
|
|
274
|
+
}
|
|
275
|
+
/** Said instead of the allow-owner command when that command can't be printed safely. */
|
|
276
|
+
export const ALLOW_OWNER_BY_HAND = 'add that owner to ' + ALLOW_OWNER_KEY + ' with git config yourself (it can\'t be printed safely to paste)';
|
|
277
|
+
/**
|
|
278
|
+
* The command that lets this clone push to `owner`, or null: for an owner git would read
|
|
279
|
+
* as an option, or one that shows as something else (control or bidi characters).
|
|
280
|
+
*/
|
|
281
|
+
export function allowOwnerCommand(owner) {
|
|
282
|
+
if (owner.startsWith('-') || printable(owner) !== owner)
|
|
283
|
+
return null;
|
|
284
|
+
return copyableCommand(['git', 'config', '--local', '--add', ALLOW_OWNER_KEY, owner]);
|
|
249
285
|
}
|
package/dist/core/guard/hook.js
CHANGED
|
@@ -19,7 +19,7 @@ import { readFile, writeFile, mkdir, rm, chmod } from 'node:fs/promises';
|
|
|
19
19
|
import { existsSync, realpathSync } from 'node:fs';
|
|
20
20
|
import { join, dirname, resolve } from 'node:path';
|
|
21
21
|
import { fileURLToPath } from 'node:url';
|
|
22
|
-
import { ok, err } from
|
|
22
|
+
import { ok, err } from '../result.js';
|
|
23
23
|
export const MARKER = 'repown-identity-guard';
|
|
24
24
|
/**
|
|
25
25
|
* A marker counts only where this tool writes it: line 2 (right after the shebang)
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
//
|
|
9
9
|
// Over SSH there is no credential helper at all -- the SSH key decides -- so an
|
|
10
10
|
// SSH remote pins no credential key rather than one that selects nothing.
|
|
11
|
-
import { credentialPrefix } from
|
|
12
|
-
import { ghProfileField } from
|
|
11
|
+
import { credentialPrefix } from '../url.js';
|
|
12
|
+
import { ghProfileField, ghProfileLookup } from '../credential/gh.js';
|
|
13
13
|
const HOSTS = ['github.com', 'gist.github.com', 'www.github.com', 'ssh.github.com'];
|
|
14
14
|
export function githubProvider() {
|
|
15
15
|
return {
|
|
@@ -38,15 +38,21 @@ async function resolveProfile(account) {
|
|
|
38
38
|
return null;
|
|
39
39
|
return { ...(name ? { name } : {}), ...(email ? { email } : {}) };
|
|
40
40
|
}
|
|
41
|
+
/** The address GitHub gives an account to keep its own private (with or without the id in front). */
|
|
42
|
+
export function isNoreplyAddress(email) {
|
|
43
|
+
return /^(\d+\+)?[^@\s]+@users\.noreply\.github\.com$/i.test(email);
|
|
44
|
+
}
|
|
41
45
|
/**
|
|
42
46
|
* The users endpoint answers for an organisation too, with type Organization.
|
|
43
47
|
* Anything else, including a failed call, is unknown -- not a user.
|
|
44
48
|
*/
|
|
45
49
|
async function accountKind(login) {
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
50
|
+
const found = await ghProfileLookup(login, 'type');
|
|
51
|
+
if (found.missing)
|
|
52
|
+
return 'missing';
|
|
53
|
+
if (found.value === 'User')
|
|
48
54
|
return 'user';
|
|
49
|
-
if (
|
|
55
|
+
if (found.value === 'Organization')
|
|
50
56
|
return 'organization';
|
|
51
57
|
return null;
|
|
52
58
|
}
|
package/dist/core/hosts/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Provider resolution. Ordered, with `generic` always last so every URL resolves
|
|
2
2
|
// to something and no caller has to handle "no provider".
|
|
3
|
-
import { githubProvider } from
|
|
4
|
-
import { azureDevOpsProvider } from
|
|
5
|
-
import { genericProvider } from
|
|
3
|
+
import { githubProvider } from './github.js';
|
|
4
|
+
import { azureDevOpsProvider } from './azdo.js';
|
|
5
|
+
import { genericProvider } from './generic.js';
|
|
6
6
|
export function providers() {
|
|
7
7
|
return [githubProvider(), azureDevOpsProvider(), genericProvider()];
|
|
8
8
|
}
|
|
@@ -12,3 +12,21 @@ export function providerFor(url) {
|
|
|
12
12
|
return all[all.length - 1];
|
|
13
13
|
return all.find((provider) => provider.matches(url)) ?? all[all.length - 1];
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* What to tell someone about a login the host looked up, or null for a user or an
|
|
17
|
+
* unknown. Only GitHub answers accountKind, so the words name github.com.
|
|
18
|
+
*/
|
|
19
|
+
export function loginKindProblem(kind, login) {
|
|
20
|
+
if (kind === 'missing')
|
|
21
|
+
return 'github.com has no account named ' + login + ': check the spelling';
|
|
22
|
+
if (kind === 'organization')
|
|
23
|
+
return login + ' is an organisation on github.com, not an account you sign in as';
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
/** The host's profile for a login, and a sentence when the host says it is no account or an organisation. */
|
|
27
|
+
export async function lookUpProfile(provider, account) {
|
|
28
|
+
if (!provider?.resolveProfile)
|
|
29
|
+
return { profile: {}, problem: null };
|
|
30
|
+
const [profile, kind] = await Promise.all([provider.resolveProfile(account), provider.accountKind?.(account)]);
|
|
31
|
+
return { profile: profile ?? {}, problem: loginKindProblem(kind, account) };
|
|
32
|
+
}
|
package/dist/core/identity.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// for a public repository to leak.
|
|
13
13
|
//
|
|
14
14
|
// NO NAMES OR ADDRESSES APPEAR IN THIS FILE.
|
|
15
|
-
import { credentialPrefix } from
|
|
15
|
+
import { credentialPrefix } from './url.js';
|
|
16
16
|
export const NAME_KEY = 'user.name';
|
|
17
17
|
export const EMAIL_KEY = 'user.email';
|
|
18
18
|
export const USE_CONFIG_ONLY_KEY = 'user.useConfigOnly';
|
package/dist/core/inspect.js
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
// (`git --exec-path`, GCM, gh) and is identical for every clone on the machine,
|
|
7
7
|
// so the commands that need it ask for it separately -- and `repown scan`, which
|
|
8
8
|
// walks many repositories, never asks for it at all.
|
|
9
|
-
import { parseGitUrl } from
|
|
10
|
-
import { providerFor } from
|
|
11
|
-
import { readIdentity } from
|
|
12
|
-
import { guardState, hookLocation } from
|
|
13
|
-
import { findGcm, listAccounts, isGcm } from
|
|
14
|
-
import { ghState, ghInstalled, isGh } from
|
|
9
|
+
import { parseGitUrl } from './url.js';
|
|
10
|
+
import { providerFor } from './hosts/index.js';
|
|
11
|
+
import { readIdentity } from './identity.js';
|
|
12
|
+
import { guardState, hookLocation } from './guard/hook.js';
|
|
13
|
+
import { findGcm, listAccounts, isGcm } from './credential/gcm.js';
|
|
14
|
+
import { ghState, ghInstalled, isGh } from './credential/gh.js';
|
|
15
15
|
const DEFAULT_PROBE_URL = 'https://github.com/';
|
|
16
16
|
export async function inspectRepo(git) {
|
|
17
17
|
const isRepo = await git.isRepo();
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// belongs to whichever remote was fetched last. So the destination is only ever
|
|
10
10
|
// "known" (it has tracking refs, and pushes where it fetches from) or "unknown",
|
|
11
11
|
// and a read that fails is unknown.
|
|
12
|
-
import { parseGitUrl } from
|
|
12
|
+
import { parseGitUrl } from './url.js';
|
|
13
13
|
/** Null when the branch pushes nowhere, to `.` (this repository), or where tracking refs reach. */
|
|
14
14
|
export async function unknownDestination(git, branch) {
|
|
15
15
|
const listed = await git.readRemotes();
|
package/dist/core/push-state.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
// a clone that could not be read is never reported ready. The push target is resolved
|
|
6
6
|
// the way a plain `git push` resolves it (push-destination.ts), and a secret in a URL is
|
|
7
7
|
// only ever reported by the config key that holds it.
|
|
8
|
-
import { ok } from
|
|
9
|
-
import { pushTarget, unknownDestination } from
|
|
10
|
-
import { parseGitUrl } from
|
|
11
|
-
import { providerFor } from
|
|
12
|
-
import { hostileSet } from
|
|
8
|
+
import { ok } from './result.js';
|
|
9
|
+
import { pushTarget, unknownDestination } from './push-destination.js';
|
|
10
|
+
import { parseGitUrl } from './url.js';
|
|
11
|
+
import { providerFor } from './hosts/index.js';
|
|
12
|
+
import { hostileSet } from './guard/check.js';
|
|
13
13
|
const OVERRIDES = ['author.email', 'committer.email'];
|
|
14
14
|
export async function readPushFacts(git, unpushed, env = process.env) {
|
|
15
15
|
const head = await git.currentBranch();
|
package/dist/core/reauthor.js
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
// rebase runs with no hook at all, without autosquash and without moving other branches,
|
|
8
8
|
// behind a backup ref that is never overwritten, and is checked afterwards: every commit
|
|
9
9
|
// still there, each by the pin. Nothing here pushes.
|
|
10
|
-
import { ok, err } from
|
|
11
|
-
import { pushTarget, unknownDestination } from
|
|
12
|
-
import { AMEND_COMMAND, isOwn, otherAddresses } from
|
|
10
|
+
import { ok, err } from './result.js';
|
|
11
|
+
import { pushTarget, unknownDestination } from './push-destination.js';
|
|
12
|
+
import { AMEND_COMMAND, isOwn, otherAddresses } from './unpushed.js';
|
|
13
13
|
const IDENTITY_ENV = ['GIT_AUTHOR_NAME', 'GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_NAME', 'GIT_COMMITTER_EMAIL'];
|
|
14
14
|
const IDENTITY_CONFIG = ['author.email', 'committer.email', 'author.name', 'committer.name'];
|
|
15
15
|
/** Null: nothing by another address. An error is a refusal, and nothing was changed. */
|
package/dist/core/registry.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { mkdir, readFile, writeFile, rename, rm } from 'node:fs/promises';
|
|
16
16
|
import { homedir } from 'node:os';
|
|
17
17
|
import { join, dirname } from 'node:path';
|
|
18
|
-
import { ok, err } from
|
|
18
|
+
import { ok, err } from './result.js';
|
|
19
19
|
const EMPTY = { accounts: {}, unreadable: [] };
|
|
20
20
|
export function configDirectory() {
|
|
21
21
|
const explicit = process.env['REPOWN_CONFIG_DIR'];
|
package/dist/core/unpushed.js
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
// them (push-destination.ts, ADR-025).
|
|
12
12
|
// scan's address totals are a different question: every ref, counts only, and
|
|
13
13
|
// setup loads them only for the guard question.
|
|
14
|
-
import { ok } from
|
|
15
|
-
import { unknownDestination } from
|
|
16
|
-
import { shellWord } from
|
|
14
|
+
import { ok } from './result.js';
|
|
15
|
+
import { unknownDestination } from './push-destination.js';
|
|
16
|
+
import { copyableCommand, shellWord } from './guard/check.js';
|
|
17
17
|
const ADDRESS_CAP = 3;
|
|
18
18
|
/** The one re-author command: the advice prints it, and `repown reauthor` runs it. */
|
|
19
19
|
export const AMEND_COMMAND = 'git commit --amend --no-edit --reset-author --allow-empty';
|
|
@@ -93,19 +93,20 @@ function unknownLine(unknown, account) {
|
|
|
93
93
|
}
|
|
94
94
|
function trackingLine(name, account) {
|
|
95
95
|
const lead = show(name) + ' has no remote-tracking refs, so some of these may already be on it' + GUARD;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return lead + ': git fetch ' + shellWord(show(name)) + ', ' + recount(account);
|
|
96
|
+
const fetch = copyable(name) ? copyableCommand(['git', 'fetch', show(name)]) : null;
|
|
97
|
+
return fetch ? lead + ': ' + fetch + ', ' + recount(account) : lead;
|
|
99
98
|
}
|
|
100
99
|
function urlLine(key, remote, account) {
|
|
101
100
|
const lead = 'this branch pushes to a URL, not a remote' + THERE;
|
|
102
101
|
if (!remote || !copyable(remote))
|
|
103
102
|
return lead;
|
|
104
|
-
const
|
|
105
|
-
|
|
103
|
+
const repoint = copyableCommand(['git', 'config', '--local', show(key), show(remote)]);
|
|
104
|
+
const fetch = copyableCommand(['git', 'fetch', show(remote)]);
|
|
105
|
+
return repoint && fetch ? lead + ': ' + repoint + ', ' + fetch + ', ' + recount(account) : lead;
|
|
106
106
|
}
|
|
107
107
|
function recount(account) {
|
|
108
|
-
|
|
108
|
+
const word = shellWord(show(account));
|
|
109
|
+
return word ? 'then repown use ' + word + ' to count again' : 'then run repown use again to count again';
|
|
109
110
|
}
|
|
110
111
|
/** Quoting keeps a shell from splitting a word, not git from reading `-x` as an option. */
|
|
111
112
|
function copyable(word) {
|
package/dist/program.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// The command table. cli.ts starts the program; the start screen's Show help
|
|
2
2
|
// loads this same table. Importing this file does not run repown.
|
|
3
3
|
export const COMMANDS = {
|
|
4
|
-
status: async () => (await import(
|
|
5
|
-
use: async () => (await import(
|
|
6
|
-
off: async () => (await import(
|
|
7
|
-
doctor: async () => (await import(
|
|
8
|
-
fix: async () => (await import(
|
|
9
|
-
reauthor: async () => (await import(
|
|
10
|
-
guard: async () => (await import(
|
|
11
|
-
accounts: async () => (await import(
|
|
12
|
-
scan: async () => (await import(
|
|
13
|
-
setup: async () => (await import(
|
|
4
|
+
status: async () => (await import('./commands/status.js')).default,
|
|
5
|
+
use: async () => (await import('./commands/use.js')).default,
|
|
6
|
+
off: async () => (await import('./commands/off.js')).default,
|
|
7
|
+
doctor: async () => (await import('./commands/doctor.js')).default,
|
|
8
|
+
fix: async () => (await import('./commands/fix.js')).default,
|
|
9
|
+
reauthor: async () => (await import('./commands/reauthor.js')).default,
|
|
10
|
+
guard: async () => (await import('./commands/guard.js')).default,
|
|
11
|
+
accounts: async () => (await import('./commands/accounts.js')).default,
|
|
12
|
+
scan: async () => (await import('./commands/scan.js')).default,
|
|
13
|
+
setup: async () => (await import('./commands/setup.js')).default,
|
|
14
14
|
};
|
package/dist/ui/args.js
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
// earlier bug: `repown use --gh octocat` read "octocat" as --gh's value and left
|
|
10
10
|
// no account), an unknown option is refused rather than silently dropped, and
|
|
11
11
|
// so is an extra positional.
|
|
12
|
-
import { Git } from
|
|
13
|
-
import { ok, err } from
|
|
14
|
-
import { suggest } from
|
|
12
|
+
import { Git } from '../core/git.js';
|
|
13
|
+
import { ok, err } from '../core/result.js';
|
|
14
|
+
import { suggest } from './suggest.js';
|
|
15
15
|
export const NO_POSITIONALS = { min: 0, max: 0 };
|
|
16
16
|
/** For commands whose payload a script may read. Only `json` is a stable contract (ADR-014). */
|
|
17
17
|
export const FORMAT_OPTION = {
|
package/dist/ui/command.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// the same way, and one renderer (ui/help.ts) generate help for all of them
|
|
6
6
|
// from the same declarations, so help can never drift from what the parser
|
|
7
7
|
// actually accepts.
|
|
8
|
-
import { NO_POSITIONALS } from
|
|
8
|
+
import { NO_POSITIONALS } from './args.js';
|
|
9
9
|
export function isGroup(entry) {
|
|
10
10
|
return 'actions' in entry;
|
|
11
11
|
}
|
package/dist/ui/dispatch.js
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
//
|
|
6
6
|
// Kept apart from src/cli.ts so a second program (the release tool in scripts/)
|
|
7
7
|
// gets the same grammar without importing cli.ts, which runs repown.
|
|
8
|
-
import { parseArgs, hasHelpFlag } from
|
|
9
|
-
import { isGroup, resolveAlias, specFor } from
|
|
10
|
-
import { renderHelpFor } from
|
|
11
|
-
import { suggest } from
|
|
12
|
-
import { ok, err } from
|
|
13
|
-
import * as out from
|
|
8
|
+
import { parseArgs, hasHelpFlag } from './args.js';
|
|
9
|
+
import { isGroup, resolveAlias, specFor } from './command.js';
|
|
10
|
+
import { renderHelpFor } from './help.js';
|
|
11
|
+
import { suggest } from './suggest.js';
|
|
12
|
+
import { ok, err } from '../core/result.js';
|
|
13
|
+
import * as out from './format.js';
|
|
14
14
|
/** Every command the program declares, in declaration order. Help uses this, and so can a runner. */
|
|
15
15
|
export async function loadEntries(commands) {
|
|
16
16
|
const names = Object.keys(commands);
|
package/dist/ui/format.js
CHANGED
|
@@ -8,6 +8,7 @@ const COLOURS = {
|
|
|
8
8
|
green: '\x1b[32m',
|
|
9
9
|
yellow: '\x1b[33m',
|
|
10
10
|
red: '\x1b[31m',
|
|
11
|
+
cyan: '\x1b[36m',
|
|
11
12
|
dim: '\x1b[2m',
|
|
12
13
|
reset: '\x1b[0m',
|
|
13
14
|
};
|
|
@@ -33,6 +34,36 @@ export function useColour(stream) {
|
|
|
33
34
|
function paint(stream, colour, text) {
|
|
34
35
|
return useColour(stream) ? COLOURS[colour] + text + COLOURS.reset : text;
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Whether the terminal draws symbols beyond ASCII: the signals @clack/prompts draws its own
|
|
39
|
+
* frame by, so a mark and the frame around it never disagree. Windows' legacy console does
|
|
40
|
+
* not; Windows Terminal, VS Code and mintty (TERM=xterm-256color) do (ADR-027).
|
|
41
|
+
*/
|
|
42
|
+
export function unicodeTerminal(env = process.env, platform = process.platform) {
|
|
43
|
+
if (platform !== 'win32')
|
|
44
|
+
return env['TERM'] !== 'linux';
|
|
45
|
+
return Boolean(env['CI'] || env['WT_SESSION'] || env['TERMINUS_SUBLIME'])
|
|
46
|
+
|| env['ConEmuTask'] === '{cmd::Cmder}'
|
|
47
|
+
|| ['Terminus-Sublime', 'vscode'].includes(env['TERM_PROGRAM'] ?? '')
|
|
48
|
+
|| ['xterm-256color', 'alacritty'].includes(env['TERM'] ?? '')
|
|
49
|
+
|| env['TERMINAL_EMULATOR'] === 'JetBrains-JediTerm';
|
|
50
|
+
}
|
|
51
|
+
/** Each mark's colour, its symbol, and the ASCII stand-in where Unicode can't be drawn. */
|
|
52
|
+
const MARKS = {
|
|
53
|
+
ok: { colour: 'green', unicode: '✔', ascii: '+' },
|
|
54
|
+
warn: { colour: 'yellow', unicode: '▲', ascii: '!' },
|
|
55
|
+
};
|
|
56
|
+
/** `text` led by a coloured mark where `stream` has colour; exactly `text` where it has none. */
|
|
57
|
+
export function marked(kind, stream, text) {
|
|
58
|
+
if (!useColour(stream))
|
|
59
|
+
return text;
|
|
60
|
+
const mark = MARKS[kind];
|
|
61
|
+
return paint(stream, mark.colour, unicodeTerminal() ? mark.unicode : mark.ascii) + ' ' + text;
|
|
62
|
+
}
|
|
63
|
+
/** A command, cyan where `stream` has colour. */
|
|
64
|
+
export function accent(stream, text) {
|
|
65
|
+
return paint(stream, 'cyan', text);
|
|
66
|
+
}
|
|
36
67
|
function status(level, tag, message) {
|
|
37
68
|
const word = paint(level.stream, level.colour, level.word.padEnd(5));
|
|
38
69
|
level.stream.write(word + ' ' + tag.padEnd(10) + ' ' + message + '\n');
|
package/dist/ui/help.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// `out.line` calls, and nothing here is reachable except by an explicit
|
|
6
6
|
// `--help`/`-h`/`help` request. A command's `run()` never sees a help request --
|
|
7
7
|
// cli.ts intercepts it before parsing the command's own arguments.
|
|
8
|
-
import { GLOBAL_OPTIONS } from
|
|
9
|
-
import { isGroup, optionsOf } from
|
|
8
|
+
import { GLOBAL_OPTIONS } from './args.js';
|
|
9
|
+
import { isGroup, optionsOf } from './command.js';
|
|
10
10
|
export function renderTopHelp(entries) {
|
|
11
11
|
return [
|
|
12
12
|
...topHeader(entries),
|
package/dist/ui/prompt.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// whatever a command actually produces, so `repown accounts add x | tee log` does
|
|
11
11
|
// not interleave a prompt into the log.
|
|
12
12
|
import { createInterface } from 'node:readline/promises';
|
|
13
|
-
import { ok, err } from
|
|
13
|
+
import { ok, err } from '../core/result.js';
|
|
14
14
|
export function interactive() {
|
|
15
15
|
return process.stdin.isTTY === true && process.stderr.isTTY === true;
|
|
16
16
|
}
|