repown 0.5.4 → 0.5.5

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,16 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.5] - 2026-11-27
11
+
12
+ ### Fixed
13
+ - `repown fix` said "nothing to undo -- gh is not installed as a credential helper" while
14
+ `repown doctor` reported gh as the helper, when `gh auth setup-git`'s entries sat in a
15
+ file your git config includes (`include.path`, for example `~/.gitconfig.local`). `fix`
16
+ now finds them there, removes them from that file, and its preview names the file.
17
+ - A `user.name` or `user.email` kept in a file your global config includes is now shown as
18
+ the machine default by setup and `repown status`.
19
+
10
20
  ## [0.5.4] - 2026-10-12
11
21
 
12
22
  ### Changed
@@ -334,7 +344,8 @@ and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
334
344
  contract for scripts.
335
345
  - Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
336
346
 
337
- [Unreleased]: https://github.com/makubexD/repown/compare/v0.5.4...HEAD
347
+ [Unreleased]: https://github.com/makubexD/repown/compare/v0.5.5...HEAD
348
+ [0.5.5]: https://github.com/makubexD/repown/compare/v0.5.4...v0.5.5
338
349
  [0.5.4]: https://github.com/makubexD/repown/compare/v0.5.3...v0.5.4
339
350
  [0.5.3]: https://github.com/makubexD/repown/compare/v0.5.2...v0.5.3
340
351
  [0.5.2]: https://github.com/makubexD/repown/compare/v0.5.1...v0.5.2
@@ -54,8 +54,10 @@ function preview(planned) {
54
54
  }
55
55
  /** What `fix` would remove, and the undo. `repown setup` shows the same lines in its review. */
56
56
  export function previewLines(planned) {
57
+ // The file is named: it may be one the scope includes, not the file the user expects (ADR-030).
57
58
  const entries = planned.flatMap((entry) => [
58
59
  ' ' + entry.scope + ': ' + entry.key,
60
+ ' in ' + entry.file,
59
61
  ...entry.values.map((value) => ' = ' + describeValue(value)),
60
62
  ]);
61
63
  return [
@@ -85,6 +87,7 @@ function reportRemovals(results) {
85
87
  continue;
86
88
  }
87
89
  out.warn('fix', 'could NOT remove ' + entry.scope + ': ' + entry.key);
90
+ out.detail('in ' + entry.file);
88
91
  if (entry.scope === 'system')
89
92
  out.detail('the system scope is machine-wide; re-run this in an ELEVATED shell.');
90
93
  }
@@ -1,9 +1,9 @@
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
1
+ // Config reads answered from one `git config [--scope [--includes]] --list -z` per scope, read on
2
+ // first use, for code that only reads (ADR-029, ADR-030). A plain `--get` or `--get-all` is answered with
3
3
  // the output git itself would print for it, so Git's parsing of that output is unchanged.
4
4
  // Other config queries (`--type=bool`, `--get-urlmatch`, `--show-origin --get-regexp`) and
5
5
  // every non-config call go to git. A config write refuses.
6
- import { Git } from './git.js';
6
+ import { Git, followsIncludes } from './git.js';
7
7
  import { succeeded } from './exec.js';
8
8
  const SCOPE_FLAGS = new Map([['--local', 'local'], ['--global', 'global'], ['--system', 'system']]);
9
9
  /** The first argument after `config` and its scope: the query git is asked, never a value. */
@@ -13,10 +13,11 @@ export class ConfigSnapshot extends Git {
13
13
  exec(args, input) {
14
14
  if (args[0] !== 'config')
15
15
  return this.spawnGit(args, input);
16
- const read = configRead(args);
16
+ const query = withoutIncludes(args);
17
+ const read = configRead(query);
17
18
  if (read)
18
19
  return this.answer(read);
19
- if (PASSED_THROUGH.has(actionOf(args) ?? ''))
20
+ if (PASSED_THROUGH.has(actionOf(query) ?? ''))
20
21
  return this.spawnGit(args, input);
21
22
  return Promise.reject(new Error('a config snapshot only reads: git ' + args.join(' ')));
22
23
  }
@@ -60,8 +61,18 @@ export function snapshotOf(git) {
60
61
  throw new Error('snapshotOf takes a plain Git, not ' + git.constructor.name);
61
62
  return new ConfigSnapshot(git.cwd);
62
63
  }
64
+ /** A global or system list follows includes, as those reads from Git do; local does not (ADR-030). */
63
65
  function listArgs(scope) {
64
- return scope ? ['config', '--' + scope, '--list', '-z'] : ['config', '--list', '-z'];
66
+ if (!scope)
67
+ return ['config', '--list', '-z'];
68
+ return ['config', '--' + scope, ...(followsIncludes(scope) ? ['--includes'] : []), '--list', '-z'];
69
+ }
70
+ /**
71
+ * The query without the `--includes` a scoped read carries: a snapshot's lists already follow
72
+ * includes. Only the flag right after the scope is dropped, so a value is never touched.
73
+ */
74
+ function withoutIncludes(args) {
75
+ return SCOPE_FLAGS.has(args[1] ?? '') && args[2] === '--includes' ? [...args.slice(0, 2), ...args.slice(3)] : args;
65
76
  }
66
77
  function missingFileIsEmpty(listed) {
67
78
  return !succeeded(listed) && /unable to read config file/.test(listed.stderr) ? answered(0, '') : listed;
@@ -27,25 +27,31 @@
27
27
  // machine-wide and needs an elevated shell.
28
28
  import { isGh } from './gh.js';
29
29
  const SCOPES = ['local', 'global', 'system'];
30
- const HOSTS = ['https://github.com', 'https://gist.github.com'];
30
+ /** The helper key of github.com and gist.github.com, the two hosts gh writes. */
31
+ const HELPER_KEYS = '^credential\\.https://(gist\\.)?github\\.com\\.helper$';
31
32
  /**
32
- * What `repair` would remove, without removing it: on each key, gh's values and
33
- * the empty reset gh writes with them. A key holding no gh value is not listed,
34
- * and any other helper on a listed key stays -- `gh auth setup-git`, the undo,
33
+ * What `repair` would remove, without removing it: on each key in each file, gh's
34
+ * values and the empty reset gh writes with them. A key holding no gh value is not
35
+ * listed, and any other helper on a listed key stays -- `gh auth setup-git`, the undo,
35
36
  * would never bring it back.
36
37
  */
37
38
  export async function planRepair(git) {
38
- const found = [];
39
- for (const scope of SCOPES) {
40
- for (const host of HOSTS) {
41
- const key = 'credential.' + host + '.helper';
42
- const values = await git.getAllConfigRaw(key, scope);
43
- if (!values.some(isGh))
44
- continue;
45
- found.push({ scope, key, values: ghEntries(values), removed: false });
46
- }
39
+ const read = await Promise.all(SCOPES.map((scope) => git.configOrigins(HELPER_KEYS, scope)));
40
+ return SCOPES.flatMap((scope, index) => plannedIn(scope, read[index]));
41
+ }
42
+ /** One outcome per (file, key) holding gh's value: gh writes its reset and value together. */
43
+ function plannedIn(scope, entries) {
44
+ const byFileAndKey = new Map();
45
+ for (const entry of entries) {
46
+ const id = entry.file + '\0' + entry.key;
47
+ byFileAndKey.set(id, [...(byFileAndKey.get(id) ?? []), entry]);
47
48
  }
48
- return found;
49
+ return [...byFileAndKey.values()].flatMap((group) => {
50
+ const values = group.map((entry) => entry.value);
51
+ if (!values.some(isGh))
52
+ return [];
53
+ return [{ scope, file: group[0].file, key: group[0].key, values: ghEntries(values), removed: false }];
54
+ });
49
55
  }
50
56
  /** gh's value, or an empty reset sitting directly before one -- the pair gh writes. */
51
57
  function isGhEntry(values, index) {
@@ -57,21 +63,30 @@ function ghEntries(values) {
57
63
  }
58
64
  /**
59
65
  * git can remove a value by PATTERN, not by position -- and two empty resets are
60
- * the same pattern, only one of them gh's. So the key is rewritten: unset, then
61
- * every value that is not gh's added back, in its original order.
66
+ * the same pattern, only one of them gh's. So the key is rewritten in its file:
67
+ * unset, then every value that is not gh's added back, in its original order.
62
68
  */
63
69
  export async function repair(git) {
64
70
  const results = [];
65
- for (const entry of await planRepair(git)) {
66
- const all = await git.getAllConfigRaw(entry.key, entry.scope);
67
- const kept = all.filter((_, index) => !isGhEntry(all, index));
68
- let removed = await git.unsetConfig(entry.key, entry.scope);
69
- for (const value of kept)
70
- removed = await git.addConfig(entry.key, value, entry.scope) && removed;
71
- results.push({ ...entry, removed });
72
- }
71
+ for (const entry of await planRepair(git))
72
+ results.push({ ...entry, removed: await rewrite(git, entry) });
73
73
  return results;
74
74
  }
75
+ /**
76
+ * That file's own values of the key, gh's left out. A local entry goes through `--local`:
77
+ * git prints its origin relative to the worktree (`.git/config`), which `--file=` would
78
+ * resolve against the cwd, and local reads don't follow includes. A global or system origin
79
+ * is absolute, and named outright, so its own includes are not read.
80
+ */
81
+ async function rewrite(git, entry) {
82
+ const target = entry.scope === 'local' ? 'local' : { file: entry.file };
83
+ const all = await git.getAllConfigRaw(entry.key, target);
84
+ const kept = all.filter((_, index) => !isGhEntry(all, index));
85
+ let removed = await git.unsetConfig(entry.key, target);
86
+ for (const value of kept)
87
+ removed = await git.addConfig(entry.key, value, target) && removed;
88
+ return removed;
89
+ }
75
90
  /**
76
91
  * An empty value is the list reset, and saying so is the whole point of showing
77
92
  * the values at all -- on its own the blank line reads like a formatting bug
package/dist/core/git.js CHANGED
@@ -154,20 +154,34 @@ export class Git {
154
154
  return output(await this.exec(['rev-parse', '--git-path', 'hooks']));
155
155
  }
156
156
  // ---- config -------------------------------------------------------------
157
- scoped(scope, args) {
158
- return scope ? ['config', `--${scope}`, ...args] : ['config', ...args];
157
+ /** argv addressed to a scope's own file, or to one file named outright: every write. */
158
+ scoped(target, args) {
159
+ if (target === undefined)
160
+ return ['config', ...args];
161
+ return ['config', typeof target === 'string' ? `--${target}` : `--file=${target.file}`, ...args];
162
+ }
163
+ /**
164
+ * A read's argv. git follows include.path only when no scope is named, unless told to:
165
+ * without --includes a global or system read misses a value kept in a file it includes,
166
+ * which git itself applies (ADR-030). A local read stays bare: a clone's include can name a
167
+ * file the repository tracks, and committed content must not set the guard's own keys.
168
+ * A file named outright is read on its own.
169
+ */
170
+ reading(target, args) {
171
+ const scoped = this.scoped(target, args);
172
+ return followsIncludes(target) ? [...scoped.slice(0, 2), '--includes', ...scoped.slice(2)] : scoped;
159
173
  }
160
174
  /** The value, or null when unset. Omit `scope` to read what git would EFFECTIVELY use. */
161
175
  async getConfig(key, scope) {
162
- return output(await this.exec(this.scoped(scope, ['--get', key])));
176
+ return output(await this.exec(this.reading(scope, ['--get', key])));
163
177
  }
164
178
  /** Effective boolean, or null when unset or not a bool. Omit `scope` for any-scope. */
165
179
  async getBoolConfig(key, scope) {
166
- const value = output(await this.exec(this.scoped(scope, ['--type=bool', '--get', key])));
180
+ const value = output(await this.exec(this.reading(scope, ['--type=bool', '--get', key])));
167
181
  return value === 'true' ? true : value === 'false' ? false : null;
168
182
  }
169
183
  async getAllConfig(key, scope) {
170
- return lines(await this.exec(this.scoped(scope, ['--get-all', key])));
184
+ return lines(await this.exec(this.reading(scope, ['--get-all', key])));
171
185
  }
172
186
  /**
173
187
  * Every value of a multi-valued key, INCLUDING empty ones.
@@ -179,8 +193,8 @@ export class Git {
179
193
  * stopped working. Filtering it out made `repown fix` preview two values while
180
194
  * removing four, and hid the one the explanation is actually about.
181
195
  */
182
- async getAllConfigRaw(key, scope) {
183
- const result = await this.exec(this.scoped(scope, ['--get-all', key]));
196
+ async getAllConfigRaw(key, target) {
197
+ const result = await this.exec(this.reading(target, ['--get-all', key]));
184
198
  if (!succeeded(result))
185
199
  return [];
186
200
  // git ends every value with LF on every platform, so a CR is part of a value: kept.
@@ -195,12 +209,12 @@ export class Git {
195
209
  return succeeded(await this.exec(this.scoped(scope, [key, value])));
196
210
  }
197
211
  /** Appends one more value to a multi-valued key. */
198
- async addConfig(key, value, scope) {
199
- return succeeded(await this.exec(this.scoped(scope, ['--add', key, value])));
212
+ async addConfig(key, value, target) {
213
+ return succeeded(await this.exec(this.scoped(target, ['--add', key, value])));
200
214
  }
201
215
  /** True when the key is gone afterwards -- including when it was never set. */
202
- async unsetConfig(key, scope = 'local') {
203
- const result = await this.exec(this.scoped(scope, ['--unset-all', key]));
216
+ async unsetConfig(key, target = 'local') {
217
+ const result = await this.exec(this.scoped(target, ['--unset-all', key]));
204
218
  return succeeded(result) || result.code === 5; // 5 = the key did not exist
205
219
  }
206
220
  /**
@@ -215,10 +229,13 @@ export class Git {
215
229
  async getUrlMatch(key, url) {
216
230
  return output(await this.exec(['config', '--get-urlmatch', key, url]));
217
231
  }
218
- /** Which FILE each matching key lives in, so a repair edits the scope that holds it. */
232
+ /**
233
+ * Which FILE each matching value lives in, so a repair edits the file that holds it: with a
234
+ * scope, an included file too, under the scope that includes it (ADR-030).
235
+ */
219
236
  async configOrigins(pattern, scope) {
220
- const args = this.scoped(scope, ['--show-origin', '--get-regexp', pattern]);
221
- return lines(await this.exec(args)).flatMap(parseOriginLine);
237
+ const result = await this.exec(this.reading(scope, ['--show-origin', '-z', '--get-regexp', pattern]));
238
+ return succeeded(result) ? parseOrigins(result.stdout) : [];
222
239
  }
223
240
  // ---- history ------------------------------------------------------------
224
241
  /**
@@ -426,16 +443,28 @@ export class Git {
426
443
  return ok(counts);
427
444
  }
428
445
  }
446
+ /** The machine's own scopes, whose includes are the user's files (ADR-030). */
447
+ export function followsIncludes(target) {
448
+ return target === 'global' || target === 'system';
449
+ }
429
450
  /**
430
- * `file:<path>\t<key> <value>`. The path is printed UNQUOTED and may hold
431
- * spaces (`C:/Program Files/Git/etc/gitconfig`), so it ends at the TAB, not at
432
- * the first space.
451
+ * `--show-origin -z --get-regexp`: `<origin>\0<key>\n<value>\0` per value, a key with no
452
+ * `=` written without the newline. NUL can't occur in a path, key or value, so a path with
453
+ * spaces or a value with a tab or newline comes back whole. Only a `file:` origin can be
454
+ * edited; a command-line or blob one is left out.
433
455
  */
434
- function parseOriginLine(line) {
435
- const match = /^file:([^\t]+)\t(\S+)(?: (.*))?$/.exec(line);
436
- if (!match)
437
- return [];
438
- return [{ file: match[1], key: match[2], value: match[3] ?? '' }];
456
+ function parseOrigins(stdout) {
457
+ const fields = stdout.split('\0');
458
+ const entries = [];
459
+ for (let index = 0; index + 1 < fields.length; index += 2) {
460
+ const origin = fields[index];
461
+ const pair = fields[index + 1];
462
+ if (!origin.startsWith('file:'))
463
+ continue;
464
+ const newline = pair.indexOf('\n');
465
+ entries.push({ file: origin.slice('file:'.length), key: newline < 0 ? pair : pair.slice(0, newline), value: newline < 0 ? '' : pair.slice(newline + 1) });
466
+ }
467
+ return entries;
439
468
  }
440
469
  /**
441
470
  * NUL-terminated fields, subject LAST. git refuses NUL in a name or an address,
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "repown",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "repown",
9
- "version": "0.5.4",
9
+ "version": "0.5.5",
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.5.4",
3
+ "version": "0.5.5",
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",