repown 0.5.2 → 0.5.3

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,26 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.3] - 2026-10-11
11
+
12
+ ### Fixed
13
+ - Setup and `repown status` missed a push's own sign-in when a `url.<base>.insteadOf` or
14
+ `pushInsteadOf` rule put a token in origin's push URL, or when a remote with several URLs
15
+ had the token in one but the last. They now judge every URL git pushes with, and say
16
+ `origin's push URL, as git resolves it, carries its own sign-in` without printing the rule,
17
+ whose name holds the token. A rule that takes a token out is no longer reported.
18
+ - The same check printed an `http.<url>.extraheader` key whole, password included when that
19
+ `<url>` held one; such a key is now printed as `an http.<url>.extraheader setting`. A push
20
+ straight to a URL that an `insteadOf` rule gives a token is now found too, named by the key
21
+ that holds the URL.
22
+ - With two push URLs for origin, a push could land on one and be refused by the guard on the
23
+ other, and setup and `repown status` said nothing: they read only the first URL's owner.
24
+ They now name a later URL's owner that this clone isn't allowed to push to, with the
25
+ command that allows it.
26
+ - A branch that pushes straight to a URL was judged by that URL's owner even when a
27
+ `pushInsteadOf` rule sends the push elsewhere. Setup and `repown status` now say they can't
28
+ tell where such a push lands, name no owner for it, and leave it to the guard.
29
+
10
30
  ## [0.5.2] - 2026-10-10
11
31
 
12
32
  ### Fixed
@@ -306,7 +326,8 @@ and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
306
326
  contract for scripts.
307
327
  - Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
308
328
 
309
- [Unreleased]: https://github.com/makubexD/repown/compare/v0.5.2...HEAD
329
+ [Unreleased]: https://github.com/makubexD/repown/compare/v0.5.3...HEAD
330
+ [0.5.3]: https://github.com/makubexD/repown/compare/v0.5.2...v0.5.3
310
331
  [0.5.2]: https://github.com/makubexD/repown/compare/v0.5.1...v0.5.2
311
332
  [0.5.1]: https://github.com/makubexD/repown/compare/v0.5.0...v0.5.1
312
333
  [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']);
@@ -15,12 +15,13 @@ 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
+ const [configOverrides, signin, repoint, destination, laterUrls, divergence, elsewhere, upstream] = await Promise.all([
20
+ overridesIn(git), signinOf(git, target, rewritable !== null), repointOf(git, branch), rewritable ? null : destinationOf(git, target), laterUrlsOf(git, target),
20
21
  divergenceOf(git, target), elsewhereOf(git, target), upstreamOf(git, branch, target),
21
22
  ]);
22
23
  return {
23
- unpushed, env: hostileSet(env), configOverrides, elsewhere, signinKey, repoint, destination, divergence,
24
+ unpushed, env: hostileSet(env), configOverrides, elsewhere, signin, repoint, destination, laterUrls, rewritable, divergence,
24
25
  detached: head?.kind === 'detached', upstream,
25
26
  };
26
27
  }
@@ -33,17 +34,49 @@ function carriesSecret(raw) {
33
34
  const user = raw ? parseGitUrl(raw)?.user : null;
34
35
  return !!user && (user.includes(':') || /^(gh[pousr]_|github_pat_)/i.test(user));
35
36
  }
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
- }
37
+ async function signinOf(git, target, rewritable) {
38
+ const found = target?.isRemote ? await remoteSignin(git, target.name) : target && !rewritable ? await bareSignin(git, target) : null;
39
+ if (found)
40
+ return found;
45
41
  const headers = await git.configOrigins('^http\\.(.*\\.)?extraheader$');
46
- return headers[0]?.key ?? null;
42
+ if (!headers[0])
43
+ return null;
44
+ // The key's <url> can hold a password: then only a fixed description is printed.
45
+ return headers[0].key.includes('@') ? { named: 'an http.<url>.extraheader setting' } : { key: headers[0].key };
46
+ }
47
+ /** A push straight to a URL, as typed and after insteadOf; a pushInsteadOf one is not judged (rewritableOf). */
48
+ async function bareSignin(git, target) {
49
+ if (target.key === null)
50
+ return null;
51
+ if (carriesSecret(target.name))
52
+ return { key: target.key };
53
+ return carriesSecret(await bareTargetUrl(git, target.name)) ? { remote: target.key } : null;
54
+ }
55
+ /**
56
+ * Judged on every URL git pushes `remote` with, after its own rewriting, so a token a rule
57
+ * adds is found and one a rule takes out is not. A URL that is a configured value is named
58
+ * by its key; any other came from a rewrite, and only the remote is named.
59
+ */
60
+ async function remoteSignin(git, remote) {
61
+ const pushed = await git.remoteUrls(remote, true);
62
+ if (!pushed.ok)
63
+ return configuredSignin(git, remote);
64
+ const signed = pushed.value.find(carriesSecret);
65
+ if (!signed)
66
+ return null;
67
+ for (const key of ['remote.' + remote + '.pushurl', 'remote.' + remote + '.url']) {
68
+ if ((await git.getAllConfig(key)).includes(signed))
69
+ return { key };
70
+ }
71
+ return { remote };
72
+ }
73
+ /** A git that cannot list the URLs (before 2.7, or config it refuses): every configured value, without rewrites. */
74
+ async function configuredSignin(git, remote) {
75
+ // A push uses pushurl when there is one, so a token in the fetch url does not sign it in.
76
+ const pushurl = 'remote.' + remote + '.pushurl';
77
+ const pushurls = await git.getAllConfig(pushurl);
78
+ const [key, values] = pushurls.length > 0 ? [pushurl, pushurls] : ['remote.' + remote + '.url', await git.getAllConfig('remote.' + remote + '.url')];
79
+ return values.some(carriesSecret) ? { key } : null;
47
80
  }
48
81
  async function repointOf(git, branch) {
49
82
  const unknown = branch ? await unknownDestination(git, branch) : null;
@@ -63,10 +96,48 @@ async function destinationOf(git, target) {
63
96
  const allowed = (await git.getAllConfig('repown.allowOwner', 'local')).map((value) => value.toLowerCase());
64
97
  return { remote: target.isRemote ? target.name : null, owner, allowed };
65
98
  }
99
+ async function laterUrlsOf(git, target) {
100
+ if (!target?.isRemote)
101
+ return null;
102
+ const urls = [...new Set(await pushUrlsOf(git, target.name))];
103
+ if (urls.length < 2)
104
+ return null;
105
+ const owners = urls.slice(1).flatMap((raw) => {
106
+ const url = parseGitUrl(raw);
107
+ const provider = providerFor(url);
108
+ const owner = url ? provider.ownerOf(url) : null;
109
+ return owner ? [{ owner, host: provider.label }] : [];
110
+ });
111
+ const allowed = (await git.getAllConfig('repown.allowOwner', 'local')).map((value) => value.toLowerCase());
112
+ return { remote: target.name, owners, allowed };
113
+ }
114
+ /** Every URL git pushes `remote` with; a git that cannot list them gets the configured values. */
115
+ async function pushUrlsOf(git, remote) {
116
+ const listed = await git.remoteUrls(remote, true);
117
+ if (listed.ok)
118
+ return listed.value;
119
+ const pushurls = await git.getAllConfig('remote.' + remote + '.pushurl');
120
+ return pushurls.length > 0 ? pushurls : git.getAllConfig('remote.' + remote + '.url');
121
+ }
66
122
  function pushUrlOf(git, remote) {
67
123
  return git.remotePushUrl(remote);
68
124
  }
69
- /** A push straight to a URL, as git rewrites it (insteadOf; see rewrittenUrl). */
125
+ /**
126
+ * A push straight to a URL that a pushInsteadOf value prefixes (an empty or missing one
127
+ * matches all). No offline git command resolves pushInsteadOf for a bare URL, and git's
128
+ * rules (first-read ties, empty values) were measured as too many to copy, so repown says it
129
+ * can't tell; a failed read can't either. A `remote."<URL>"` section needs nothing here: it
130
+ * makes the URL a remote, whose push URL git itself resolves.
131
+ */
132
+ async function rewritableOf(git, target) {
133
+ if (!target || target.isRemote)
134
+ return null;
135
+ const url = target.name;
136
+ const rules = await git.configValues('^url\\..*\\.pushinsteadof$');
137
+ const ruled = !rules.ok || rules.value.some((value) => value === null || url.startsWith(value));
138
+ return ruled ? { key: target.key ?? 'its push URL' } : null;
139
+ }
140
+ /** A push straight to a URL after insteadOf (see rewrittenUrl); only when no pushInsteadOf may apply (rewritableOf). */
70
141
  async function bareTargetUrl(git, url) {
71
142
  return (await git.rewrittenUrl(url)) ?? url;
72
143
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "repown",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
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.3",
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.3",
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",