repown 0.8.0 → 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,18 @@ 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
+
10
22
  ## [0.8.0] - 2026-11-29
11
23
 
12
24
  ### Added
@@ -430,7 +442,8 @@ and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
430
442
  contract for scripts.
431
443
  - Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
432
444
 
433
- [Unreleased]: https://github.com/makubexD/repown/compare/v0.8.0...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
434
447
  [0.8.0]: https://github.com/makubexD/repown/compare/v0.7.1...v0.8.0
435
448
  [0.7.1]: https://github.com/makubexD/repown/compare/v0.7.0...v0.7.1
436
449
  [0.7.0]: https://github.com/makubexD/repown/compare/v0.6.0...v0.7.0
@@ -290,7 +290,8 @@ function printDefault(machine, registry) {
290
290
  out.field('user.email', machine.email ? out.printable(machine.email) + ' (' + emailWhere(machine.emailFile) + ')' : 'none: ' + withoutEmail(machine));
291
291
  if (machine.email && registry.ok)
292
292
  out.field('belongs to', out.printable(ownerOfEmail(machine.email, registry.value) ?? 'no recorded account'));
293
- const advice = refuseAdvice(machine);
293
+ printPush(machine);
294
+ const advice = refuseAdvice(machine, (path) => out.displayPath(path));
294
295
  if (advice)
295
296
  out.detail(out.printable(advice));
296
297
  for (const [index, rule] of machine.includeIfs.entries())
@@ -299,7 +300,16 @@ function printDefault(machine, registry) {
299
300
  out.warn('shell', name + ' is set: the guard refuses every push while it is');
300
301
  return machine.env.length;
301
302
  }
302
- const DEFAULT_HEADING = "Machine default (what a clone repown hasn't pinned commits as)";
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
+ }
303
313
  function emailWhere(file) {
304
314
  return file ? out.displayPath(out.printable(file)) : 'set for every git command: -c or GIT_CONFIG_*';
305
315
  }
@@ -9,15 +9,46 @@ import { join } from 'node:path';
9
9
  import { Git } from './git.js';
10
10
  import { hostileSet } from './guard/check.js';
11
11
  import { copyableCommand } from './shell.js';
12
+ const GITHUB = 'https://github.com';
12
13
  export async function readMachineDefault(env = process.env) {
13
14
  const dir = await mkdtemp(join(tmpdir(), 'repown-default-'));
14
15
  try {
15
- return { ...await readFrom(new Git(dir)), emailVariable: !!env['EMAIL'], env: hostileSet(env) };
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) };
16
19
  }
17
20
  finally {
18
21
  await rm(dir, { recursive: true, force: true });
19
22
  }
20
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
+ }
21
52
  async function readFrom(git) {
22
53
  const [name, email, useConfigOnly, files] = await Promise.all([
23
54
  git.getConfig('user.name'), git.getConfig('user.email'),
@@ -38,17 +69,18 @@ export function withoutEmail(machine) {
38
69
  return machine.emailVariable ? 'git uses the EMAIL variable instead' : "git makes one up from this machine's user and host name";
39
70
  }
40
71
  /**
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.
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.
43
75
  */
44
- export function refuseAdvice(machine) {
76
+ export function refuseAdvice(machine, showPath = (path) => path) {
45
77
  if (!machine.email && machine.useConfigOnly)
46
78
  return null;
47
79
  const turnOn = copyableCommand(['git', 'config', '--global', 'user.useConfigOnly', 'true']) ?? '';
48
- const lead = 'to make a clone repown hasn\'t pinned refuse to commit instead: ';
80
+ const lead = "optional: to make a clone repown hasn't pinned refuse to commit instead: ";
49
81
  if (!machine.email)
50
82
  return lead + turnOn;
51
- const where = machine.emailFile ? 'remove user.email from ' + machine.emailFile : 'stop setting user.email for every command';
83
+ const where = machine.emailFile ? 'remove user.email from ' + showPath(machine.emailFile) : 'stop setting user.email for every command';
52
84
  return lead + where + ', then ' + turnOn;
53
85
  }
54
86
  /** The recorded account whose commit email this is, ignoring case; null when none is. */
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "repown",
3
- "version": "0.8.0",
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.8.0",
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.8.0",
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",