repown 0.5.5 → 0.6.0

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.6.0] - 2026-11-27
11
+
12
+ ### Added
13
+ - `repown doctor --online` checks the sign-in itself. It runs one dry-run push to origin
14
+ as the clone's account, which sends nothing and skips the pre-push hook. Then it says what
15
+ the host answered, and the fix: a token that was rejected (expired, revoked or wrong) gets the
16
+ Git Credential Manager command to sign in again; an organisation that enforces SAML SSO gets
17
+ the approval link GitHub sent; a sign-in as the wrong account, or an account that can't see
18
+ the repository, is named. Without the flag, doctor stays offline.
19
+
10
20
  ## [0.5.5] - 2026-11-27
11
21
 
12
22
  ### Fixed
@@ -344,7 +354,8 @@ and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
344
354
  contract for scripts.
345
355
  - Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
346
356
 
347
- [Unreleased]: https://github.com/makubexD/repown/compare/v0.5.5...HEAD
357
+ [Unreleased]: https://github.com/makubexD/repown/compare/v0.6.0...HEAD
358
+ [0.6.0]: https://github.com/makubexD/repown/compare/v0.5.5...v0.6.0
348
359
  [0.5.5]: https://github.com/makubexD/repown/compare/v0.5.4...v0.5.5
349
360
  [0.5.4]: https://github.com/makubexD/repown/compare/v0.5.3...v0.5.4
350
361
  [0.5.3]: https://github.com/makubexD/repown/compare/v0.5.2...v0.5.3
package/README.md CHANGED
@@ -213,7 +213,7 @@ then commit and push.
213
213
 
214
214
  | When | Command | What it does |
215
215
  | --- | --- | --- |
216
- | Once per machine | `repown doctor` | what serves credentials on this machine, and whether each account is signed in to git and gh |
216
+ | Once per machine | `repown doctor [--online]` | what serves credentials on this machine, and whether each account is signed in to git and gh. 🌐 `--online` also asks origin, with a dry-run push that sends nothing, whether it accepts this clone's sign-in, and prints the fix when it doesn't |
217
217
  | | `repown fix [--dry-run] [--yes]` | undo `gh auth setup-git`, so each clone's pinned account is used; shows what it removes, and the undo, first |
218
218
  | Once per clone | `repown setup [<account>]` | guided setup of this clone. Questions, flags and the review: [Quick start](#quick-start). A clone that is already set up opens on that screen |
219
219
  | | `repown use <account> [--gh]` | what setup runs: pin this clone to an account. `--gh` switches gh's active account, or signs the account in to gh when needed (in a terminal). `--name` with `--email` skips the registry, the file where repown remembers accounts |
@@ -296,6 +296,7 @@ Every `setup` case: [Scripts and CI](docs/CONFIGURATION.md#scripts-and-ci).
296
296
  | `repown doctor` shows `helper` … `none configured` | `git credential-manager configure`, then `repown doctor` again |
297
297
  | A push asked for a password | `repown status` (this clone) or `repown doctor` (this machine): each names the cause (gh as the helper, or no helper) and the fix |
298
298
  | A push failed right after signing in (SSO) | [card 6](docs/HOW-IT-WORKS.md#6-commit-and-first-push) |
299
+ | A pinned clone still can't push or pull ("Invalid username or token", "SAML SSO", 403, 404) | `repown doctor --online`: it says whether the token was rejected, needs SSO approval, or belongs to the wrong account, and prints the command or link that fixes it |
299
300
  | The guard refused a push | it says which commit and the fix. Most often a commit made before pinning: `git commit --amend --reset-author --no-edit` fixes the last one ([card 8](docs/HOW-IT-WORKS.md#8-push-refused-and-the-fix) for older ones, and every other refusal) |
300
301
  | `gh pr create` acts as the wrong account | `gh auth switch -u <account>` when gh lists it, otherwise `repown use <account> --gh` |
301
302
  | `git push` says the branch has no upstream | `repown setup --auto-upstream`, or once `git push -u origin <branch>` |
@@ -0,0 +1,66 @@
1
+ // `repown doctor --online`: ask origin, once, whether it accepts this clone's sign-in for a
2
+ // push (ADR-031). Opt-in, never in the push path (ADR-004): without the flag doctor stays
3
+ // offline.
4
+ import { pinsCredential } from '../core/inspect.js';
5
+ import { isGcm } from '../core/credential/gcm.js';
6
+ import { classifySignIn, describeSignIn } from '../core/signin-check.js';
7
+ import { parseGitUrl } from '../core/url.js';
8
+ import * as out from '../ui/format.js';
9
+ /** Prints the verdict and returns its level; nothing to ask with is a warning, never a pass. */
10
+ export async function checkOnline(repo, pinned) {
11
+ out.heading('This clone, asked online');
12
+ const blocked = await nothingToAsk(repo);
13
+ if (blocked) {
14
+ out.warn('sign-in', blocked);
15
+ return 'warn';
16
+ }
17
+ const verdict = ownLink(classifySignIn(await repo.git.signInProbe('origin')), httpsUrl(repo));
18
+ return printed(describeSignIn(verdict, { account: sentAccount(repo), pinned, gcm: isGcm(repo.helper), github: onGithubCom(repo) }));
19
+ }
20
+ /** The username git sends: the pinned credential username, only where repown pins one over HTTPS. */
21
+ function sentAccount(repo) {
22
+ return pinsCredential(repo) && httpsUrl(repo) ? repo.identity.account : null;
23
+ }
24
+ function httpsUrl(repo) {
25
+ const url = repo.credentialUrl ? parseGitUrl(repo.credentialUrl) : null;
26
+ return url?.scheme === 'https' ? url : null;
27
+ }
28
+ /** The SSO link comes from the remote: shown only when it points at origin's own host. */
29
+ function ownLink(verdict, origin) {
30
+ if (verdict.kind !== 'sso' || !verdict.link)
31
+ return verdict;
32
+ const host = URL.canParse(verdict.link) ? new URL(verdict.link).hostname.toLowerCase() : null;
33
+ return host !== null && host === origin?.host.toLowerCase() ? verdict : { kind: 'sso', link: null };
34
+ }
35
+ /** Why there is no push to try, or null when there is one. */
36
+ async function nothingToAsk(repo) {
37
+ if (!repo.isRepo || repo.originUrl === null)
38
+ return 'not checked: --online asks origin, and there is no clone with an origin here.';
39
+ if (await repo.git.revParse('HEAD') === null)
40
+ return 'not checked: there is no commit to try a push with yet. Commit once, then: repown doctor --online';
41
+ return null;
42
+ }
43
+ /** GCM's `github login` was measured on github.com only (ADR-009). */
44
+ function onGithubCom(repo) {
45
+ return httpsUrl(repo)?.host.toLowerCase() === 'github.com';
46
+ }
47
+ function printed(report) {
48
+ const message = out.printable(report.message);
49
+ if (report.level === 'pass')
50
+ out.pass('sign-in', message);
51
+ else if (report.level === 'fail')
52
+ out.fail('sign-in', message);
53
+ else
54
+ out.warn('sign-in', message);
55
+ for (const line of report.fix)
56
+ out.detail(out.printable(line));
57
+ return report.level;
58
+ }
59
+ /** The closing line, with what the online check found added to the offline verdict. */
60
+ export function closingWithOnline(verdict, code, level) {
61
+ if (level === 'fail')
62
+ return code === 0 ? '1 problem: origin refused the sign-in (above)' : verdict + ' · and origin refused the sign-in';
63
+ if (level === 'warn')
64
+ return verdict + ' · sign-in not checked online';
65
+ return verdict + ' · origin accepts the sign-in';
66
+ }
@@ -15,7 +15,8 @@
15
15
  // accountRows decides the cells. A failed lookup stays `unknown`.
16
16
  import { inspectRepo, inspectAuth, activeAccountLabel, pinsCredential } from '../core/inspect.js';
17
17
  import { loadRegistry } from '../core/registry.js';
18
- import { gitFor } from '../ui/args.js';
18
+ import { flagBool, gitFor } from '../ui/args.js';
19
+ import { checkOnline, closingWithOnline } from './doctor-online.js';
19
20
  import { snapshotOf } from '../core/config-snapshot.js';
20
21
  import { parseGitUrl } from '../core/url.js';
21
22
  import * as out from '../ui/format.js';
@@ -31,7 +32,10 @@ const MACHINE = 'This machine';
31
32
  const MACHINE_FOR_GITHUB = 'This machine, for github.com';
32
33
  export default {
33
34
  summary: 'what serves credentials on this machine, and to whom',
34
- examples: ['repown doctor'],
35
+ options: [
36
+ { name: 'online', kind: 'boolean', help: 'also ask origin, with a dry-run push that sends nothing, whether it accepts this clone\'s sign-in (uses the network)' },
37
+ ],
38
+ examples: ['repown doctor', 'repown doctor --online'],
35
39
  async run(args) {
36
40
  // Read-only: config reads come from one list per scope (ADR-029).
37
41
  const git = snapshotOf(gitFor(args));
@@ -39,8 +43,13 @@ export default {
39
43
  const auth = await inspectAuth(git, probeUrl(repo));
40
44
  const warned = printReport(repo, auth, await loadRegistry());
41
45
  const found = diagnose(auth, ssoHost(repo));
42
- closeDoctor(scoped(repo, found) + warningTally(warned));
43
- return found.code;
46
+ if (!flagBool(args, 'online')) {
47
+ closeDoctor(scoped(repo, found) + warningTally(warned));
48
+ return found.code;
49
+ }
50
+ const level = await checkOnline(repo, pinnedOf(repo));
51
+ closeDoctor(closingWithOnline(scoped(repo, found), found.code, level) + warningTally(warned));
52
+ return level === 'fail' ? 1 : found.code;
44
53
  },
45
54
  };
46
55
  export function accountRows(registry, auth, pinned) {
package/dist/core/git.js CHANGED
@@ -19,6 +19,7 @@ import { tmpdir } from 'node:os';
19
19
  import { randomUUID } from 'node:crypto';
20
20
  import { run, succeeded, output, lines } from './exec.js';
21
21
  import { ok, err } from './result.js';
22
+ import { positional } from './shell.js';
22
23
  export class Git {
23
24
  cwd;
24
25
  constructor(cwd = process.cwd()) {
@@ -296,6 +297,16 @@ export class Git {
296
297
  const fetched = await this.execLong([...QUIET, 'fetch', '--quiet', '--no-recurse-submodules', '--', remote], await this.quietEnvHere(), NETWORK_MS);
297
298
  return succeeded(fetched) ? ok(undefined) : err(networkReason(fetched));
298
299
  }
300
+ /**
301
+ * A dry-run push of HEAD to a branch nobody has (network, prompts off, no pre-push hook): it
302
+ * signs in as a push would and sends nothing. git's raw answer, for classifySignIn (ADR-031).
303
+ * `--no-recurse-submodules` overrides push.recurseSubmodules: on-demand would run each
304
+ * submodule's own push, and its hook, which --no-verify doesn't reach.
305
+ */
306
+ async signInProbe(remote) {
307
+ const push = ['push', '--dry-run', '--no-verify', '--no-recurse-submodules', '--porcelain', ...positional(remote), 'HEAD:refs/heads/repown-sign-in-check'];
308
+ return this.execLong([...QUIET, ...push], await this.quietEnvHere(), NETWORK_MS);
309
+ }
299
310
  /** How many branches the remote lists (network, prompts off). */
300
311
  async remoteHeadCount(remote) {
301
312
  const listed = await this.execLong([...QUIET, 'ls-remote', '--heads', '--', remote], await this.quietEnvHere(), NETWORK_MS);
@@ -0,0 +1,59 @@
1
+ // What origin says to a dry-run push, as the clone's pinned account (ADR-031).
2
+ //
3
+ // A read is no check: github.com answers `ls-remote` of a public repository without asking for
4
+ // the credential at all, so a revoked token reads as fine (measured). The push endpoint always
5
+ // asks. `git push --dry-run` stops after the ref advertisement and sends nothing.
6
+ //
7
+ // The WHOLE stderr is read: the SSO refusal's fix is the `visit <url>` line git prints before
8
+ // its last one.
9
+ import { succeeded } from './exec.js';
10
+ import { networkReason } from './git.js';
11
+ import { copyableCommand } from './shell.js';
12
+ /** First match wins: SSO's 403 also reads as "unable to access", so it goes first. */
13
+ const PATTERNS = [
14
+ [/SAML SSO/, (stderr) => ({ kind: 'sso', link: /visit (https:\/\/\S+)/.exec(stderr)?.[1] ?? null })],
15
+ [/Permission to \S+ denied to /, (stderr) => ({ kind: 'denied', as: /denied to ([^\s.]+)/.exec(stderr)?.[1] ?? '' })],
16
+ [/Invalid username or token|Authentication failed/, () => ({ kind: 'rejected' })],
17
+ [/Repository not found/, () => ({ kind: 'not-found' })],
18
+ [/unable to get password|Cannot prompt because user interactivity has been disabled|could not read Username|terminal prompts disabled/, () => ({ kind: 'no-sign-in' })],
19
+ ];
20
+ export function classifySignIn(result) {
21
+ if (succeeded(result))
22
+ return { kind: 'ok' };
23
+ if (result.timedOut)
24
+ return { kind: 'unchecked', reason: 'timed out' };
25
+ const found = PATTERNS.find(([pattern]) => pattern.test(result.stderr));
26
+ return found ? found[1](result.stderr) : { kind: 'unchecked', reason: networkReason(result) };
27
+ }
28
+ export function describeSignIn(verdict, ctx) {
29
+ const whose = ctx.account ? ctx.account + '\'s sign-in' : 'this clone\'s sign-in';
30
+ switch (verdict.kind) {
31
+ case 'ok': return { level: 'pass', message: (ctx.account ? 'origin accepts ' + whose + ' for a push' : 'origin accepts a push from this clone') + ' (a dry run: nothing was sent)', fix: [] };
32
+ case 'sso': return { level: 'fail', message: 'origin refused ' + whose + ': the organisation enforces SAML SSO, and this sign-in isn\'t authorised for it.', fix: ssoFix(verdict.link) };
33
+ case 'rejected': return { level: 'fail', message: 'the host rejected ' + whose + ': the token or password git holds was expired, revoked or wrong.', fix: loginFix(ctx) };
34
+ case 'denied': return denied(verdict.as, ctx);
35
+ case 'not-found': return { level: 'fail', message: 'origin was not found with ' + whose + ': that account can\'t see it (the wrong account, or no access).', fix: ['check the account (repown status), or ask for access'] };
36
+ case 'no-sign-in': return { level: 'fail', message: 'no sign-in is stored' + (ctx.account ? ' for ' + ctx.account : '') + ', so a push would ask for one.', fix: loginFix(ctx) };
37
+ case 'unchecked': return { level: 'warn', message: 'couldn\'t check the sign-in: ' + verdict.reason, fix: [] };
38
+ }
39
+ }
40
+ function ssoFix(link) {
41
+ const then = 'then: repown doctor --online';
42
+ return link ? ['authorise it: ' + link, then] : ['authorise this sign-in in the organisation\'s SSO settings', then];
43
+ }
44
+ /** GCM's own sign-in, only where it was measured, and only when the account quotes safely. */
45
+ function loginFix(ctx) {
46
+ if (!ctx.gcm || !ctx.github || !ctx.account)
47
+ return [];
48
+ const command = copyableCommand(['git', 'credential-manager', 'github', 'login', '--username', ctx.account, '--browser', '--force']);
49
+ return command ? ['sign in again: ' + command] : [];
50
+ }
51
+ /** Signed in as someone who can't push: the pinned account when it differs, else write access. */
52
+ function denied(as, ctx) {
53
+ const pinned = ctx.pinned;
54
+ if (!pinned || !as || as.toLowerCase() === pinned.toLowerCase()) {
55
+ return { level: 'fail', message: 'origin refused the push: ' + (as || 'this sign-in') + ' can\'t push here; ask for write access.', fix: [] };
56
+ }
57
+ const command = copyableCommand(['repown', 'use', pinned]);
58
+ return { level: 'fail', message: 'origin refused the push: git signed in as ' + as + ', not ' + pinned + ', and ' + as + ' can\'t push here.', fix: command ? ['use the pinned account: ' + command] : [] };
59
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "repown",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "repown",
9
- "version": "0.5.5",
9
+ "version": "0.6.0",
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.5",
3
+ "version": "0.6.0",
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",