repown 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +99 -1
  2. package/README.md +4 -1
  3. package/dist/cli.js +4 -4
  4. package/dist/commands/accounts.js +20 -14
  5. package/dist/commands/doctor.js +7 -5
  6. package/dist/commands/fix.js +5 -5
  7. package/dist/commands/guard.js +7 -5
  8. package/dist/commands/off.js +4 -4
  9. package/dist/commands/reauthor.js +5 -5
  10. package/dist/commands/scan.js +9 -7
  11. package/dist/commands/setup.js +3 -3
  12. package/dist/commands/start.js +6 -6
  13. package/dist/commands/status.js +20 -16
  14. package/dist/commands/use.js +18 -14
  15. package/dist/core/blockers.js +8 -7
  16. package/dist/core/config-snapshot.js +97 -0
  17. package/dist/core/credential/gcm.js +3 -3
  18. package/dist/core/credential/gh.js +14 -6
  19. package/dist/core/credential/repair.js +1 -1
  20. package/dist/core/git.js +27 -4
  21. package/dist/core/guard/check.js +44 -8
  22. package/dist/core/guard/hook.js +1 -1
  23. package/dist/core/hosts/github.js +43 -12
  24. package/dist/core/hosts/index.js +21 -3
  25. package/dist/core/identity.js +1 -1
  26. package/dist/core/inspect.js +19 -8
  27. package/dist/core/push-destination.js +1 -1
  28. package/dist/core/push-state.js +12 -8
  29. package/dist/core/reauthor.js +3 -3
  30. package/dist/core/registry.js +12 -5
  31. package/dist/core/unpushed.js +10 -9
  32. package/dist/program.js +10 -10
  33. package/dist/ui/args.js +3 -3
  34. package/dist/ui/command.js +1 -1
  35. package/dist/ui/dispatch.js +6 -6
  36. package/dist/ui/format.js +31 -0
  37. package/dist/ui/help.js +2 -2
  38. package/dist/ui/prompt.js +1 -1
  39. package/dist/wizard/clack.js +56 -21
  40. package/dist/wizard/engine.js +1 -1
  41. package/dist/wizard/home-context.js +23 -10
  42. package/dist/wizard/home-flow.js +33 -11
  43. package/dist/wizard/home-run.js +92 -44
  44. package/dist/wizard/home-text.js +18 -3
  45. package/dist/wizard/plain.js +2 -2
  46. package/dist/wizard/review-text.js +19 -4
  47. package/dist/wizard/setup-changes.js +2 -2
  48. package/dist/wizard/setup-context.js +22 -18
  49. package/dist/wizard/setup-flow.js +115 -35
  50. package/dist/wizard/setup-run.js +31 -28
  51. package/npm-shrinkwrap.json +378 -17
  52. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -7,6 +7,102 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.1] - 2026-10-03
11
+
12
+ A safety release: account lookups can no longer borrow another account's profile, the start
13
+ screen won't ask questions it can't save, and the owner repown names for a push is the one the
14
+ push guard checks.
15
+
16
+ ### Fixed
17
+ - **Security: a typed login can no longer pull in another account's GitHub profile.**
18
+ `repown accounts add ../user` made the lookup GitHub's own `/user`, your signed-in account,
19
+ and suggested its name and noreply id for a different login. Now only a login spelled the way
20
+ GitHub spells one (letters, digits, `-`, `_`) is looked up, as one URL path segment; anything
21
+ else is recorded as typed with nothing suggested, and a login GitHub can't have (a dot, a
22
+ slash) is named as no account on github.com without asking it. A profile name with control or
23
+ bidi characters is dropped instead of drawn and saved (the name question then says `GitHub
24
+ gives no usable name for …`), the missing-account warning escapes the login, and setup and the
25
+ start screen refuse a login made only of dots.
26
+ - The start screen's Record an account checks first that the account list can be saved. When
27
+ it can't be read, or has entries repown can't read, it says why and asks nothing, instead of
28
+ asking four questions and then failing to save (and skipping the "already recorded" check).
29
+ - Setup, `repown status`, `repown use`, `repown scan` and the push blockers name the owner your
30
+ pushes really go to, after `pushurl` and git's `url.<base>.insteadOf` / `pushInsteadOf`
31
+ rewrites, the same owner the pre-push guard checks, with the host of that same URL. Before,
32
+ they read the configured URL and could say a push was fine that the guard then refused, or
33
+ warn about an owner the push never reaches. `scan --format json`'s `owner` and `host` now
34
+ describe that push URL (the same values unless pushes are rewritten).
35
+
36
+ ## [0.5.0] - 2026-10-03
37
+
38
+ The start screen (bare `repown` outside a clone) now records and removes accounts without
39
+ leaving its frame, and warns before you pin a clone to someone else's GitHub account. Every
40
+ command repown prints for you to copy now pastes correctly in sh, bash, zsh, fish, PowerShell
41
+ and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
42
+
43
+ ### Added
44
+ - **Remove an account** on the start screen: pick a recorded account, read what stays (clones
45
+ pinned to it keep their settings and the push guard), and confirm. It runs
46
+ `repown accounts remove`, and the start screen comes back without it (ADR-028).
47
+ - **A warning before you record someone else's GitHub account.** When gh or Git Credential
48
+ Manager is signed in to github.com as other accounts only, the name question in setup and on
49
+ the start screen says so: `signed in as octo-work, not octocat: if octocat isn't your
50
+ account, go back; otherwise the first push asks you to sign in as it`. A login that exists
51
+ can still be a stranger's, and its noreply address would link your commits to them. Nothing
52
+ is refused (ADR-028).
53
+ - `repown accounts add <login>`, when it asks, warns when github.com has no account by that
54
+ name (a typo) or the name is an organisation. It still records the account, and says nothing
55
+ when GitHub can't be asked.
56
+
57
+ ### Changed
58
+ - **Record an account on the start screen asks everything in its frame**: the login, where it
59
+ is hosted, and the commit name and email, prefilled from GitHub (name, noreply address), with
60
+ Back on each. It then runs `repown accounts add` with every answer as a flag, so the bare
61
+ `Commit name` / `Commit email` prompts are gone. A login already recorded is refused, and in
62
+ setup and on the start screen a login github.com doesn't know, or an organisation, is named
63
+ on the name question, so a typo can be fixed before anything is recorded.
64
+ - **The start screen comes back** with a fresh summary after Record an account, Remove an
65
+ account, Check this machine or Stop gh serving credentials. Quit, Esc or Ctrl-C leave it
66
+ (ADR-028).
67
+ - **Prefilled answers say where they came from**: `GitHub shows no name for octocat, so this
68
+ is the login`, and `prefilled with the private address GitHub gives octocat` instead of a
69
+ `1234+` example beside the real address. This machine's own identity reads `your default git
70
+ name here is …: use it only if this account does too`.
71
+ - **The wizard is easier to read in colour**, with nothing to set: the title is a cyan badge,
72
+ summary values are bold cyan, commands are cyan, and setup's closing line leads with a green
73
+ ✔ (done) or a yellow ▲ (the next push will fail). On a terminal that can't draw Unicode
74
+ (Windows' classic console, the Linux console) the marks are `+` and `!`. Without colour (a
75
+ pipe, a log, `NO_COLOR`) the output is exactly as before. `repown accounts add` prints its
76
+ next command, `repown use <account>`, in cyan the same way (ADR-027).
77
+ - A question's note (this clone's current account, what the history holds, what GitHub said
78
+ about a login) is drawn inside that question, under its hint, instead of as a line above it
79
+ that read as part of the previous answer. Plain prompts already did this.
80
+ - Commands setup and the start screen show for you to copy start with `$ ` instead of `> `:
81
+ pasted whole, `>` was a redirect in every shell and left an empty file named `repown`
82
+ (ADR-027).
83
+ - **Faster on Windows:** `repown status`, `doctor`, `scan`, the pre-push guard, the start
84
+ screen's read of each clone and setup's first read take each git config scope in one read
85
+ instead of one process per key. One `repown status` in a clone went from 68 processes to 38,
86
+ about a third faster (ADR-029).
87
+
88
+ ### Fixed
89
+ - **Security: pasting a command repown printed can no longer run part of it as code.** A value
90
+ no quoting keeps literal in every shell (`$`, a backtick, `"`, `%`, `!`, a curly double quote,
91
+ a control character, an escaping backslash) used to get a single-quoted command, and pasted
92
+ into PowerShell or cmd part of it ran. A remote's owner made of such text could do that
93
+ through the allow-owner advice of the guard, `status` or `use`. repown now says to add it by
94
+ hand, shows `[value not safe to paste]` in a command it runs itself, and prints the owner
95
+ with control and bidi characters escaped.
96
+ - **Copyable commands paste correctly in cmd and PowerShell as well as POSIX shells**: a value
97
+ with a space or an apostrophe is in double quotes (`--name "Octo Cat"`, on every OS), a
98
+ GitHub noreply address and a URL are no longer quoted, a leading `@` and a dashed word with
99
+ `.` or `:` are quoted (PowerShell read them as a splat, or split them), and the `--` before a
100
+ dashed login is `"--"` (PowerShell dropped a bare one).
101
+ - On a terminal that can't draw Unicode (classic Windows cmd), a text question's hint lines
102
+ drew a `│` beside a gutter of `|`. They now use the same bar as the rest of the frame.
103
+ - `type < to go back` no longer breaks across two lines; when it doesn't fit after the hint,
104
+ it takes a line of its own.
105
+
10
106
  ## [0.4.0] - 2026-09-30
11
107
 
12
108
  ### Added
@@ -141,7 +237,9 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
141
237
  contract for scripts.
142
238
  - Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
143
239
 
144
- [Unreleased]: https://github.com/makubexD/repown/compare/v0.4.0...HEAD
240
+ [Unreleased]: https://github.com/makubexD/repown/compare/v0.5.1...HEAD
241
+ [0.5.1]: https://github.com/makubexD/repown/compare/v0.5.0...v0.5.1
242
+ [0.5.0]: https://github.com/makubexD/repown/compare/v0.4.0...v0.5.0
145
243
  [0.4.0]: https://github.com/makubexD/repown/compare/v0.3.0...v0.4.0
146
244
  [0.3.0]: https://github.com/makubexD/repown/compare/v0.2.0...v0.3.0
147
245
  [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. Nothing changes until you pick one.
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 "./program.js";
21
- import { renderTopHelp } from "./ui/help.js";
22
- import { start } from "./ui/dispatch.js";
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("./commands/start.js").then((mod) => mod.startDefault()),
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 "../core/registry.js";
6
- import { providers } from "../core/hosts/index.js";
7
- import { ask, interactive } from "../ui/prompt.js";
8
- import { flagString, wantsJson, FORMAT_OPTION } from "../ui/args.js";
9
- import * as out from "../ui/format.js";
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) {
@@ -68,21 +69,26 @@ async function add(args) {
68
69
  return 1;
69
70
  const written = await saveAccount(account, { name, email, host: hostId });
70
71
  if (!written.ok) {
71
- out.fail('accounts', written.error);
72
+ out.fail('accounts', out.printable(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: repown use ' + account);
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 provider = providers().find((candidate) => candidate.id === hostId);
83
- if (!provider?.resolveProfile)
84
- return {};
85
- return (await provider.resolveProfile(account)) ?? {};
88
+ const found = await lookUpProfile(providers().find((candidate) => candidate.id === hostId), account);
89
+ if (found.problem)
90
+ out.warn('accounts', out.printable(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');
@@ -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 "../core/inspect.js";
17
- import { loadRegistry } from "../core/registry.js";
18
- import { gitFor } from "../ui/args.js";
19
- import * as out from "../ui/format.js";
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
- const git = gitFor(args);
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());
@@ -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 "../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";
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: [
@@ -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 "../core/guard/hook.js";
7
- import { check } from "../core/guard/check.js";
8
- import { flagString, gitFor } from "../ui/args.js";
9
- import * as out from "../ui/format.js";
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
- git: gitFor(args),
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(),
@@ -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 "../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";
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 "../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";
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: [
@@ -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 "../core/git.js";
22
- import { inspectRepo } from "../core/inspect.js";
23
- import { ok, err } from "../core/result.js";
24
- import { flagBool, flagString, wantsJson, FORMAT_OPTION } from "../ui/args.js";
25
- import * as out from "../ui/format.js";
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;
@@ -143,7 +144,8 @@ async function describe(found, showEmails) {
143
144
  path: resolve(found.path),
144
145
  remote: repo.originUrl !== null,
145
146
  owner: repo.owner,
146
- host: repo.url ? repo.provider.id : null,
147
+ // owner and host describe the same URL: where origin's pushes go (ADR-014 note).
148
+ host: repo.url ? repo.ownerProvider.id : null,
147
149
  identity: identityOf(repo),
148
150
  guard: repo.guard,
149
151
  history: counts.ok ? grouped(counts.value, showEmails) : null,
@@ -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 "../core/hosts/index.js";
8
- import { interactive } from "../ui/prompt.js";
9
- import { runSetup } from "../wizard/setup-run.js";
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>' },
@@ -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 "../core/git.js";
11
- import { inspectRepo } from "../core/inspect.js";
12
- import { identityProblems } from "./status.js";
13
- import { interactive } from "../ui/prompt.js";
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("../wizard/home-run.js").then((mod) => mod.runHome());
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("../wizard/setup-run.js").then((mod) => mod.runSetup(bareArgs(), { interactive: true, lead }));
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() };
@@ -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 "../core/inspect.js";
18
- import { isPinned } from "../core/identity.js";
19
- import { loadRegistry } from "../core/registry.js";
20
- import { allowedOwners, shellWord } from "../core/guard/check.js";
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 "../ui/args.js";
24
- import * as out from "../ui/format.js";
25
- import { printable } from "../ui/format.js";
26
- import { blockers } from "../core/blockers.js";
27
- import { readPushFacts } from "../core/push-state.js";
28
- import { readUnpushed } from "../core/unpushed.js";
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
- const git = gitFor(args);
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);
@@ -133,7 +135,7 @@ function person(name, email, absent) {
133
135
  function originOf(repo) {
134
136
  if (!repo.originUrl)
135
137
  return 'no remote';
136
- return (repo.owner ?? 'unknown') + ' ' + out.dim('(' + repo.provider.label + ')');
138
+ return (repo.owner ?? 'unknown') + ' ' + out.dim('(' + repo.ownerProvider.label + ')');
137
139
  }
138
140
  function pushesAs(repo) {
139
141
  if (!repo.originUrl)
@@ -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(' git config --local --add repown.allowOwner ' + shellWord(repo.owner));
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 -u ' + login;
363
- return 'fix: repown use ' + account + ' --gh (signs ' + account + ' in to gh)';
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)
@@ -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 "../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 { allowedOwners, shellWord } 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";
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 {
@@ -50,7 +50,7 @@ export default {
50
50
  return 1;
51
51
  if (!reportPinned(await pinIdentity(git, { ...values, account }, repo.credentialKeys)))
52
52
  return 1;
53
- out.pass('identity', values.name + ' <' + values.email + '> push-as:' + account);
53
+ out.pass('identity', out.printable(values.name + ' <' + values.email + '> push-as:' + account));
54
54
  if (flagBool(args, 'gh'))
55
55
  await applyGh(account, repo);
56
56
  await reportConcerns(account, repo, values.email);
@@ -100,16 +100,20 @@ async function askAndRecord(account, repo, known) {
100
100
  out.line();
101
101
  out.line(' No record of "' + account + '" yet. Asking once, then never again.');
102
102
  const entry = await askProfile({
103
- name: known.name ?? suggested.name ?? account, email: known.email ?? suggested.email,
103
+ name: offered(known.name) ?? suggested.name ?? offered(account) ?? '', email: offered(known.email) ?? suggested.email,
104
104
  }, repo.provider.id);
105
105
  if (!entry)
106
106
  return null;
107
107
  const saved = await saveAccount(account, entry);
108
108
  if (!saved.ok)
109
- out.warn('accounts', 'pinned, but not recorded: ' + saved.error);
109
+ out.warn('accounts', 'pinned, but not recorded: ' + out.printable(saved.error));
110
110
  out.line();
111
111
  return entry;
112
112
  }
113
+ /** A default worth offering: one printable() would change would be drawn raw, and saved if accepted. */
114
+ function offered(value) {
115
+ return value && out.printable(value) === value ? value : undefined;
116
+ }
113
117
  async function askProfile(defaults, host) {
114
118
  const name = await ask('Commit name', defaults.name);
115
119
  if (!name.ok) {
@@ -275,9 +279,9 @@ async function ownerConcern(account, repo) {
275
279
  return;
276
280
  if ((await allowedOwners(repo.git, account)).includes(repo.owner.toLowerCase()))
277
281
  return;
278
- out.warn('origin', 'origin belongs to "' + repo.owner + '", not "' + account + '".');
282
+ out.warn('origin', 'origin belongs to "' + out.printable(repo.owner) + '", not "' + out.printable(account) + '".');
279
283
  out.detail('normal for an organisation repository. To stop the guard refusing it:');
280
- out.detail(' git config --local --add repown.allowOwner ' + shellWord(repo.owner));
284
+ out.detail(' ' + (allowOwnerCommand(repo.owner) ?? ALLOW_OWNER_BY_HAND));
281
285
  }
282
286
  async function credentialConcern(account, repo) {
283
287
  const auth = await inspectAuth(repo.git, repo.originUrl ?? undefined);
@@ -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 "./unpushed.js";
9
- import { shellWord } from "./guard/check.js";
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: git config --local --add repown.allowOwner ' + shellWord(destination.owner)],
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 remote = shellWord(facts.destination?.remote ?? 'origin');
128
- return [{ kind: 'upstream', summary: branch + ' has no upstream', lines: [branch + ' has no upstream: the first push needs git push -u ' + remote + ' ' + shellWord(branch)], blocks: true }];
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 };