repown 0.5.2 → 0.5.4

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.5.4] - 2026-10-12
11
+
12
+ ### Changed
13
+ - Reading a clone starts up to three fewer git processes (about 75 ms each on
14
+ Windows): the guard's state now comes from the hook location already read, and the
15
+ sign-in and later-push-URL checks share one read of origin's push URLs. Output is
16
+ unchanged.
17
+
18
+ ## [0.5.3] - 2026-10-11
19
+
20
+ ### Fixed
21
+ - Setup and `repown status` missed a push's own sign-in when a `url.<base>.insteadOf` or
22
+ `pushInsteadOf` rule put a token in origin's push URL, or when a remote with several URLs
23
+ had the token in one but the last. They now judge every URL git pushes with, and say
24
+ `origin's push URL, as git resolves it, carries its own sign-in` without printing the rule,
25
+ whose name holds the token. A rule that takes a token out is no longer reported.
26
+ - The same check printed an `http.<url>.extraheader` key whole, password included when that
27
+ `<url>` held one; such a key is now printed as `an http.<url>.extraheader setting`. A push
28
+ straight to a URL that an `insteadOf` rule gives a token is now found too, named by the key
29
+ that holds the URL.
30
+ - With two push URLs for origin, a push could land on one and be refused by the guard on the
31
+ other, and setup and `repown status` said nothing: they read only the first URL's owner.
32
+ They now name a later URL's owner that this clone isn't allowed to push to, with the
33
+ command that allows it.
34
+ - A branch that pushes straight to a URL was judged by that URL's owner even when a
35
+ `pushInsteadOf` rule sends the push elsewhere. Setup and `repown status` now say they can't
36
+ tell where such a push lands, name no owner for it, and leave it to the guard.
37
+
10
38
  ## [0.5.2] - 2026-10-10
11
39
 
12
40
  ### Fixed
@@ -306,7 +334,9 @@ and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
306
334
  contract for scripts.
307
335
  - Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
308
336
 
309
- [Unreleased]: https://github.com/makubexD/repown/compare/v0.5.2...HEAD
337
+ [Unreleased]: https://github.com/makubexD/repown/compare/v0.5.4...HEAD
338
+ [0.5.4]: https://github.com/makubexD/repown/compare/v0.5.3...v0.5.4
339
+ [0.5.3]: https://github.com/makubexD/repown/compare/v0.5.2...v0.5.3
310
340
  [0.5.2]: https://github.com/makubexD/repown/compare/v0.5.1...v0.5.2
311
341
  [0.5.1]: https://github.com/makubexD/repown/compare/v0.5.0...v0.5.1
312
342
  [0.5.0]: https://github.com/makubexD/repown/compare/v0.4.0...v0.5.0
@@ -19,6 +19,8 @@ export function blockers(facts, choice) {
19
19
  ...facts.env.map((name) => envBlocker(name, choice)),
20
20
  ...facts.configOverrides.map((key) => configBlocker(key, choice.email)),
21
21
  ...ownerBlocker(facts.destination, branch, choice),
22
+ ...laterUrlsBlocker(facts.laterUrls, facts.destination, choice),
23
+ ...rewriteBlocker(facts.rewritable, branch),
22
24
  ...divergenceBlocker(facts.divergence, branch),
23
25
  ...upstreamBlocker(facts, branch, choice.autoUpstream),
24
26
  ...(facts.detached ? [detachedBlocker()] : []),
@@ -41,14 +43,16 @@ function unpushedBlocker(fact, choice) {
41
43
  }
42
44
  /** Where a remote names the same repository, the fix is setup's repoint. */
43
45
  function signinBlocker(facts, branch, account) {
44
- const key = facts.signinKey;
45
- if (!key)
46
+ const signin = facts.signin;
47
+ if (!signin)
46
48
  return [];
47
- const fix = facts.repoint?.key === key ? ': point it back at ' + facts.repoint.remote + ' with repown setup --repoint' : '';
49
+ // A rewrite rule's key holds the token in its name: only the remote is ever printed for it.
50
+ const holder = 'key' in signin ? signin.key : 'named' in signin ? signin.named : printable(signin.remote) + "'s push URL, as git resolves it,";
51
+ const fix = 'key' in signin && facts.repoint?.key === signin.key ? ': point it back at ' + facts.repoint.remote + ' with repown setup --repoint' : '';
48
52
  return [{
49
53
  kind: 'signin',
50
54
  summary: 'the branch pushes with its own sign-in',
51
- lines: [key + ' carries its own sign-in, so pushes from ' + branch + ' use it, not ' + account + fix],
55
+ lines: [holder + ' carries its own sign-in, so pushes from ' + branch + ' use it, not ' + account + fix],
52
56
  blocks: true,
53
57
  }];
54
58
  }
@@ -93,10 +97,7 @@ function envBlocker(name, choice) {
93
97
  };
94
98
  }
95
99
  function ownerBlocker(destination, branch, choice) {
96
- if (!destination)
97
- return [];
98
- const owner = destination.owner.toLowerCase();
99
- if (owner === choice.account.toLowerCase() || destination.allowed.includes(owner))
100
+ if (!destination || allows(destination.owner, destination.allowed, choice.account))
100
101
  return [];
101
102
  const where = destination.remote ?? 'its URL';
102
103
  const guard = choice.guarded ? 'the guard will refuse it' : 'the guard is off, so it pushes there anyway';
@@ -109,6 +110,47 @@ function ownerBlocker(destination, branch, choice) {
109
110
  blocks: choice.guarded,
110
111
  }];
111
112
  }
113
+ /**
114
+ * A later push URL the guard refuses while the first takes the push: the push half-lands.
115
+ * Judged as ownerBlocker judges the first URL, which speaks alone when it is refused itself.
116
+ */
117
+ function laterUrlsBlocker(later, first, choice) {
118
+ if (!later || (first && !allows(first.owner, first.allowed, choice.account)))
119
+ return [];
120
+ const refused = onceEach(later.owners.filter(({ owner }) => !allows(owner, later.allowed, choice.account)));
121
+ if (refused.length === 0)
122
+ return [];
123
+ const names = refused.map(({ owner, host }) => '"' + printable(owner) + '" (' + host + ')').join(', ');
124
+ const urls = refused.length === 1 ? 'that URL' : 'those URLs';
125
+ const guard = choice.guarded ? 'the guard will refuse ' + urls + ' while the first takes the push' : 'the guard is off, so the push goes there too';
126
+ const fix = refused.map(({ owner }) => allowOwnerCommand(owner) ?? ALLOW_OWNER_BY_HAND).join(' and ');
127
+ const remote = printable(later.remote);
128
+ return [{
129
+ kind: 'pushurls',
130
+ summary: remote + ' also pushes to "' + printable(refused[0].owner) + '"',
131
+ lines: [remote + ' also pushes to ' + names + ', not ' + choice.account + ': ' + guard + '. If you belong there: ' + fix],
132
+ blocks: choice.guarded,
133
+ }];
134
+ }
135
+ /** One per owner, compared as the guard compares them (case-insensitively), first spelling kept. */
136
+ function onceEach(owners) {
137
+ return owners.filter(({ owner }, index) => owners.findIndex((other) => other.owner.toLowerCase() === owner.toLowerCase()) === index);
138
+ }
139
+ /** Said, never blocking: the guard still checks the URL git hands it. */
140
+ function rewriteBlocker(rewritable, branch) {
141
+ if (!rewritable)
142
+ return [];
143
+ return [{
144
+ kind: 'rewrite',
145
+ summary: "repown can't tell where the push goes",
146
+ lines: [rewritable.key + ' names a URL that a pushInsteadOf rule may rewrite, so repown ' +
147
+ "can't tell where a push from " + branch + ' lands: the guard checks it when you push'],
148
+ blocks: false,
149
+ }];
150
+ }
151
+ function allows(owner, allowed, account) {
152
+ return owner.toLowerCase() === account.toLowerCase() || allowed.includes(owner.toLowerCase());
153
+ }
112
154
  function divergenceBlocker(divergence, branch) {
113
155
  if (!divergence.ok) {
114
156
  return [{ kind: 'divergence', summary: branch + ' could not be compared with its upstream', lines: [branch + ' could not be compared with its upstream (' + divergence.error + ')'], blocks: true }];
package/dist/core/git.js CHANGED
@@ -98,6 +98,21 @@ export class Git {
98
98
  async rewrittenUrl(url) {
99
99
  return output(await this.exec(['ls-remote', '--get-url', '--', url]));
100
100
  }
101
+ /**
102
+ * The values of every key matching `pattern`, null for a key set with no value. A failed
103
+ * read keeps no git message: one can quote a key that holds a token (`url.<base>.*`).
104
+ */
105
+ async configValues(pattern) {
106
+ const asked = await this.exec(['config', '--get-regexp', '-z', pattern]);
107
+ if (asked.code === 1 && !asked.stdout)
108
+ return ok([]);
109
+ if (!succeeded(asked))
110
+ return err('git config could not be read');
111
+ return ok(asked.stdout.split('\0').filter(Boolean).map((entry) => {
112
+ const newline = entry.indexOf('\n');
113
+ return newline < 0 ? null : entry.slice(newline + 1);
114
+ }));
115
+ }
101
116
  /** Remote names, in the order git lists them. A failed read is an error, not "none". */
102
117
  async readRemotes() {
103
118
  const listed = await this.exec(['remote']);
@@ -51,10 +51,6 @@ async function hookDirs(git) {
51
51
  return null;
52
52
  return { own: join(resolve(git.cwd, common), 'hooks'), effective: resolve(git.cwd, hooks) };
53
53
  }
54
- /** The pre-push hook git will actually RUN -- through core.hooksPath if that is set. */
55
- export async function hookPath(git) {
56
- return (await hookLocation(git))?.path ?? null;
57
- }
58
54
  export async function hookLocation(git) {
59
55
  const dirs = await hookDirs(git);
60
56
  return dirs ? { path: join(dirs.effective, 'pre-push'), redirected: isRedirected(dirs) } : null;
@@ -88,8 +84,14 @@ function redirectMessage(dirs) {
88
84
  'pre-push hook run: repown guard check --remote="$1" --url="$2"';
89
85
  }
90
86
  export async function guardState(git) {
91
- const path = await hookPath(git);
92
- return path ? stateOf(path) : 'off';
87
+ return guardStateAt(await hookLocation(git));
88
+ }
89
+ /**
90
+ * The guard's state at a location already read, so one read need not ask git twice. Only a
91
+ * location from this same read: after a write or a wait, read it again (ADR-029).
92
+ */
93
+ export async function guardStateAt(location) {
94
+ return location ? stateOf(location.path) : 'off';
93
95
  }
94
96
  /**
95
97
  * The PATH fallback trusts a `repown` only if it SAYS it is repown. Without this, any
@@ -9,7 +9,7 @@
9
9
  import { parseGitUrl } from './url.js';
10
10
  import { providerFor } from './hosts/index.js';
11
11
  import { readIdentity } from './identity.js';
12
- import { guardState, hookLocation } from './guard/hook.js';
12
+ import { guardStateAt, hookLocation } from './guard/hook.js';
13
13
  import { findGcm, listAccounts, isGcm } from './credential/gcm.js';
14
14
  import { ghState, ghInstalled, isGh } from './credential/gh.js';
15
15
  const DEFAULT_PROBE_URL = 'https://github.com/';
@@ -18,14 +18,14 @@ export async function inspectRepo(git) {
18
18
  const originUrl = isRepo ? await git.getConfig('remote.origin.url') : null;
19
19
  const url = originUrl ? parseGitUrl(originUrl) : null;
20
20
  const sides = await originSides(git, originUrl);
21
- const [root, branch, hook, identity, guard, helper] = await Promise.all([
21
+ const [root, branch, hook, identity, helper] = await Promise.all([
22
22
  isRepo ? git.root() : Promise.resolve(null),
23
23
  isRepo ? git.currentBranch() : Promise.resolve(null),
24
24
  isRepo ? hookLocation(git) : Promise.resolve(null),
25
25
  readIdentity(git, sides.credential.keys[0] ?? null),
26
- isRepo ? guardState(git) : Promise.resolve('off'),
27
26
  git.getUrlMatch('credential.helper', sides.credential.url ?? DEFAULT_PROBE_URL),
28
27
  ]);
28
+ const guard = await guardStateAt(hook);
29
29
  return {
30
30
  git, isRepo, root, branch, originUrl, url, provider: providerFor(url),
31
31
  owner: sides.owner, ownerProvider: sides.ownerProvider,
@@ -15,12 +15,19 @@ export async function readPushFacts(git, unpushed, env = process.env) {
15
15
  const head = await git.currentBranch();
16
16
  const branch = head?.kind === 'branch' ? head.name : null;
17
17
  const target = branch ? await pushTarget(git, branch) : null;
18
- const [configOverrides, signinKey, repoint, destination, divergence, elsewhere, upstream] = await Promise.all([
19
- overridesIn(git), signinOf(git, target), repointOf(git, branch), destinationOf(git, target),
18
+ const rewritable = await rewritableOf(git, target);
19
+ // A remote target's push URLs, read once for the sign-in and later-URL checks.
20
+ const pushed = target?.isRemote ? git.remoteUrls(target.name, true) : null;
21
+ const [configOverrides, signin, repoint, destination, laterUrls, divergence, elsewhere, upstream] = await Promise.all([
22
+ overridesIn(git),
23
+ signinOf(git, target, { rewritable: rewritable !== null, pushed }),
24
+ repointOf(git, branch),
25
+ rewritable ? null : destinationOf(git, target),
26
+ laterUrlsOf(git, target, pushed),
20
27
  divergenceOf(git, target), elsewhereOf(git, target), upstreamOf(git, branch, target),
21
28
  ]);
22
29
  return {
23
- unpushed, env: hostileSet(env), configOverrides, elsewhere, signinKey, repoint, destination, divergence,
30
+ unpushed, env: hostileSet(env), configOverrides, elsewhere, signin, repoint, destination, laterUrls, rewritable, divergence,
24
31
  detached: head?.kind === 'detached', upstream,
25
32
  };
26
33
  }
@@ -33,17 +40,49 @@ function carriesSecret(raw) {
33
40
  const user = raw ? parseGitUrl(raw)?.user : null;
34
41
  return !!user && (user.includes(':') || /^(gh[pousr]_|github_pat_)/i.test(user));
35
42
  }
36
- async function signinOf(git, target) {
37
- if (target && !target.isRemote && carriesSecret(target.name))
38
- return target.key;
39
- if (target?.isRemote) {
40
- // A push uses pushurl when there is one, so a token in the fetch url does not sign it in.
41
- const key = await git.getConfig('remote.' + target.name + '.pushurl') !== null ? 'remote.' + target.name + '.pushurl' : 'remote.' + target.name + '.url';
42
- if (carriesSecret(await git.getConfig(key)))
43
- return key;
44
- }
43
+ async function signinOf(git, target, { rewritable, pushed }) {
44
+ const found = pushed && target ? await remoteSignin(git, target.name, await pushed)
45
+ : target && !rewritable ? await bareSignin(git, target) : null;
46
+ if (found)
47
+ return found;
45
48
  const headers = await git.configOrigins('^http\\.(.*\\.)?extraheader$');
46
- return headers[0]?.key ?? null;
49
+ if (!headers[0])
50
+ return null;
51
+ // The key's <url> can hold a password: then only a fixed description is printed.
52
+ return headers[0].key.includes('@') ? { named: 'an http.<url>.extraheader setting' } : { key: headers[0].key };
53
+ }
54
+ /** A push straight to a URL, as typed and after insteadOf; a pushInsteadOf one is not judged (rewritableOf). */
55
+ async function bareSignin(git, target) {
56
+ if (target.key === null)
57
+ return null;
58
+ if (carriesSecret(target.name))
59
+ return { key: target.key };
60
+ return carriesSecret(await bareTargetUrl(git, target.name)) ? { remote: target.key } : null;
61
+ }
62
+ /**
63
+ * Judged on every URL git pushes `remote` with, after its own rewriting, so a token a rule
64
+ * adds is found and one a rule takes out is not. A URL that is a configured value is named
65
+ * by its key; any other came from a rewrite, and only the remote is named.
66
+ */
67
+ async function remoteSignin(git, remote, pushed) {
68
+ if (!pushed.ok)
69
+ return configuredSignin(git, remote);
70
+ const signed = pushed.value.find(carriesSecret);
71
+ if (!signed)
72
+ return null;
73
+ for (const key of ['remote.' + remote + '.pushurl', 'remote.' + remote + '.url']) {
74
+ if ((await git.getAllConfig(key)).includes(signed))
75
+ return { key };
76
+ }
77
+ return { remote };
78
+ }
79
+ /** A git that cannot list the URLs (before 2.7, or config it refuses): every configured value, without rewrites. */
80
+ async function configuredSignin(git, remote) {
81
+ // A push uses pushurl when there is one, so a token in the fetch url does not sign it in.
82
+ const pushurl = 'remote.' + remote + '.pushurl';
83
+ const pushurls = await git.getAllConfig(pushurl);
84
+ const [key, values] = pushurls.length > 0 ? [pushurl, pushurls] : ['remote.' + remote + '.url', await git.getAllConfig('remote.' + remote + '.url')];
85
+ return values.some(carriesSecret) ? { key } : null;
47
86
  }
48
87
  async function repointOf(git, branch) {
49
88
  const unknown = branch ? await unknownDestination(git, branch) : null;
@@ -63,10 +102,47 @@ async function destinationOf(git, target) {
63
102
  const allowed = (await git.getAllConfig('repown.allowOwner', 'local')).map((value) => value.toLowerCase());
64
103
  return { remote: target.isRemote ? target.name : null, owner, allowed };
65
104
  }
105
+ async function laterUrlsOf(git, target, pushed) {
106
+ if (!target?.isRemote || !pushed)
107
+ return null;
108
+ const urls = [...new Set(await pushUrlsOf(git, target.name, await pushed))];
109
+ if (urls.length < 2)
110
+ return null;
111
+ const owners = urls.slice(1).flatMap((raw) => {
112
+ const url = parseGitUrl(raw);
113
+ const provider = providerFor(url);
114
+ const owner = url ? provider.ownerOf(url) : null;
115
+ return owner ? [{ owner, host: provider.label }] : [];
116
+ });
117
+ const allowed = (await git.getAllConfig('repown.allowOwner', 'local')).map((value) => value.toLowerCase());
118
+ return { remote: target.name, owners, allowed };
119
+ }
120
+ /** Every URL git pushes `remote` with; a git that cannot list them gets the configured values. */
121
+ async function pushUrlsOf(git, remote, listed) {
122
+ if (listed.ok)
123
+ return listed.value;
124
+ const pushurls = await git.getAllConfig('remote.' + remote + '.pushurl');
125
+ return pushurls.length > 0 ? pushurls : git.getAllConfig('remote.' + remote + '.url');
126
+ }
66
127
  function pushUrlOf(git, remote) {
67
128
  return git.remotePushUrl(remote);
68
129
  }
69
- /** A push straight to a URL, as git rewrites it (insteadOf; see rewrittenUrl). */
130
+ /**
131
+ * A push straight to a URL that a pushInsteadOf value prefixes (an empty or missing one
132
+ * matches all). No offline git command resolves pushInsteadOf for a bare URL, and git's
133
+ * rules (first-read ties, empty values) were measured as too many to copy, so repown says it
134
+ * can't tell; a failed read can't either. A `remote."<URL>"` section needs nothing here: it
135
+ * makes the URL a remote, whose push URL git itself resolves.
136
+ */
137
+ async function rewritableOf(git, target) {
138
+ if (!target || target.isRemote)
139
+ return null;
140
+ const url = target.name;
141
+ const rules = await git.configValues('^url\\..*\\.pushinsteadof$');
142
+ const ruled = !rules.ok || rules.value.some((value) => value === null || url.startsWith(value));
143
+ return ruled ? { key: target.key ?? 'its push URL' } : null;
144
+ }
145
+ /** A push straight to a URL after insteadOf (see rewrittenUrl); only when no pushInsteadOf may apply (rewritableOf). */
70
146
  async function bareTargetUrl(git, url) {
71
147
  return (await git.rewrittenUrl(url)) ?? url;
72
148
  }
@@ -25,7 +25,7 @@ import { plainPrompter } from './plain.js';
25
25
  import { COMMAND_MARK } from './review-text.js';
26
26
  import { blockers } from '../core/blockers.js';
27
27
  import { readPushFacts } from '../core/push-state.js';
28
- import { guardState, hookLocation } from '../core/guard/hook.js';
28
+ import { guardStateAt, hookLocation } from '../core/guard/hook.js';
29
29
  import { readUnpushed } from '../core/unpushed.js';
30
30
  const CANCELLED = 130;
31
31
  export async function runSetup(args, deps) {
@@ -365,7 +365,8 @@ function closing(account, found) {
365
365
  /** Re-read after the run: a step may have fixed what the review showed, or not. */
366
366
  async function blockersNow(git, account) {
367
367
  const email = await git.getConfig('user.email', 'local') ?? '';
368
- const [facts, guard, hook] = await Promise.all([readPushFacts(git, await readUnpushed(git)), guardState(git), hookLocation(git)]);
368
+ const [facts, hook] = await Promise.all([readPushFacts(git, await readUnpushed(git)), hookLocation(git)]);
369
+ const guard = await guardStateAt(hook);
369
370
  return blockers(facts, { email, account, autoUpstream: false, guarded: guard !== 'off' || hook?.redirected === true });
370
371
  }
371
372
  async function printClone(before, state) {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "repown",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "repown",
9
- "version": "0.5.2",
9
+ "version": "0.5.4",
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.2",
3
+ "version": "0.5.4",
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",