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
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,76 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-10-03
|
|
11
|
+
|
|
12
|
+
The start screen (bare `repown` outside a clone) now records and removes accounts without
|
|
13
|
+
leaving its frame, and warns before you pin a clone to someone else's GitHub account. Every
|
|
14
|
+
command repown prints for you to copy now pastes correctly in sh, bash, zsh, fish, PowerShell
|
|
15
|
+
and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- **Remove an account** on the start screen: pick a recorded account, read what stays (clones
|
|
19
|
+
pinned to it keep their settings and the push guard), and confirm. It runs
|
|
20
|
+
`repown accounts remove`, and the start screen comes back without it (ADR-028).
|
|
21
|
+
- **A warning before you record someone else's GitHub account.** When gh or Git Credential
|
|
22
|
+
Manager is signed in to github.com as other accounts only, the name question in setup and on
|
|
23
|
+
the start screen says so: `signed in as octo-work, not octocat: if octocat isn't your
|
|
24
|
+
account, go back; otherwise the first push asks you to sign in as it`. A login that exists
|
|
25
|
+
can still be a stranger's, and its noreply address would link your commits to them. Nothing
|
|
26
|
+
is refused (ADR-028).
|
|
27
|
+
- `repown accounts add <login>`, when it asks, warns when github.com has no account by that
|
|
28
|
+
name (a typo) or the name is an organisation. It still records the account, and says nothing
|
|
29
|
+
when GitHub can't be asked.
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- **Record an account on the start screen asks everything in its frame**: the login, where it
|
|
33
|
+
is hosted, and the commit name and email, prefilled from GitHub (name, noreply address), with
|
|
34
|
+
Back on each. It then runs `repown accounts add` with every answer as a flag, so the bare
|
|
35
|
+
`Commit name` / `Commit email` prompts are gone. A login already recorded is refused, and in
|
|
36
|
+
setup and on the start screen a login github.com doesn't know, or an organisation, is named
|
|
37
|
+
on the name question, so a typo can be fixed before anything is recorded.
|
|
38
|
+
- **The start screen comes back** with a fresh summary after Record an account, Remove an
|
|
39
|
+
account, Check this machine or Stop gh serving credentials. Quit, Esc or Ctrl-C leave it
|
|
40
|
+
(ADR-028).
|
|
41
|
+
- **Prefilled answers say where they came from**: `GitHub shows no name for octocat, so this
|
|
42
|
+
is the login`, and `prefilled with the private address GitHub gives octocat` instead of a
|
|
43
|
+
`1234+` example beside the real address. This machine's own identity reads `your default git
|
|
44
|
+
name here is …: use it only if this account does too`.
|
|
45
|
+
- **The wizard is easier to read in colour**, with nothing to set: the title is a cyan badge,
|
|
46
|
+
summary values are bold cyan, commands are cyan, and setup's closing line leads with a green
|
|
47
|
+
✔ (done) or a yellow ▲ (the next push will fail). On a terminal that can't draw Unicode
|
|
48
|
+
(Windows' classic console, the Linux console) the marks are `+` and `!`. Without colour (a
|
|
49
|
+
pipe, a log, `NO_COLOR`) the output is exactly as before. `repown accounts add` prints its
|
|
50
|
+
next command, `repown use <account>`, in cyan the same way (ADR-027).
|
|
51
|
+
- A question's note (this clone's current account, what the history holds, what GitHub said
|
|
52
|
+
about a login) is drawn inside that question, under its hint, instead of as a line above it
|
|
53
|
+
that read as part of the previous answer. Plain prompts already did this.
|
|
54
|
+
- Commands setup and the start screen show for you to copy start with `$ ` instead of `> `:
|
|
55
|
+
pasted whole, `>` was a redirect in every shell and left an empty file named `repown`
|
|
56
|
+
(ADR-027).
|
|
57
|
+
- **Faster on Windows:** `repown status`, `doctor`, `scan`, the pre-push guard, the start
|
|
58
|
+
screen's read of each clone and setup's first read take each git config scope in one read
|
|
59
|
+
instead of one process per key. One `repown status` in a clone went from 68 processes to 38,
|
|
60
|
+
about a third faster (ADR-029).
|
|
61
|
+
|
|
62
|
+
### Fixed
|
|
63
|
+
- **Security: pasting a command repown printed can no longer run part of it as code.** A value
|
|
64
|
+
no quoting keeps literal in every shell (`$`, a backtick, `"`, `%`, `!`, a curly double quote,
|
|
65
|
+
a control character, an escaping backslash) used to get a single-quoted command, and pasted
|
|
66
|
+
into PowerShell or cmd part of it ran. A remote's owner made of such text could do that
|
|
67
|
+
through the allow-owner advice of the guard, `status` or `use`. repown now says to add it by
|
|
68
|
+
hand, shows `[value not safe to paste]` in a command it runs itself, and prints the owner
|
|
69
|
+
with control and bidi characters escaped.
|
|
70
|
+
- **Copyable commands paste correctly in cmd and PowerShell as well as POSIX shells**: a value
|
|
71
|
+
with a space or an apostrophe is in double quotes (`--name "Octo Cat"`, on every OS), a
|
|
72
|
+
GitHub noreply address and a URL are no longer quoted, a leading `@` and a dashed word with
|
|
73
|
+
`.` or `:` are quoted (PowerShell read them as a splat, or split them), and the `--` before a
|
|
74
|
+
dashed login is `"--"` (PowerShell dropped a bare one).
|
|
75
|
+
- On a terminal that can't draw Unicode (classic Windows cmd), a text question's hint lines
|
|
76
|
+
drew a `│` beside a gutter of `|`. They now use the same bar as the rest of the frame.
|
|
77
|
+
- `type < to go back` no longer breaks across two lines; when it doesn't fit after the hint,
|
|
78
|
+
it takes a line of its own.
|
|
79
|
+
|
|
10
80
|
## [0.4.0] - 2026-09-30
|
|
11
81
|
|
|
12
82
|
### Added
|
|
@@ -141,7 +211,8 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
|
|
|
141
211
|
contract for scripts.
|
|
142
212
|
- Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
|
|
143
213
|
|
|
144
|
-
[Unreleased]: https://github.com/makubexD/repown/compare/v0.
|
|
214
|
+
[Unreleased]: https://github.com/makubexD/repown/compare/v0.5.0...HEAD
|
|
215
|
+
[0.5.0]: https://github.com/makubexD/repown/compare/v0.4.0...v0.5.0
|
|
145
216
|
[0.4.0]: https://github.com/makubexD/repown/compare/v0.3.0...v0.4.0
|
|
146
217
|
[0.3.0]: https://github.com/makubexD/repown/compare/v0.2.0...v0.3.0
|
|
147
218
|
[0.2.0]: https://github.com/makubexD/repown/compare/v0.1.1...v0.2.0
|
package/README.md
CHANGED
|
@@ -235,7 +235,10 @@ then commit and push.
|
|
|
235
235
|
|
|
236
236
|
The start screen lists the accounts on this machine and the clones it found, then offers
|
|
237
237
|
the next command. The summary is in the frame. Picking a command closes the frame with
|
|
238
|
-
that command
|
|
238
|
+
that command (Record an account first asks the login, host, name and email in it; Remove
|
|
239
|
+
an account asks which, then to confirm). Nothing changes until you pick one. After
|
|
240
|
+
recording or removing an account, checking the machine or stopping gh, it comes back with
|
|
241
|
+
a fresh summary.
|
|
239
242
|
|
|
240
243
|
**Who is this clone?** `repown status` prints:
|
|
241
244
|
|
package/dist/cli.js
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
// can import without pulling in this file.
|
|
18
18
|
import { readFileSync } from 'node:fs';
|
|
19
19
|
import { fileURLToPath } from 'node:url';
|
|
20
|
-
import { COMMANDS } from
|
|
21
|
-
import { renderTopHelp } from
|
|
22
|
-
import { start } from
|
|
20
|
+
import { COMMANDS } from './program.js';
|
|
21
|
+
import { renderTopHelp } from './ui/help.js';
|
|
22
|
+
import { start } from './ui/dispatch.js';
|
|
23
23
|
function version() {
|
|
24
24
|
const path = fileURLToPath(new URL('../package.json', import.meta.url));
|
|
25
25
|
return JSON.parse(readFileSync(path, 'utf8')).version;
|
|
@@ -28,7 +28,7 @@ start({
|
|
|
28
28
|
name: 'repown',
|
|
29
29
|
commands: COMMANDS,
|
|
30
30
|
defaultCommand: 'status',
|
|
31
|
-
chooseDefault: () => import(
|
|
31
|
+
chooseDefault: () => import('./commands/start.js').then((mod) => mod.startDefault()),
|
|
32
32
|
topHelp: renderTopHelp,
|
|
33
33
|
version,
|
|
34
34
|
});
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Recording an account once is what makes `repown use <account>` a one-word command
|
|
4
4
|
// afterwards, in every repository on the machine.
|
|
5
|
-
import { loadRegistry, saveAccount, removeAccount, registryPath } from
|
|
6
|
-
import { providers } from
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
5
|
+
import { loadRegistry, saveAccount, removeAccount, registryPath } from '../core/registry.js';
|
|
6
|
+
import { lookUpProfile, providers } from '../core/hosts/index.js';
|
|
7
|
+
import { copyableCommand } from '../core/guard/check.js';
|
|
8
|
+
import { ask, interactive } from '../ui/prompt.js';
|
|
9
|
+
import { flagString, wantsJson, FORMAT_OPTION } from '../ui/args.js';
|
|
10
|
+
import * as out from '../ui/format.js';
|
|
10
11
|
async function list(args) {
|
|
11
12
|
const loaded = await loadRegistry();
|
|
12
13
|
if (!loaded.ok) {
|
|
@@ -71,18 +72,23 @@ async function add(args) {
|
|
|
71
72
|
out.fail('accounts', written.error);
|
|
72
73
|
return 1;
|
|
73
74
|
}
|
|
74
|
-
out.pass('accounts', account + ' ' + name + ' <' + email + '>');
|
|
75
|
+
out.pass('accounts', out.printable(account) + ' ' + out.printable(name) + ' <' + out.printable(email) + '>');
|
|
75
76
|
out.line();
|
|
76
|
-
out.line(' Use it in any clone:
|
|
77
|
+
out.line(' Use it in any clone: ' + out.accent(process.stdout, useCommand(account)));
|
|
77
78
|
out.line();
|
|
78
79
|
return 0;
|
|
79
80
|
}
|
|
81
|
+
/** `repown use <account>` to paste, `--` first for a dashed login; described when it can't be printed safely. */
|
|
82
|
+
function useCommand(account) {
|
|
83
|
+
const words = account.startsWith('-') ? ['repown', 'use', '--', account] : ['repown', 'use', account];
|
|
84
|
+
return copyableCommand(words) ?? 'repown use, with this account\'s name';
|
|
85
|
+
}
|
|
80
86
|
/** Best effort. A host that cannot be asked simply contributes no suggestion. */
|
|
81
87
|
async function suggestProfile(hostId, account) {
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
return
|
|
88
|
+
const found = await lookUpProfile(providers().find((candidate) => candidate.id === hostId), account);
|
|
89
|
+
if (found.problem)
|
|
90
|
+
out.warn('accounts', found.problem + ' (recording it anyway)');
|
|
91
|
+
return found.profile;
|
|
86
92
|
}
|
|
87
93
|
async function askFor(label, suggestion) {
|
|
88
94
|
const answer = await ask(label, suggestion);
|
|
@@ -100,10 +106,10 @@ async function remove(args) {
|
|
|
100
106
|
return 1;
|
|
101
107
|
}
|
|
102
108
|
if (!removed.value) {
|
|
103
|
-
out.warn('accounts', account + ' was not recorded.');
|
|
109
|
+
out.warn('accounts', out.printable(account) + ' was not recorded.');
|
|
104
110
|
return 0;
|
|
105
111
|
}
|
|
106
|
-
out.pass('accounts', 'removed ' + account);
|
|
112
|
+
out.pass('accounts', 'removed ' + out.printable(account));
|
|
107
113
|
out.line();
|
|
108
114
|
out.line(' Clones already pinned to it are unchanged -- their identity is in');
|
|
109
115
|
out.line(' their own .git/config. Unpin one with: repown off');
|
package/dist/commands/doctor.js
CHANGED
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
//
|
|
14
14
|
// Under that diagnosis, one row per account the registry, GCM or gh knows.
|
|
15
15
|
// accountRows decides the cells. A failed lookup stays `unknown`.
|
|
16
|
-
import { inspectRepo, inspectAuth, activeAccountLabel } from
|
|
17
|
-
import { loadRegistry } from
|
|
18
|
-
import { gitFor } from
|
|
19
|
-
import
|
|
16
|
+
import { inspectRepo, inspectAuth, activeAccountLabel } from '../core/inspect.js';
|
|
17
|
+
import { loadRegistry } from '../core/registry.js';
|
|
18
|
+
import { gitFor } from '../ui/args.js';
|
|
19
|
+
import { snapshotOf } from '../core/config-snapshot.js';
|
|
20
|
+
import * as out from '../ui/format.js';
|
|
20
21
|
const DOCTOR_TITLE = 'repown doctor · how this machine signs in to git hosts';
|
|
21
22
|
const NAME_WIDTH = 14;
|
|
22
23
|
const NOT_YET = 'not signed in yet (the first push signs in)';
|
|
@@ -29,7 +30,8 @@ export default {
|
|
|
29
30
|
summary: 'what serves credentials on this machine, and to whom',
|
|
30
31
|
examples: ['repown doctor'],
|
|
31
32
|
async run(args) {
|
|
32
|
-
|
|
33
|
+
// Read-only: config reads come from one list per scope (ADR-029).
|
|
34
|
+
const git = snapshotOf(gitFor(args));
|
|
33
35
|
const repo = await inspectRepo(git);
|
|
34
36
|
const auth = await inspectAuth(git, repo.originUrl ?? undefined);
|
|
35
37
|
const warned = printReport(repo, auth, await loadRegistry());
|
package/dist/commands/fix.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
// values and the reset gh wrote with them -- so it shows exactly what it will
|
|
6
6
|
// remove, and the undo, BEFORE asking. A change to machine-wide config should be
|
|
7
7
|
// reviewable rather than magic.
|
|
8
|
-
import { inspectAuth, storedAccountsLabel } from
|
|
9
|
-
import { planRepair, repair, describeValue } from
|
|
10
|
-
import { confirm, interactive } from
|
|
11
|
-
import { flagBool, gitFor } from
|
|
12
|
-
import * as out from
|
|
8
|
+
import { inspectAuth, storedAccountsLabel } from '../core/inspect.js';
|
|
9
|
+
import { planRepair, repair, describeValue } from '../core/credential/repair.js';
|
|
10
|
+
import { confirm, interactive } from '../ui/prompt.js';
|
|
11
|
+
import { flagBool, gitFor } from '../ui/args.js';
|
|
12
|
+
import * as out from '../ui/format.js';
|
|
13
13
|
export default {
|
|
14
14
|
summary: 'undo `gh auth setup-git` so per-repo account pins work again',
|
|
15
15
|
options: [
|
package/dist/commands/guard.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
// `guard check` is what the installed hook invokes, with the exact syntax baked
|
|
4
4
|
// into every hook already on disk (src/core/guard/hook.ts) -- `--remote` and
|
|
5
5
|
// `--url` on this action are a frozen contract, not just today's flags.
|
|
6
|
-
import { installGuard, uninstallGuard, guardState, fromNpxCache } from
|
|
7
|
-
import { check } from
|
|
8
|
-
import { flagString, gitFor } from
|
|
9
|
-
import
|
|
6
|
+
import { installGuard, uninstallGuard, guardState, fromNpxCache } from '../core/guard/hook.js';
|
|
7
|
+
import { check } from '../core/guard/check.js';
|
|
8
|
+
import { flagString, gitFor } from '../ui/args.js';
|
|
9
|
+
import { snapshotOf } from '../core/config-snapshot.js';
|
|
10
|
+
import * as out from '../ui/format.js';
|
|
10
11
|
/** "off" is an answer about a repository; outside one, it would be a guess. */
|
|
11
12
|
async function status(args) {
|
|
12
13
|
const git = gitFor(args);
|
|
@@ -50,7 +51,8 @@ async function disable(args) {
|
|
|
50
51
|
}
|
|
51
52
|
async function runCheck(args) {
|
|
52
53
|
const refusals = await check({
|
|
53
|
-
|
|
54
|
+
// Read-only, and on every push: config reads come from one list per scope (ADR-029).
|
|
55
|
+
git: snapshotOf(gitFor(args)),
|
|
54
56
|
remote: flagString(args, 'remote') ?? 'origin',
|
|
55
57
|
url: flagString(args, 'url') ?? '',
|
|
56
58
|
stdin: await readStdin(),
|
package/dist/commands/off.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
// this is the command you run when handing a machine back or when a clone should
|
|
5
5
|
// go back to inheriting the machine default, and it should be able to do that
|
|
6
6
|
// without being able to break anything else.
|
|
7
|
-
import { inspectRepo } from
|
|
8
|
-
import { clearIdentity, legacyAccountKey } from
|
|
9
|
-
import { gitFor } from
|
|
10
|
-
import * as out from
|
|
7
|
+
import { inspectRepo } from '../core/inspect.js';
|
|
8
|
+
import { clearIdentity, legacyAccountKey } from '../core/identity.js';
|
|
9
|
+
import { gitFor } from '../ui/args.js';
|
|
10
|
+
import * as out from '../ui/format.js';
|
|
11
11
|
export default {
|
|
12
12
|
summary: 'unpin this clone (leaves global config alone)',
|
|
13
13
|
examples: ['repown off'],
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// `repown reauthor`: give this branch's unpushed commits by another address the pinned
|
|
2
2
|
// identity, so the guard lets them through. It fetches the push destination first, rewrites
|
|
3
3
|
// only commits no remote has, keeps a backup ref, and never pushes (ADR-026).
|
|
4
|
-
import { planReauthor, applyReauthor } from
|
|
5
|
-
import { confirm, interactive } from
|
|
6
|
-
import { flagBool, gitFor } from
|
|
7
|
-
import * as out from
|
|
8
|
-
import { printable } from
|
|
4
|
+
import { planReauthor, applyReauthor } from '../core/reauthor.js';
|
|
5
|
+
import { confirm, interactive } from '../ui/prompt.js';
|
|
6
|
+
import { flagBool, gitFor } from '../ui/args.js';
|
|
7
|
+
import * as out from '../ui/format.js';
|
|
8
|
+
import { printable } from '../ui/format.js';
|
|
9
9
|
export default {
|
|
10
10
|
summary: 'rewrite this branch\'s unpushed commits by another address as the pinned account',
|
|
11
11
|
options: [
|
package/dist/commands/scan.js
CHANGED
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
import { readdir } from 'node:fs/promises';
|
|
19
19
|
import { join, relative, resolve, sep } from 'node:path';
|
|
20
20
|
import { existsSync, statSync } from 'node:fs';
|
|
21
|
-
import { Git } from
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import
|
|
21
|
+
import { Git } from '../core/git.js';
|
|
22
|
+
import { snapshotOf } from '../core/config-snapshot.js';
|
|
23
|
+
import { inspectRepo } from '../core/inspect.js';
|
|
24
|
+
import { ok, err } from '../core/result.js';
|
|
25
|
+
import { flagBool, flagString, wantsJson, FORMAT_OPTION } from '../ui/args.js';
|
|
26
|
+
import * as out from '../ui/format.js';
|
|
26
27
|
export default {
|
|
27
28
|
summary: 'audit every clone under a directory',
|
|
28
29
|
positionals: { min: 0, max: Infinity, label: '<dir>' },
|
|
@@ -133,7 +134,7 @@ function childAt(root, path) {
|
|
|
133
134
|
* in different folders are told apart instead of printed as one name twice.
|
|
134
135
|
*/
|
|
135
136
|
async function describe(found, showEmails) {
|
|
136
|
-
const git = new Git(found.path);
|
|
137
|
+
const git = snapshotOf(new Git(found.path));
|
|
137
138
|
const repo = await inspectRepo(git);
|
|
138
139
|
const configured = await git.getConfig('repown.mirrorBranch', 'local');
|
|
139
140
|
const mirror = configured && await git.hasCommit('refs/heads/' + configured) ? configured : null;
|
package/dist/commands/setup.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
// It shows the commands its answers stand for, and runs exactly those --
|
|
5
5
|
// `accounts add`, `use`, `guard on`, `fix`, `reauthor`, and a few git lines -- so anything it
|
|
6
6
|
// does can be done, or scripted, without it (src/wizard/setup-run.ts).
|
|
7
|
-
import { providers } from
|
|
8
|
-
import { interactive } from
|
|
9
|
-
import { runSetup } from
|
|
7
|
+
import { providers } from '../core/hosts/index.js';
|
|
8
|
+
import { interactive } from '../ui/prompt.js';
|
|
9
|
+
import { runSetup } from '../wizard/setup-run.js';
|
|
10
10
|
export default {
|
|
11
11
|
summary: 'guided setup of this clone: asks, shows each step and its command, then runs them',
|
|
12
12
|
positionals: { min: 0, max: 1, label: '<account>' },
|
package/dist/commands/start.js
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
// outside a clone, including a bare repository, open the start screen: a
|
|
8
8
|
// runner too. With stdout redirected outside a clone, the top help.
|
|
9
9
|
// Everything else is status.
|
|
10
|
-
import { Git } from
|
|
11
|
-
import { inspectRepo } from
|
|
12
|
-
import { identityProblems } from
|
|
13
|
-
import { interactive } from
|
|
10
|
+
import { Git } from '../core/git.js';
|
|
11
|
+
import { inspectRepo } from '../core/inspect.js';
|
|
12
|
+
import { identityProblems } from './status.js';
|
|
13
|
+
import { interactive } from '../ui/prompt.js';
|
|
14
14
|
export const SETUP_NOTE = 'This clone isn\'t set up yet, so repown is starting setup (repown status shows its settings).';
|
|
15
15
|
export const PINNED_NOTE = 'Starting setup to check this clone (repown status shows its settings without asking anything).';
|
|
16
16
|
/** Setup, status, the start screen, or the top help. No output. */
|
|
@@ -27,11 +27,11 @@ export async function startDefault(deps = realDeps()) {
|
|
|
27
27
|
return pick.choice;
|
|
28
28
|
}
|
|
29
29
|
function startHome() {
|
|
30
|
-
return import(
|
|
30
|
+
return import('../wizard/home-run.js').then((mod) => mod.runHome());
|
|
31
31
|
}
|
|
32
32
|
function startSetup(pinned) {
|
|
33
33
|
const lead = pinned ? PINNED_NOTE : SETUP_NOTE;
|
|
34
|
-
return import(
|
|
34
|
+
return import('../wizard/setup-run.js').then((mod) => mod.runSetup(bareArgs(), { interactive: true, lead }));
|
|
35
35
|
}
|
|
36
36
|
function bareArgs() {
|
|
37
37
|
return { positional: [], flags: new Map() };
|
package/dist/commands/status.js
CHANGED
|
@@ -14,22 +14,24 @@
|
|
|
14
14
|
// What would stop the next push (blockers.ts, the list setup reads too) comes first among
|
|
15
15
|
// the warnings, and `ready:` is said only without it (ADR-026). It is still a warning:
|
|
16
16
|
// the exit code is unchanged (ADR-020). This reports; it changes nothing.
|
|
17
|
-
import { inspectRepo, inspectAuth, activeAccountLabel } from
|
|
18
|
-
import { isPinned } from
|
|
19
|
-
import { loadRegistry } from
|
|
20
|
-
import {
|
|
17
|
+
import { inspectRepo, inspectAuth, activeAccountLabel } from '../core/inspect.js';
|
|
18
|
+
import { isPinned } from '../core/identity.js';
|
|
19
|
+
import { loadRegistry } from '../core/registry.js';
|
|
20
|
+
import { snapshotOf } from '../core/config-snapshot.js';
|
|
21
|
+
import { ALLOW_OWNER_BY_HAND, allowOwnerCommand, allowedOwners, copyableCommand } from '../core/guard/check.js';
|
|
21
22
|
import { existsSync } from 'node:fs';
|
|
22
23
|
import { join } from 'node:path';
|
|
23
|
-
import { gitFor } from
|
|
24
|
-
import * as out from
|
|
25
|
-
import { printable } from
|
|
26
|
-
import { blockers } from
|
|
27
|
-
import { readPushFacts } from
|
|
28
|
-
import { readUnpushed } from
|
|
24
|
+
import { gitFor } from '../ui/args.js';
|
|
25
|
+
import * as out from '../ui/format.js';
|
|
26
|
+
import { printable } from '../ui/format.js';
|
|
27
|
+
import { blockers } from '../core/blockers.js';
|
|
28
|
+
import { readPushFacts } from '../core/push-state.js';
|
|
29
|
+
import { readUnpushed } from '../core/unpushed.js';
|
|
29
30
|
export default {
|
|
30
31
|
summary: 'this clone\'s and this machine\'s settings, and what to fix (bare `repown` when output isn\'t a terminal)',
|
|
31
32
|
async run(args) {
|
|
32
|
-
|
|
33
|
+
// Read-only: every config read of this run comes from one list per scope (ADR-029).
|
|
34
|
+
const git = snapshotOf(gitFor(args));
|
|
33
35
|
const repo = await inspectRepo(git);
|
|
34
36
|
if (!repo.isRepo) {
|
|
35
37
|
out.fail('repown', 'Not a git repository: ' + git.cwd);
|
|
@@ -329,9 +331,9 @@ async function originForeign(repo) {
|
|
|
329
331
|
function ownerWarning(repo) {
|
|
330
332
|
if (!repo.owner)
|
|
331
333
|
return false;
|
|
332
|
-
out.warn('origin', 'origin belongs to "' + repo.owner + '", which is not an owner this clone pushes to.');
|
|
334
|
+
out.warn('origin', 'origin belongs to "' + out.printable(repo.owner) + '", which is not an owner this clone pushes to.');
|
|
333
335
|
out.detail('if that is an organisation you belong to:');
|
|
334
|
-
out.detail('
|
|
336
|
+
out.detail(' ' + (allowOwnerCommand(repo.owner) ?? ALLOW_OWNER_BY_HAND));
|
|
335
337
|
return true;
|
|
336
338
|
}
|
|
337
339
|
function registryUnread() {
|
|
@@ -358,9 +360,11 @@ const GH_UNVERIFIED = 'could not be queried, so who `gh pr create` would act as
|
|
|
358
360
|
/** `gh auth switch` only works for a login gh already lists, and only in gh's spelling. */
|
|
359
361
|
function ghFix(account, auth) {
|
|
360
362
|
const login = ghReportedLogin(account, auth);
|
|
363
|
+
const shown = out.printable(account);
|
|
364
|
+
const fix = login !== null ? copyableCommand(['gh', 'auth', 'switch', '-u', login]) : copyableCommand(['repown', 'use', account, '--gh']);
|
|
361
365
|
if (login !== null)
|
|
362
|
-
return 'fix: gh auth switch
|
|
363
|
-
return 'fix:
|
|
366
|
+
return 'fix: ' + (fix ?? 'gh auth switch to ' + out.printable(login));
|
|
367
|
+
return 'fix: ' + (fix ?? 'repown use with --gh') + ' (signs ' + shown + ' in to gh)';
|
|
364
368
|
}
|
|
365
369
|
function ghReportedLogin(account, auth) {
|
|
366
370
|
if (!auth.gh.ok)
|
package/dist/commands/use.js
CHANGED
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
// GitHub CLI on the same account: `gh auth switch` when gh already lists it,
|
|
18
18
|
// and, in a terminal, `gh auth login` when it does not. After `repown fix`
|
|
19
19
|
// neither changes which account git pushes as.
|
|
20
|
-
import { inspectRepo, inspectAuth } from
|
|
21
|
-
import { pinIdentity } from
|
|
22
|
-
import { lookupAccount, saveAccount } from
|
|
23
|
-
import { ghSwitch, ghLogin, readGhLoginVersion, } from
|
|
24
|
-
import {
|
|
25
|
-
import { readUnpushed, unpushedLines } from
|
|
26
|
-
import { ask, interactive } from
|
|
27
|
-
import { flagString, flagBool, gitFor } from
|
|
28
|
-
import * as out from
|
|
20
|
+
import { inspectRepo, inspectAuth } from '../core/inspect.js';
|
|
21
|
+
import { pinIdentity } from '../core/identity.js';
|
|
22
|
+
import { lookupAccount, saveAccount } from '../core/registry.js';
|
|
23
|
+
import { ghSwitch, ghLogin, readGhLoginVersion, } from '../core/credential/gh.js';
|
|
24
|
+
import { ALLOW_OWNER_BY_HAND, allowOwnerCommand, allowedOwners } from '../core/guard/check.js';
|
|
25
|
+
import { readUnpushed, unpushedLines } from '../core/unpushed.js';
|
|
26
|
+
import { ask, interactive } from '../ui/prompt.js';
|
|
27
|
+
import { flagString, flagBool, gitFor } from '../ui/args.js';
|
|
28
|
+
import * as out from '../ui/format.js';
|
|
29
29
|
/** The last hint while the guard is off; `repown setup` leaves it out when its next step turns the guard on. */
|
|
30
30
|
export const NEXT_GUARD = ' Next: repown guard on (check every push before it leaves)';
|
|
31
31
|
export default {
|
|
@@ -275,9 +275,9 @@ async function ownerConcern(account, repo) {
|
|
|
275
275
|
return;
|
|
276
276
|
if ((await allowedOwners(repo.git, account)).includes(repo.owner.toLowerCase()))
|
|
277
277
|
return;
|
|
278
|
-
out.warn('origin', 'origin belongs to "' + repo.owner + '", not "' + account + '".');
|
|
278
|
+
out.warn('origin', 'origin belongs to "' + out.printable(repo.owner) + '", not "' + out.printable(account) + '".');
|
|
279
279
|
out.detail('normal for an organisation repository. To stop the guard refusing it:');
|
|
280
|
-
out.detail('
|
|
280
|
+
out.detail(' ' + (allowOwnerCommand(repo.owner) ?? ALLOW_OWNER_BY_HAND));
|
|
281
281
|
}
|
|
282
282
|
async function credentialConcern(account, repo) {
|
|
283
283
|
const auth = await inspectAuth(repo.git, repo.originUrl ?? undefined);
|
package/dist/core/blockers.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
// (or git) is about to refuse. A fact that could not be read is a blocker of its own,
|
|
6
6
|
// never an absence (a skipped check must not look passed). What only the guard would
|
|
7
7
|
// refuse is still said with the guard off, as a warning that blocks nothing.
|
|
8
|
-
import { unpushedLines, foreignCount } from
|
|
9
|
-
import {
|
|
8
|
+
import { unpushedLines, foreignCount } from './unpushed.js';
|
|
9
|
+
import { ALLOW_OWNER_BY_HAND, allowOwnerCommand, copyableCommand } from './guard/check.js';
|
|
10
|
+
import { printable } from '../ui/format.js';
|
|
10
11
|
const TOKENS = ['GH_TOKEN', 'GITHUB_TOKEN'];
|
|
11
12
|
export function blockers(facts, choice) {
|
|
12
13
|
const branch = facts.unpushed.branch ?? 'HEAD';
|
|
@@ -100,9 +101,9 @@ function ownerBlocker(destination, branch, choice) {
|
|
|
100
101
|
const guard = choice.guarded ? 'the guard will refuse it' : 'the guard is off, so it pushes there anyway';
|
|
101
102
|
return [{
|
|
102
103
|
kind: 'owner',
|
|
103
|
-
summary: 'the push goes to "' + destination.owner + '"',
|
|
104
|
-
lines: [branch + ' pushes to ' + where + ', owned by "' + destination.owner + '", not ' + choice.account +
|
|
105
|
-
': ' + guard + '. If you belong there:
|
|
104
|
+
summary: 'the push goes to "' + printable(destination.owner) + '"',
|
|
105
|
+
lines: [branch + ' pushes to ' + where + ', owned by "' + printable(destination.owner) + '", not ' + choice.account +
|
|
106
|
+
': ' + guard + '. If you belong there: ' + (allowOwnerCommand(destination.owner) ?? ALLOW_OWNER_BY_HAND)],
|
|
106
107
|
blocks: choice.guarded,
|
|
107
108
|
}];
|
|
108
109
|
}
|
|
@@ -124,8 +125,8 @@ function divergenceBlocker(divergence, branch) {
|
|
|
124
125
|
function upstreamBlocker(facts, branch, autoUpstream) {
|
|
125
126
|
if (facts.upstream !== 'missing' || autoUpstream)
|
|
126
127
|
return [];
|
|
127
|
-
const
|
|
128
|
-
return [{ kind: 'upstream', summary: branch + ' has no upstream', lines: [branch + ' has no upstream: the first push needs
|
|
128
|
+
const push = copyableCommand(['git', 'push', '-u', facts.destination?.remote ?? 'origin', branch]) ?? 'git push -u with the remote and this branch';
|
|
129
|
+
return [{ kind: 'upstream', summary: branch + ' has no upstream', lines: [branch + ' has no upstream: the first push needs ' + push], blocks: true }];
|
|
129
130
|
}
|
|
130
131
|
function detachedBlocker() {
|
|
131
132
|
return { kind: 'detached', summary: 'HEAD is detached', lines: ['HEAD is detached: git pull and a plain git push fail here; git switch to a branch first'], blocks: true };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Config reads answered from one `git config [--scope] --list -z` per scope, read on first
|
|
2
|
+
// use, for code that only reads (ADR-029). A plain `--get` or `--get-all` is answered with
|
|
3
|
+
// the output git itself would print for it, so Git's parsing of that output is unchanged.
|
|
4
|
+
// Other config queries (`--type=bool`, `--get-urlmatch`, `--show-origin --get-regexp`) and
|
|
5
|
+
// every non-config call go to git. A config write refuses.
|
|
6
|
+
import { Git } from './git.js';
|
|
7
|
+
import { succeeded } from './exec.js';
|
|
8
|
+
const SCOPE_FLAGS = new Map([['--local', 'local'], ['--global', 'global'], ['--system', 'system']]);
|
|
9
|
+
/** The first argument after `config` and its scope: the query git is asked, never a value. */
|
|
10
|
+
const PASSED_THROUGH = new Set(['--type=bool', '--get-urlmatch', '--show-origin', '--get-regexp', '--list']);
|
|
11
|
+
export class ConfigSnapshot extends Git {
|
|
12
|
+
lists = new Map();
|
|
13
|
+
exec(args, input) {
|
|
14
|
+
if (args[0] !== 'config')
|
|
15
|
+
return this.spawnGit(args, input);
|
|
16
|
+
const read = configRead(args);
|
|
17
|
+
if (read)
|
|
18
|
+
return this.answer(read);
|
|
19
|
+
if (PASSED_THROUGH.has(actionOf(args) ?? ''))
|
|
20
|
+
return this.spawnGit(args, input);
|
|
21
|
+
return Promise.reject(new Error('a config snapshot only reads: git ' + args.join(' ')));
|
|
22
|
+
}
|
|
23
|
+
async answer(read) {
|
|
24
|
+
const listed = await this.listOf(read.scope);
|
|
25
|
+
if (!succeeded(listed))
|
|
26
|
+
return listed;
|
|
27
|
+
const values = valuesOf(listed.stdout, canonicalKey(read.key));
|
|
28
|
+
if (values.length === 0)
|
|
29
|
+
return answered(1, '');
|
|
30
|
+
if (read.all)
|
|
31
|
+
return answered(0, values.map((value) => (value ?? '') + '\n').join(''));
|
|
32
|
+
return answered(0, (values[values.length - 1] ?? '') + '\n');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* One list per scope, shared by every read of this snapshot (a failure too). A scope with
|
|
36
|
+
* no file at all is empty: `--list` fails there where `--get` says "not set".
|
|
37
|
+
*/
|
|
38
|
+
listOf(scope) {
|
|
39
|
+
const name = scope ?? 'effective';
|
|
40
|
+
if (!this.lists.has(name))
|
|
41
|
+
this.lists.set(name, this.spawnGit(listArgs(scope)).then(missingFileIsEmpty));
|
|
42
|
+
return this.lists.get(name);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A snapshot of a plain `git`, or `git` itself when it already is one. A subclass is refused:
|
|
47
|
+
* the snapshot keeps only the cwd, so whatever the subclass overrides would be dropped.
|
|
48
|
+
*/
|
|
49
|
+
export function snapshotOf(git) {
|
|
50
|
+
if (git instanceof ConfigSnapshot)
|
|
51
|
+
return git;
|
|
52
|
+
if (Object.getPrototypeOf(git) !== Git.prototype)
|
|
53
|
+
throw new Error('snapshotOf takes a plain Git, not ' + git.constructor.name);
|
|
54
|
+
return new ConfigSnapshot(git.cwd);
|
|
55
|
+
}
|
|
56
|
+
function listArgs(scope) {
|
|
57
|
+
return scope ? ['config', '--' + scope, '--list', '-z'] : ['config', '--list', '-z'];
|
|
58
|
+
}
|
|
59
|
+
function missingFileIsEmpty(listed) {
|
|
60
|
+
return !succeeded(listed) && /unable to read config file/.test(listed.stderr) ? answered(0, '') : listed;
|
|
61
|
+
}
|
|
62
|
+
/** The query after `config` and an optional scope flag. */
|
|
63
|
+
function actionOf(args) {
|
|
64
|
+
return SCOPE_FLAGS.has(args[1] ?? '') ? args[2] : args[1];
|
|
65
|
+
}
|
|
66
|
+
/** `config [--scope] --get|--get-all <key>`, exactly the shapes Git's plain getters send. */
|
|
67
|
+
function configRead(args) {
|
|
68
|
+
const scoped = SCOPE_FLAGS.get(args[1] ?? '');
|
|
69
|
+
const rest = args.slice(scoped ? 2 : 1);
|
|
70
|
+
if (rest.length !== 2 || (rest[0] !== '--get' && rest[0] !== '--get-all'))
|
|
71
|
+
return null;
|
|
72
|
+
return { scope: scoped, key: rest[1], all: rest[0] === '--get-all' };
|
|
73
|
+
}
|
|
74
|
+
/** Section and variable name are case-insensitive, a subsection is not: `--list` prints them so. */
|
|
75
|
+
function canonicalKey(key) {
|
|
76
|
+
const first = key.indexOf('.');
|
|
77
|
+
const last = key.lastIndexOf('.');
|
|
78
|
+
if (first <= 0 || last === key.length - 1)
|
|
79
|
+
return '\0';
|
|
80
|
+
const section = key.slice(0, first).toLowerCase();
|
|
81
|
+
const name = key.slice(last + 1).toLowerCase();
|
|
82
|
+
return first === last ? section + '.' + name : section + '.' + key.slice(first + 1, last) + '.' + name;
|
|
83
|
+
}
|
|
84
|
+
/** Every value of `key`, in git's order; null for a key written with no `=` (git's implicit true). */
|
|
85
|
+
function valuesOf(listed, key) {
|
|
86
|
+
const values = [];
|
|
87
|
+
for (const entry of listed.split('\0')) {
|
|
88
|
+
const newline = entry.indexOf('\n');
|
|
89
|
+
const name = newline < 0 ? entry : entry.slice(0, newline);
|
|
90
|
+
if (entry !== '' && name === key)
|
|
91
|
+
values.push(newline < 0 ? null : entry.slice(newline + 1));
|
|
92
|
+
}
|
|
93
|
+
return values;
|
|
94
|
+
}
|
|
95
|
+
function answered(code, stdout) {
|
|
96
|
+
return { code, stdout, stderr: '' };
|
|
97
|
+
}
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
// deliberately rather than rediscovered.
|
|
14
14
|
import { join, dirname } from 'node:path';
|
|
15
15
|
import { existsSync } from 'node:fs';
|
|
16
|
-
import { run, succeeded, lines, notInstalled } from
|
|
17
|
-
import { ok, err } from
|
|
16
|
+
import { run, succeeded, lines, notInstalled } from '../exec.js';
|
|
17
|
+
import { ok, err } from '../result.js';
|
|
18
18
|
const NAMES = ['git-credential-manager', 'git-credential-manager-core'];
|
|
19
19
|
/** Directories that hold GCM but are not necessarily on PATH. */
|
|
20
20
|
async function searchDirectories() {
|