repown 0.7.1 → 0.8.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 CHANGED
@@ -7,6 +7,22 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.8.0] - 2026-11-29
11
+
12
+ ### Added
13
+ - `repown doctor` shows the machine default: who a clone repown hasn't pinned commits as
14
+ (your global `user.name` and `user.email`, the file the email comes from, and which
15
+ recorded account it belongs to), what git does when no address is set (refuses, with
16
+ `user.useConfigOnly`, or makes one up), and any `includeIf` folder rules. A variable the guard refuses (`GH_TOKEN`, `GITHUB_TOKEN`,
17
+ `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_EMAIL`) set in your shell is a warning. Nothing is
18
+ changed: how to make such a clone refuse to commit is printed, never run.
19
+ - The start screen (bare `repown` outside a clone) shows the same default in a `Default`
20
+ row, a `Shell` row when such a variable is set, and counts the clones not set up that one
21
+ of your recorded accounts owns.
22
+
23
+ ### Changed
24
+ - The start screen looks for clones 3 levels down, as `repown scan` does, instead of 2.
25
+
10
26
  ## [0.7.1] - 2026-11-29
11
27
 
12
28
  ### Added
@@ -414,7 +430,8 @@ and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
414
430
  contract for scripts.
415
431
  - Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
416
432
 
417
- [Unreleased]: https://github.com/makubexD/repown/compare/v0.7.1...HEAD
433
+ [Unreleased]: https://github.com/makubexD/repown/compare/v0.8.0...HEAD
434
+ [0.8.0]: https://github.com/makubexD/repown/compare/v0.7.1...v0.8.0
418
435
  [0.7.1]: https://github.com/makubexD/repown/compare/v0.7.0...v0.7.1
419
436
  [0.7.0]: https://github.com/makubexD/repown/compare/v0.6.0...v0.7.0
420
437
  [0.6.0]: https://github.com/makubexD/repown/compare/v0.5.5...v0.6.0
package/README.md CHANGED
@@ -101,7 +101,9 @@ repown # in a terminal: starts the guided setup of this clone
101
101
  > the guard checks every push; and `repown doctor --online` checks the sign-in. You need
102
102
  > only `repown doctor` once and `repown` in each clone.
103
103
 
104
- 1. **`repown doctor`, once per machine.** It ends with a verdict:
104
+ 1. **`repown doctor`, once per machine, from any folder.** It shows who a clone repown
105
+ hasn't pinned commits as (your global identity, and whose account that is), then ends
106
+ with a verdict:
105
107
  - 🟢 `ready: each clone signs in as its own account through Git Credential Manager`
106
108
  - 🟢 `ready · no accounts stored yet: the first push signs in once`
107
109
  - 🔴 `1 problem: gh answers git's sign-in requests: run repown fix`
@@ -256,8 +258,9 @@ then commit and push.
256
258
  | stdout redirected (stdin and stderr still terminals) | Status inside a clone. The top help outside a clone, exit 0 |
257
259
  | No terminal (stdin or stderr is not one) | Status. Exit 1 outside a clone |
258
260
 
259
- The start screen lists the accounts on this machine and the clones it found, then offers
260
- the next command. The summary is in the frame. Picking a command closes the frame with
261
+ The start screen lists the accounts on this machine, who a clone repown hasn't pinned
262
+ commits as, and the clones it found up to 3 levels down (counting those your accounts own),
263
+ then offers the next command. The summary is in the frame. Picking a command closes the frame with
261
264
  that command (Record an account first asks the login, host, name and email in it; Remove
262
265
  an account asks which, then to confirm). Nothing changes until you pick one. After
263
266
  recording or removing an account, checking the machine or stopping gh, it comes back with
@@ -19,6 +19,7 @@ import { flagBool, gitFor } from '../ui/args.js';
19
19
  import { askOnline, closingWithOnline } from './doctor-online.js';
20
20
  import { snapshotOf } from '../core/config-snapshot.js';
21
21
  import { parseGitUrl } from '../core/url.js';
22
+ import { ownerOfEmail, readMachineDefault, refuseAdvice, withoutEmail } from '../core/machine-default.js';
22
23
  import * as out from '../ui/format.js';
23
24
  const DOCTOR_TITLE = 'repown doctor · how this machine signs in to git hosts';
24
25
  const NAME_WIDTH = 14;
@@ -41,7 +42,7 @@ export default {
41
42
  const git = snapshotOf(gitFor(args));
42
43
  const repo = await inspectRepo(git);
43
44
  const auth = await inspectAuth(git, probeUrl(repo));
44
- const warned = printReport(repo, auth, await loadRegistry());
45
+ const warned = printReport(repo, auth, await loadRegistry(), await readMachineDefault());
45
46
  const found = diagnose(auth, ssoHost(repo));
46
47
  if (!flagBool(args, 'online')) {
47
48
  closeDoctor(scoped(repo, found) + warningTally(warned));
@@ -266,17 +267,41 @@ function recordedPhrase(row) {
266
267
  return '';
267
268
  }
268
269
  /** Prints the machine and its accounts; returns how many sources could not be read. */
269
- function printReport(repo, auth, registry) {
270
+ function printReport(repo, auth, registry, machine) {
270
271
  out.heading(DOCTOR_TITLE);
271
272
  const unpinned = unpinnedClone(repo);
272
273
  if (unpinned)
273
274
  printClone(repo);
274
275
  printMachine(auth, unpinned ? MACHINE_FOR_GITHUB : MACHINE);
276
+ const shell = printDefault(machine, registry);
275
277
  // In an unpinned clone the rows are github.com's sign-ins, none of them this clone's.
276
278
  const report = accountRows(registry, auth, unpinned ? null : pinnedOf(repo));
277
279
  printAccounts(report);
278
280
  out.line();
279
- return report.warnings.length;
281
+ return report.warnings.length + shell;
282
+ }
283
+ /**
284
+ * Who a clone repown hasn't pinned commits as (ADR-033): read-only, and the useConfigOnly
285
+ * advice is printed, never run. Returns how many warnings it printed (the shell's variables).
286
+ */
287
+ function printDefault(machine, registry) {
288
+ out.heading(DEFAULT_HEADING);
289
+ out.field('user.name', out.printable(machine.name ?? 'none'));
290
+ out.field('user.email', machine.email ? out.printable(machine.email) + ' (' + emailWhere(machine.emailFile) + ')' : 'none: ' + withoutEmail(machine));
291
+ if (machine.email && registry.ok)
292
+ out.field('belongs to', out.printable(ownerOfEmail(machine.email, registry.value) ?? 'no recorded account'));
293
+ const advice = refuseAdvice(machine);
294
+ if (advice)
295
+ out.detail(out.printable(advice));
296
+ for (const [index, rule] of machine.includeIfs.entries())
297
+ out.field(index === 0 ? 'includeIf' : '', out.printable(rule.condition + ' -> ' + rule.path));
298
+ for (const name of machine.env)
299
+ out.warn('shell', name + ' is set: the guard refuses every push while it is');
300
+ return machine.env.length;
301
+ }
302
+ const DEFAULT_HEADING = "Machine default (what a clone repown hasn't pinned commits as)";
303
+ function emailWhere(file) {
304
+ return file ? out.displayPath(out.printable(file)) : 'set for every git command: -c or GIT_CONFIG_*';
280
305
  }
281
306
  /**
282
307
  * Said first, since the machine below is github.com's: why origin gets no pin, and the helper
@@ -0,0 +1,67 @@
1
+ // What a clone repown hasn't pinned commits as, read once for doctor and the start screen
2
+ // (ADR-033). Read-only. git's effective config is read from a fresh, empty folder outside any
3
+ // repository: no clone's own config takes part, and no `includeIf` folder rule applies, so
4
+ // the answer is the same wherever repown runs. That read sees what a `--global` read can miss:
5
+ // the XDG file beside ~/.gitconfig, and values set for every command (`-c`, GIT_CONFIG_*).
6
+ import { mkdtemp, rm } from 'node:fs/promises';
7
+ import { tmpdir } from 'node:os';
8
+ import { join } from 'node:path';
9
+ import { Git } from './git.js';
10
+ import { hostileSet } from './guard/check.js';
11
+ import { copyableCommand } from './shell.js';
12
+ export async function readMachineDefault(env = process.env) {
13
+ const dir = await mkdtemp(join(tmpdir(), 'repown-default-'));
14
+ try {
15
+ return { ...await readFrom(new Git(dir)), emailVariable: !!env['EMAIL'], env: hostileSet(env) };
16
+ }
17
+ finally {
18
+ await rm(dir, { recursive: true, force: true });
19
+ }
20
+ }
21
+ async function readFrom(git) {
22
+ const [name, email, useConfigOnly, files] = await Promise.all([
23
+ git.getConfig('user.name'), git.getConfig('user.email'),
24
+ git.getBoolConfig('user.useConfigOnly'), git.configOrigins('^(user\\.email|includeif\\..*\\.path)$'),
25
+ ]);
26
+ const fromFile = files.filter((entry) => entry.key === 'user.email').at(-1);
27
+ // A value set for every command wins over every file, and has none.
28
+ const emailFile = fromFile && fromFile.value === email ? fromFile.file : null;
29
+ return { name, email, emailFile, useConfigOnly: useConfigOnly ?? false, includeIfs: files.flatMap(includeIf) };
30
+ }
31
+ /**
32
+ * What a commit in such a clone gets with no `user.email` (measured, git 2.50): useConfigOnly
33
+ * on refuses; otherwise git takes `EMAIL`, or makes one up from the user and host name.
34
+ */
35
+ export function withoutEmail(machine) {
36
+ if (machine.useConfigOnly)
37
+ return "useConfigOnly is on, so a clone repown hasn't pinned can't commit";
38
+ return machine.emailVariable ? 'git uses the EMAIL variable instead' : "git makes one up from this machine's user and host name";
39
+ }
40
+ /**
41
+ * How to make such a clone refuse to commit instead, printed and never run; null when it
42
+ * already does. useConfigOnly alone changes nothing while a default email is set.
43
+ */
44
+ export function refuseAdvice(machine) {
45
+ if (!machine.email && machine.useConfigOnly)
46
+ return null;
47
+ const turnOn = copyableCommand(['git', 'config', '--global', 'user.useConfigOnly', 'true']) ?? '';
48
+ const lead = 'to make a clone repown hasn\'t pinned refuse to commit instead: ';
49
+ if (!machine.email)
50
+ return lead + turnOn;
51
+ const where = machine.emailFile ? 'remove user.email from ' + machine.emailFile : 'stop setting user.email for every command';
52
+ return lead + where + ', then ' + turnOn;
53
+ }
54
+ /** The recorded account whose commit email this is, ignoring case; null when none is. */
55
+ export function ownerOfEmail(email, registry) {
56
+ if (!email)
57
+ return null;
58
+ const wanted = email.toLowerCase();
59
+ const found = Object.entries(registry.accounts).find(([, account]) => account.email.toLowerCase() === wanted);
60
+ return found ? found[0] : null;
61
+ }
62
+ /** `includeif.<condition>.path`: git lowercases the section and the name, never the condition. */
63
+ function includeIf(entry) {
64
+ if (!entry.key.startsWith('includeif.') || !entry.key.endsWith('.path'))
65
+ return [];
66
+ return [{ condition: entry.key.slice('includeif.'.length, -'.path'.length), path: entry.value, file: entry.file }];
67
+ }
@@ -1,5 +1,6 @@
1
1
  // What the start screen reads before it asks: the registry, whether gh is git's
2
- // credential helper, and the clones below this folder. Read-only. A directory
2
+ // credential helper, the machine default (who a clone repown hasn't pinned commits as,
3
+ // ADR-033), and the clones below this folder with their owners. Read-only. A directory
3
4
  // it cannot list is skipped; `repown scan` is the command that reports those.
4
5
  import { readdir } from 'node:fs/promises';
5
6
  import { join, relative, resolve, sep } from 'node:path';
@@ -11,11 +12,13 @@ import { loadRegistry } from '../core/registry.js';
11
12
  import { identityProblems } from '../commands/status.js';
12
13
  import { CONCURRENCY, discover, mapLimited } from '../commands/scan.js';
13
14
  import { signedInLogins } from './setup-flow.js';
14
- /** How many levels below this folder the start screen looks. `repown scan` looks further. */
15
- export const HOME_DEPTH = 2;
15
+ import { readMachineDefault } from '../core/machine-default.js';
16
+ /** How many levels below this folder the start screen looks: `repown scan`'s default (ADR-033). */
17
+ export const HOME_DEPTH = 3;
16
18
  export async function readHome(cwd, deps = {}) {
17
- const [registry, ghIsHelper, clones] = await Promise.all([registryOf(deps), helperOf(cwd, deps), clonesOf(cwd, deps)]);
18
- return { cwd: resolve(cwd), registry, ghIsHelper, clones };
19
+ const machine = deps.machine ? deps.machine() : readMachineDefault();
20
+ const [registry, ghIsHelper, defaults, clones] = await Promise.all([registryOf(deps), helperOf(cwd, deps), machine, clonesOf(cwd, deps)]);
21
+ return { cwd: resolve(cwd), registry, ghIsHelper, machine: defaults, clones };
19
22
  }
20
23
  /**
21
24
  * Global user.name and user.email, shown beside a new account's and never filled in: read only
@@ -97,7 +100,7 @@ async function describeClone(dir, deps) {
97
100
  const repo = await inspect(snapshotOf(new Git(dir)));
98
101
  if (!repo.isRepo)
99
102
  return null;
100
- return { path: resolve(dir), setUp: identityProblems(repo).length === 0 };
103
+ return { path: resolve(dir), setUp: identityProblems(repo).length === 0, owner: repo.owner, ownerHost: repo.owner ? repo.ownerProvider.id : null };
101
104
  }
102
105
  function isClone(clone) {
103
106
  return clone !== null;
@@ -3,7 +3,8 @@
3
3
  import { relative } from 'node:path';
4
4
  import { registryPath } from '../core/registry.js';
5
5
  import { HOME_DEPTH } from './home-context.js';
6
- import { CD_NOTE, CHECK_MACHINE, HELPER_LINE, HINT_ACCOUNT, HINT_DOCTOR, HINT_FIX, HINT_REMOVE, NONE_RECORDED, NOT_SET_UP, QUIT, RECORD_ACCOUNT, REMOVE_ACCOUNT, SET_UP, SETUP_CLONE, SHOW_HELP, STOP_GH, clonesNone, clonesSome, couldNotRead, moreClones, recordedLine, setupHint, unreadableLine, } from './home-text.js';
6
+ import { CD_NOTE, CHECK_MACHINE, HELPER_LINE, HINT_ACCOUNT, HINT_DOCTOR, HINT_FIX, HINT_REMOVE, NONE_RECORDED, NOT_SET_UP, QUIT, RECORD_ACCOUNT, REMOVE_ACCOUNT, SET_UP, SETUP_CLONE, SHOW_HELP, STOP_GH, clonesNone, clonesSome, couldNotRead, defaultLine, moreClones, recordedLine, setupHint, shellLine, unreadableLine, } from './home-text.js';
7
+ import { ownerOfEmail, withoutEmail } from '../core/machine-default.js';
7
8
  import { addAccountArgv, printable } from './setup-flow.js';
8
9
  /** Shown choices. `back` returns to the menu; the others run a command or leave. */
9
10
  export const MENU = {
@@ -12,10 +13,21 @@ export const MENU = {
12
13
  export const BACK = 'back';
13
14
  const LIST_CAP = 20;
14
15
  export function summaryLines(home) {
15
- const lines = [row('Accounts', accountsText(home.registry)), row('Clones', clonesText(home.clones))];
16
- if (home.ghIsHelper)
17
- lines.splice(1, 0, row('Helper', HELPER_LINE));
18
- return lines;
16
+ return [
17
+ row('Accounts', accountsText(home.registry)),
18
+ ...(home.ghIsHelper ? [row('Helper', HELPER_LINE)] : []),
19
+ row('Default', defaultText(home)),
20
+ ...(home.machine.env.length > 0 ? [row('Shell', shellLine(home.machine.env))] : []),
21
+ row('Clones', clonesText(home)),
22
+ ];
23
+ }
24
+ /** Read-only (ADR-033): the address is the user's own, shown in their own terminal. */
25
+ function defaultText(home) {
26
+ const { email } = home.machine;
27
+ if (!email)
28
+ return 'none set: ' + withoutEmail(home.machine);
29
+ const owner = home.registry.ok ? ownerOfEmail(email, home.registry.value) : undefined;
30
+ return printable(defaultLine(email, owner));
19
31
  }
20
32
  export function homeNote(home) {
21
33
  return home.clones.length === 0 ? CD_NOTE : null;
@@ -71,11 +83,22 @@ function accountsSummary(registry) {
71
83
  return unreadableLine(names.length, unread, registryPath());
72
84
  return names.length === 0 ? NONE_RECORDED : recordedLine(names.map(printable));
73
85
  }
74
- function clonesText(clones) {
86
+ function clonesText({ clones, registry }) {
75
87
  if (clones.length === 0)
76
88
  return clonesNone(HOME_DEPTH);
77
- const pending = clones.filter((clone) => !clone.setUp).length;
78
- return clonesSome(clones.length, pending, clones.length - pending);
89
+ const pending = clones.filter((clone) => !clone.setUp);
90
+ const owned = pending.filter((clone) => ownedBy(clone, registry)).length;
91
+ return clonesSome(clones.length, pending.length, clones.length - pending.length, owned);
92
+ }
93
+ /**
94
+ * The push URL's owner is a recorded account on that host: logins compare without case, as
95
+ * hosts do, and an account recorded for one host never owns a clone on another.
96
+ */
97
+ function ownedBy(clone, registry) {
98
+ if (!clone.owner || !registry.ok)
99
+ return false;
100
+ const owner = clone.owner.toLowerCase();
101
+ return Object.entries(registry.value.accounts).some(([login, account]) => login.toLowerCase() === owner && (!account.host || account.host === clone.ownerHost));
79
102
  }
80
103
  function setupItem(home) {
81
104
  if (home.clones.length === 0)
@@ -54,8 +54,21 @@ export function couldNotRead(path) {
54
54
  export function clonesNone(depth) {
55
55
  return 'none below this folder (' + depth + ' levels)';
56
56
  }
57
- export function clonesSome(total, pending, ready) {
58
- return total + ' below this folder: ' + pending + ' not set up, ' + ready + ' set up';
57
+ export function clonesSome(total, pending, ready, owned = 0) {
58
+ const yours = owned > 0 ? ' (' + owned + ' owned by your accounts)' : '';
59
+ return total + ' below this folder: ' + pending + ' not set up' + yours + ', ' + ready + ' set up';
60
+ }
61
+ /**
62
+ * Who a clone repown hasn't pinned commits as, and whose that is: `undefined` when the
63
+ * registry couldn't be read, so a skipped check never reads as "not a recorded account".
64
+ */
65
+ export function defaultLine(email, owner) {
66
+ if (owner === undefined)
67
+ return 'commits as ' + email;
68
+ return 'commits as ' + email + ' · ' + (owner ? owner + "'s" : 'not a recorded account');
69
+ }
70
+ export function shellLine(names) {
71
+ return names.join(', ') + ' set: the guard refuses pushes while ' + (names.length === 1 ? 'it is' : 'they are');
59
72
  }
60
73
  export function setupHint(pending, total) {
61
74
  return pending > 0 ? pending + ' not set up' : total + ' set up';
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "repown",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "repown",
9
- "version": "0.7.1",
9
+ "version": "0.8.0",
10
10
  "license": "MIT",
11
11
  "bin": {
12
12
  "repown": "dist/cli.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repown",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Use several git accounts on one machine: each repo owns its identity, so you move between repos with no switch command and never push the wrong one.",
5
5
  "repository": {
6
6
  "type": "git",