repown 0.7.1 → 0.8.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,34 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.8.1] - 2026-11-29
11
+
12
+ ### Added
13
+ - `repown doctor`'s Machine default also says who a clone repown hasn't pinned pushes as:
14
+ the username git sends to github.com (`credential.username`) and the file it is set in,
15
+ and, for a username set for an organisation's path, who clones under it push as instead
16
+ (or that a later entry overrides it).
17
+
18
+ ### Changed
19
+ - The advice to make such a clone refuse to commit starts `optional:` (pinning each clone is
20
+ the fix), and shows its file with Windows separators on Windows.
21
+
22
+ ## [0.8.0] - 2026-11-29
23
+
24
+ ### Added
25
+ - `repown doctor` shows the machine default: who a clone repown hasn't pinned commits as
26
+ (your global `user.name` and `user.email`, the file the email comes from, and which
27
+ recorded account it belongs to), what git does when no address is set (refuses, with
28
+ `user.useConfigOnly`, or makes one up), and any `includeIf` folder rules. A variable the guard refuses (`GH_TOKEN`, `GITHUB_TOKEN`,
29
+ `GIT_AUTHOR_EMAIL`, `GIT_COMMITTER_EMAIL`) set in your shell is a warning. Nothing is
30
+ changed: how to make such a clone refuse to commit is printed, never run.
31
+ - The start screen (bare `repown` outside a clone) shows the same default in a `Default`
32
+ row, a `Shell` row when such a variable is set, and counts the clones not set up that one
33
+ of your recorded accounts owns.
34
+
35
+ ### Changed
36
+ - The start screen looks for clones 3 levels down, as `repown scan` does, instead of 2.
37
+
10
38
  ## [0.7.1] - 2026-11-29
11
39
 
12
40
  ### Added
@@ -414,7 +442,9 @@ and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
414
442
  contract for scripts.
415
443
  - Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
416
444
 
417
- [Unreleased]: https://github.com/makubexD/repown/compare/v0.7.1...HEAD
445
+ [Unreleased]: https://github.com/makubexD/repown/compare/v0.8.1...HEAD
446
+ [0.8.1]: https://github.com/makubexD/repown/compare/v0.8.0...v0.8.1
447
+ [0.8.0]: https://github.com/makubexD/repown/compare/v0.7.1...v0.8.0
418
448
  [0.7.1]: https://github.com/makubexD/repown/compare/v0.7.0...v0.7.1
419
449
  [0.7.0]: https://github.com/makubexD/repown/compare/v0.6.0...v0.7.0
420
450
  [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,51 @@ 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
+ printPush(machine);
294
+ const advice = refuseAdvice(machine, (path) => out.displayPath(path));
295
+ if (advice)
296
+ out.detail(out.printable(advice));
297
+ for (const [index, rule] of machine.includeIfs.entries())
298
+ out.field(index === 0 ? 'includeIf' : '', out.printable(rule.condition + ' -> ' + rule.path));
299
+ for (const name of machine.env)
300
+ out.warn('shell', name + ' is set: the guard refuses every push while it is');
301
+ return machine.env.length;
302
+ }
303
+ const DEFAULT_HEADING = "Machine default (who a clone repown hasn't pinned commits and pushes as)";
304
+ /** Who such a clone signs in to github.com as, and who clones under an organisation's path do. */
305
+ function printPush(machine) {
306
+ const where = (file) => file ? ' (' + out.displayPath(out.printable(file)) + ')' : '';
307
+ out.field('pushes as', machine.pushUser ? out.printable(machine.pushUser) + ' on github.com' + where(machine.pushFile) : 'none set: the credential helper picks the account');
308
+ for (const scoped of machine.scopedUsernames) {
309
+ const said = scoped.overridden ? ', overridden by a later entry' : '';
310
+ out.field('', 'under ' + out.printable(scoped.url + ': ' + scoped.user) + said + where(scoped.file));
311
+ }
312
+ }
313
+ function emailWhere(file) {
314
+ return file ? out.displayPath(out.printable(file)) : 'set for every git command: -c or GIT_CONFIG_*';
280
315
  }
281
316
  /**
282
317
  * Said first, since the machine below is github.com's: why origin gets no pin, and the helper
@@ -0,0 +1,99 @@
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
+ const GITHUB = 'https://github.com';
13
+ export async function readMachineDefault(env = process.env) {
14
+ const dir = await mkdtemp(join(tmpdir(), 'repown-default-'));
15
+ try {
16
+ const git = new Git(dir);
17
+ const [identity, push] = await Promise.all([readFrom(git), readPush(git)]);
18
+ return { ...identity, ...push, emailVariable: !!env['EMAIL'], env: hostileSet(env) };
19
+ }
20
+ finally {
21
+ await rm(dir, { recursive: true, force: true });
22
+ }
23
+ }
24
+ /**
25
+ * Who git signs in to github.com as without a clone's pin. git applies every matching
26
+ * `credential.<url>.username` in the order it reads config, and the last wins (measured):
27
+ * the path counts in the match, and only reaching the helper depends on useHttpPath.
28
+ */
29
+ async function readPush(git) {
30
+ const entries = (await git.configOrigins('^credential\\..*username$')).flatMap(forGithub);
31
+ const pathFree = entries.filter((entry) => entry.path === null);
32
+ const last = pathFree.at(-1);
33
+ const scoped = entries.flatMap((entry, at) => entry.path === null ? [] : [{
34
+ url: entry.url, user: entry.user, file: entry.file, overridden: pathFree.some((later) => entries.indexOf(later) > at),
35
+ }]);
36
+ return { pushUser: last?.user ?? null, pushFile: last?.file ?? null, scopedUsernames: scoped };
37
+ }
38
+ /**
39
+ * A username entry that applies to github.com over https: the bare key, or a URL git matches
40
+ * against `https://github.com/...` (host in any case, a trailing slash, no user part; measured).
41
+ */
42
+ function forGithub(entry) {
43
+ if (entry.key === 'credential.username')
44
+ return [{ url: GITHUB, path: null, user: entry.value, file: entry.file }];
45
+ const url = entry.key.slice('credential.'.length, -'.username'.length);
46
+ const found = /^https:\/\/github\.com(\/(.*))?$/i.exec(url);
47
+ if (!found)
48
+ return [];
49
+ const path = found[2] ? found[2] : null;
50
+ return [{ url, path, user: entry.value, file: entry.file }];
51
+ }
52
+ async function readFrom(git) {
53
+ const [name, email, useConfigOnly, files] = await Promise.all([
54
+ git.getConfig('user.name'), git.getConfig('user.email'),
55
+ git.getBoolConfig('user.useConfigOnly'), git.configOrigins('^(user\\.email|includeif\\..*\\.path)$'),
56
+ ]);
57
+ const fromFile = files.filter((entry) => entry.key === 'user.email').at(-1);
58
+ // A value set for every command wins over every file, and has none.
59
+ const emailFile = fromFile && fromFile.value === email ? fromFile.file : null;
60
+ return { name, email, emailFile, useConfigOnly: useConfigOnly ?? false, includeIfs: files.flatMap(includeIf) };
61
+ }
62
+ /**
63
+ * What a commit in such a clone gets with no `user.email` (measured, git 2.50): useConfigOnly
64
+ * on refuses; otherwise git takes `EMAIL`, or makes one up from the user and host name.
65
+ */
66
+ export function withoutEmail(machine) {
67
+ if (machine.useConfigOnly)
68
+ return "useConfigOnly is on, so a clone repown hasn't pinned can't commit";
69
+ return machine.emailVariable ? 'git uses the EMAIL variable instead' : "git makes one up from this machine's user and host name";
70
+ }
71
+ /**
72
+ * How to make such a clone refuse to commit instead: optional (pinning each clone is the fix),
73
+ * printed and never run; null when it already refuses. useConfigOnly alone changes nothing
74
+ * while a default email is set. `showPath` draws the file as the caller shows paths.
75
+ */
76
+ export function refuseAdvice(machine, showPath = (path) => path) {
77
+ if (!machine.email && machine.useConfigOnly)
78
+ return null;
79
+ const turnOn = copyableCommand(['git', 'config', '--global', 'user.useConfigOnly', 'true']) ?? '';
80
+ const lead = "optional: to make a clone repown hasn't pinned refuse to commit instead: ";
81
+ if (!machine.email)
82
+ return lead + turnOn;
83
+ const where = machine.emailFile ? 'remove user.email from ' + showPath(machine.emailFile) : 'stop setting user.email for every command';
84
+ return lead + where + ', then ' + turnOn;
85
+ }
86
+ /** The recorded account whose commit email this is, ignoring case; null when none is. */
87
+ export function ownerOfEmail(email, registry) {
88
+ if (!email)
89
+ return null;
90
+ const wanted = email.toLowerCase();
91
+ const found = Object.entries(registry.accounts).find(([, account]) => account.email.toLowerCase() === wanted);
92
+ return found ? found[0] : null;
93
+ }
94
+ /** `includeif.<condition>.path`: git lowercases the section and the name, never the condition. */
95
+ function includeIf(entry) {
96
+ if (!entry.key.startsWith('includeif.') || !entry.key.endsWith('.path'))
97
+ return [];
98
+ return [{ condition: entry.key.slice('includeif.'.length, -'.path'.length), path: entry.value, file: entry.file }];
99
+ }
@@ -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.1",
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.1",
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.1",
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",