repown 0.6.0 → 0.7.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 +66 -4
- package/README.md +57 -33
- package/dist/commands/doctor-online.js +75 -33
- package/dist/commands/doctor.js +29 -5
- package/dist/commands/signin-guide.js +43 -0
- package/dist/commands/signin-terminal.js +25 -0
- package/dist/commands/use.js +1 -1
- package/dist/core/blockers.js +22 -0
- package/dist/core/credential/gcm.js +11 -1
- package/dist/core/exec.js +3 -2
- package/dist/core/guard/check.js +3 -1
- package/dist/core/push-state.js +32 -4
- package/dist/core/signin-check.js +67 -16
- package/dist/core/signin-repair.js +53 -0
- package/dist/ui/help.js +1 -1
- package/dist/ui/prompt.js +25 -5
- package/dist/wizard/setup-run.js +65 -19
- package/dist/wizard/setup-signin.js +55 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,58 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.1] - 2026-11-29
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `docs/TROUBLESHOOTING.md` lists every message repown and git print, with its fix.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- The guard's refusal of commits by another address now ends with the fix:
|
|
17
|
+
`repown reauthor`, which rewrites that branch's unpushed commits as the pinned account,
|
|
18
|
+
asks first, and never pushes.
|
|
19
|
+
- `repown use`, when no credential is stored yet, points at `repown doctor --online` to
|
|
20
|
+
check the sign-in (it pointed at `repown doctor`, which can't check it).
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- Done on an already set-up clone offered the online sign-in check even when something
|
|
24
|
+
would stop the next push. It now says `sign-in not checked online: the next push will
|
|
25
|
+
fail: …` instead, as after a run.
|
|
26
|
+
- Where the push URL names a user other than the pinned account, a rejected or missing
|
|
27
|
+
sign-in suggested a Git Credential Manager sign-in as that user. It now says the URL
|
|
28
|
+
names that user, and to remove it.
|
|
29
|
+
- With no credential helper at all, `repown doctor` said it couldn't tell whether
|
|
30
|
+
"nothing" honours the per-clone pin. It now says no helper serves github.com, and how to
|
|
31
|
+
set up Git Credential Manager.
|
|
32
|
+
|
|
33
|
+
## [0.7.0] - 2026-11-28
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
- repown now guides the sign-in until the remote accepts it. In a terminal, when
|
|
37
|
+
`repown doctor --online` finds a refusal, it offers the matching fix, runs it on a yes,
|
|
38
|
+
and checks again: Git Credential Manager's github.com sign-in (your browser opens),
|
|
39
|
+
`repown fix` when gh is the helper (it shows what it removes and asks first), pinning the
|
|
40
|
+
account again, or, for SAML SSO, waiting while you approve the page. Without a terminal it
|
|
41
|
+
prints the verdict and the fix, as before.
|
|
42
|
+
- `repown setup` ends by asking to check the sign-in online (one dry-run push, nothing sent),
|
|
43
|
+
with the same guided repair. Its closing line says `done` with `· origin accepts the
|
|
44
|
+
sign-in` only on a pass, and says what is left otherwise. Never asked under `--no-input`.
|
|
45
|
+
- `doctor --online` names an SSH key the host refused, a host key ssh doesn't trust yet, and
|
|
46
|
+
a deploy key without write access, each with its fix.
|
|
47
|
+
|
|
48
|
+
### Changed
|
|
49
|
+
- `repown doctor --online` exits 3 when the check couldn't run (offline, no commit, no
|
|
50
|
+
remote), so a script never reads a skipped check as a pass.
|
|
51
|
+
- `doctor --online` asks the remote a plain `git push` uses, and describes that remote's
|
|
52
|
+
push URL: its account, helper and SSO link.
|
|
53
|
+
- A failed check always names a next step, by credential helper.
|
|
54
|
+
|
|
55
|
+
### Fixed
|
|
56
|
+
- A username in the push URL (`https://octo-work@github.com/…`) other than the pinned
|
|
57
|
+
account was reported as ready, though git signs in as that user. `repown status` and setup
|
|
58
|
+
now report it as blocking the next push, with the `git remote set-url` command that
|
|
59
|
+
removes it.
|
|
60
|
+
- A remote that refused only the pushed ref, after signing in, read as a failed sign-in.
|
|
61
|
+
|
|
10
62
|
## [0.6.0] - 2026-11-27
|
|
11
63
|
|
|
12
64
|
### Added
|
|
@@ -249,9 +301,17 @@ and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
|
|
|
249
301
|
remote, they say so, say how to fetch and count again where there is a remote to fetch,
|
|
250
302
|
and offer the rebase only for when the destination has none of those commits. The URL
|
|
251
303
|
is never printed (ADR-025).
|
|
252
|
-
- `repown setup` no longer says `done` when the next push would fail. It names what is in
|
|
253
|
-
|
|
254
|
-
|
|
304
|
+
- `repown setup` no longer says `done` when the next push would fail. It names what is in
|
|
305
|
+
the way, first among the review's notes, on the already-set-up screen, and in its closing
|
|
306
|
+
line (`set up for <account>; the next push will fail: …`): commits the guard will refuse,
|
|
307
|
+
a sign-in in the push URL, identity or token variables, `author.email` in config, a
|
|
308
|
+
destination owner, a diverged branch, a missing upstream, a detached HEAD (ADR-026).
|
|
309
|
+
- With the guard off, setup and status still name commits by another address, a
|
|
310
|
+
destination owner and `GH_TOKEN`, but as a warning (`the guard is off, so …`): they no
|
|
311
|
+
longer stop `done` or `ready` (ADR-026).
|
|
312
|
+
- `repown status` no longer says `ready` when the next push would fail. It prints what is
|
|
313
|
+
in the way first among its warnings (`WARN push`), and ends `the next push will fail: …`;
|
|
314
|
+
the exit code is unchanged (ADR-026).
|
|
255
315
|
- The re-author advice says `or pin that address` only when one address made them all.
|
|
256
316
|
- The suggested `git rebase` starts at the parent of the oldest commit by another address,
|
|
257
317
|
not the oldest unpushed one, so your own commits before it are never rewritten.
|
|
@@ -354,7 +414,9 @@ and cmd. `status`, `doctor` and the pre-push guard are faster on Windows.
|
|
|
354
414
|
contract for scripts.
|
|
355
415
|
- Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
|
|
356
416
|
|
|
357
|
-
[Unreleased]: https://github.com/makubexD/repown/compare/v0.
|
|
417
|
+
[Unreleased]: https://github.com/makubexD/repown/compare/v0.7.1...HEAD
|
|
418
|
+
[0.7.1]: https://github.com/makubexD/repown/compare/v0.7.0...v0.7.1
|
|
419
|
+
[0.7.0]: https://github.com/makubexD/repown/compare/v0.6.0...v0.7.0
|
|
358
420
|
[0.6.0]: https://github.com/makubexD/repown/compare/v0.5.5...v0.6.0
|
|
359
421
|
[0.5.5]: https://github.com/makubexD/repown/compare/v0.5.4...v0.5.5
|
|
360
422
|
[0.5.4]: https://github.com/makubexD/repown/compare/v0.5.3...v0.5.4
|
package/README.md
CHANGED
|
@@ -96,9 +96,19 @@ cd ~/code/my-repo
|
|
|
96
96
|
repown # in a terminal: starts the guided setup of this clone
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
+
> 👤 **Only one account?** repown still helps: it pins each clone, so a global identity that
|
|
100
|
+
> changes (an IDE, a CI script, a work email set machine-wide) can't leak into its commits;
|
|
101
|
+
> the guard checks every push; and `repown doctor --online` checks the sign-in. You need
|
|
102
|
+
> only `repown doctor` once and `repown` in each clone.
|
|
103
|
+
|
|
99
104
|
1. **`repown doctor`, once per machine.** It ends with a verdict:
|
|
100
105
|
- 🟢 `ready: each clone signs in as its own account through Git Credential Manager`
|
|
106
|
+
- 🟢 `ready · no accounts stored yet: the first push signs in once`
|
|
101
107
|
- 🔴 `1 problem: gh answers git's sign-in requests: run repown fix`
|
|
108
|
+
- 🟡 `unchecked: repown can't tell whether <helper> honours the per-clone pin` (often
|
|
109
|
+
macOS's `osxkeychain`: install GCM, then `git credential-manager configure`)
|
|
110
|
+
- 🟡 `unchecked: no credential helper serves github.com: git credential-manager configure`
|
|
111
|
+
(often Linux: install GCM first)
|
|
102
112
|
|
|
103
113
|
If gh is the helper, or something is missing, see [Troubleshooting](#troubleshooting).
|
|
104
114
|
2. **Clone as usual,** then from inside a new clone just type **`repown`.** That starts
|
|
@@ -106,20 +116,22 @@ repown # in a terminal: starts the guided setup of this clone
|
|
|
106
116
|
in first: pick the account that owns it.) It asks how setup should work. Recommended is
|
|
107
117
|
the default. Answers it fills in still appear in the review.
|
|
108
118
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
| Let this clone push to origin's owner
|
|
115
|
-
| Turn the guard on? |
|
|
116
|
-
|
|
|
117
|
-
|
|
|
118
|
-
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
`--no-input` asks nothing
|
|
119
|
+
Only the questions that apply to this clone are asked:
|
|
120
|
+
|
|
121
|
+
| Question | Recommended | Flag |
|
|
122
|
+
| --- | --- | --- |
|
|
123
|
+
| Which account should this clone belong to? (a new one also asks host, name, email) | Asked | `<account>`, `--host`, `--name`, `--email` |
|
|
124
|
+
| Let this clone push to origin's owner, such as an organisation? | Asked, default Yes | `--allow-owner <owner>` |
|
|
125
|
+
| Turn the guard on? · Push branches without `-u`? (git 2.37+) · Push through the remote instead of a URL? · Fetch the remote first? | Yes, without asking | `--guard`, `--auto-upstream`, `--repoint`, `--fetch` |
|
|
126
|
+
| Switch gh too, so `gh pr create` matches? | Yes without asking when gh lists the account and the clone isn't already pinned to it; a gh sign-in (a browser) is asked, default No | `--gh` |
|
|
127
|
+
| Take git's sign-ins back from gh? (machine-wide: answer Yes if `repown doctor` said gh is the helper) | Asked, default No | `--fix` |
|
|
128
|
+
| Re-author your unpushed commits by another address? (only if you made them; runs last, as `repown reauthor --yes`) | Asked, default No | `--reauthor` |
|
|
129
|
+
|
|
130
|
+
`repown setup <account>` skips the mode question and uses Recommended, so a recorded
|
|
131
|
+
account goes straight to the review when nothing else must be asked. Step by step asks
|
|
132
|
+
every question: `--step-by-step`. `--no-input` asks nothing
|
|
133
|
+
([scripts and CI](docs/CONFIGURATION.md#scripts-and-ci)). When each one is asked, and its
|
|
134
|
+
default: [card 13](docs/HOW-IT-WORKS.md#13-guided-setup).
|
|
123
135
|
|
|
124
136
|
- **In your first clone,** it lists the accounts it can already see on GitHub (origin's
|
|
125
137
|
owner, gh's accounts, Git Credential Manager's) and suggests origin's owner when that
|
|
@@ -158,8 +170,17 @@ repown # in a terminal: starts the guided setup of this clone
|
|
|
158
170
|
└
|
|
159
171
|
```
|
|
160
172
|
|
|
161
|
-
|
|
162
|
-
|
|
173
|
+
🌐 Once the steps have run and nothing blocks the next push, setup asks one more
|
|
174
|
+
question: **Check the sign-in with the remote now?** Yes (the default) runs one dry-run
|
|
175
|
+
push that sends nothing. If the remote refuses, setup says why and offers the fix: sign in
|
|
176
|
+
again through Git Credential Manager, undo gh's helper, approve the SSO page in your
|
|
177
|
+
browser (setup waits), or pin the account again. Then it checks again. Setup says
|
|
178
|
+
`done … · origin accepts the sign-in` only when it passes
|
|
179
|
+
([card 13](docs/HOW-IT-WORKS.md#13-guided-setup)).
|
|
180
|
+
|
|
181
|
+
4. **Push.** The first push from each account signs in once (unless you accepted the
|
|
182
|
+
sign-in that setup's check offered): GCM opens a browser, and you sign in as *that* clone's account,
|
|
183
|
+
not whichever you used last. After that, pushes from
|
|
163
184
|
that clone use it without asking. When setup set `push.autoSetupRemote`, the first
|
|
164
185
|
`git push` of a branch without an upstream also creates it on origin. When it did not
|
|
165
186
|
(older git, a version repown could not read, or you answered No), use
|
|
@@ -196,8 +217,10 @@ with no account and no flags, and setup opens on this screen, before any questio
|
|
|
196
217
|
└
|
|
197
218
|
```
|
|
198
219
|
|
|
199
|
-
**Done** changes nothing
|
|
200
|
-
|
|
220
|
+
**Done** changes nothing, then, when nothing blocks the next push, offers the same sign-in
|
|
221
|
+
check as after a run (otherwise it says
|
|
222
|
+
`sign-in not checked online: the next push will fail: …`). **Use another account** asks
|
|
223
|
+
which account this clone should use. When gh acts as someone else, a third option is **Sign in to gh as `<account>`** (or
|
|
201
224
|
**Make `<account>` gh's active account** when gh already lists it) and runs
|
|
202
225
|
`repown use <account> --gh`. With unpushed commits by another address, **Re-author them**
|
|
203
226
|
is offered too (`repown reauthor --yes`). The upstream line shows the tracked branch (for example
|
|
@@ -213,7 +236,7 @@ then commit and push.
|
|
|
213
236
|
|
|
214
237
|
| When | Command | What it does |
|
|
215
238
|
| --- | --- | --- |
|
|
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
|
|
239
|
+
| 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. When it doesn't, it says why and the fix; in a terminal it offers to run that fix (waiting while you approve an SSO page), then checks again |
|
|
217
240
|
| | `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
241
|
| 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
242
|
| | `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 |
|
|
@@ -282,30 +305,29 @@ note, not a warning. Every warning it can print:
|
|
|
282
305
|
| --- | --- | --- | --- | --- |
|
|
283
306
|
| In general | Success | Failure or refusal | Usage error | 130 when setup or the start screen is cancelled |
|
|
284
307
|
| `repown scan` | Whatever it finds (read its output or JSON) | | A missing folder or a bad `--depth` | |
|
|
285
|
-
| `repown setup` | Done, or already set up | Decline, or it can't start | Flags that don't fit, or no terminal without `--no-input` | 130 when cancelled or interrupted; a failing step's own code |
|
|
308
|
+
| `repown setup` | Done, or already set up. A sign-in the last step found refused is said in the closing line, not the exit code | Decline, or it can't start | Flags that don't fit, or no terminal without `--no-input` | 130 when cancelled or interrupted; a failing step's own code |
|
|
286
309
|
| `repown status` | Success. Warnings alone exit 0 | A problem | | |
|
|
310
|
+
| `repown doctor --online` | Ready, and the remote accepts the sign-in | A problem, or the remote refused the sign-in | | 3 when the sign-in wasn't confirmed: no network, a timeout, no commit, no remote, or an answer repown can't classify (the `WARN` shows git's reason). 1 instead if the offline checks already failed |
|
|
287
311
|
|
|
288
312
|
Every `setup` case: [Scripts and CI](docs/CONFIGURATION.md#scripts-and-ci).
|
|
289
313
|
|
|
290
314
|
## Troubleshooting
|
|
291
315
|
|
|
316
|
+
Start with `repown` in the clone, `repown doctor`, then `repown doctor --online`. The most
|
|
317
|
+
common cases:
|
|
318
|
+
|
|
292
319
|
| What happened | What to do |
|
|
293
320
|
| --- | --- |
|
|
294
321
|
| `repown doctor` says gh is the helper | `repown fix` ([card 1](docs/HOW-IT-WORKS.md#1-set-up-the-machine)) |
|
|
295
|
-
| `repown doctor` shows `GCM` … `not found` | install Git Credential Manager ([Install](#install)), then `repown doctor` again |
|
|
296
|
-
| `repown doctor` shows `helper` … `none configured` | `git credential-manager configure`, then `repown doctor` again |
|
|
297
322
|
| 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
|
-
| A push
|
|
299
|
-
|
|
|
300
|
-
| The guard
|
|
323
|
+
| A pinned clone still can't push or pull ("Invalid username or token", "SAML SSO", 403, 404) | `repown doctor --online`: it tells a rejected or missing token, an SSO approval, the wrong account, a repository that account can't see, and an SSH key, host key or deploy key problem apart, with the command or link that fixes it. In a terminal it offers to run the fix, then checks again |
|
|
324
|
+
| The guard refused a push: commits by another address | most often made before pinning: `repown reauthor` (fetches, rewrites only what no remote has, keeps a backup, never pushes); for just the last one, `git commit --amend --reset-author --no-edit`. Every other refusal: [card 8](docs/HOW-IT-WORKS.md#8-push-refused-and-the-fix) |
|
|
325
|
+
| The guard said the push goes to another owner (on Azure DevOps, the organisation) | if you're a member or collaborator there: `git config --local --add repown.allowOwner <owner>` |
|
|
301
326
|
| `gh pr create` acts as the wrong account | `gh auth switch -u <account>` when gh lists it, otherwise `repown use <account> --gh` |
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
| husky or another tool owns the pre-push hook | have that hook run `repown guard check --remote="$1" --url="$2"`, passing its stdin through; if the hook is committed, make it skip teammates without repown ([card 10](docs/HOW-IT-WORKS.md#10-other-hook-tools)) |
|
|
307
|
-
| An Azure DevOps push is refused as "wrong owner" | the owner there is the organisation: allow it with `git config --local --add repown.allowOwner <organisation>` |
|
|
308
|
-
| "repown cannot be found" on push | [card 12](docs/HOW-IT-WORKS.md#12-uninstall-or-repown-missing) |
|
|
327
|
+
|
|
328
|
+
📖 Everything else, by the exact message you see (doctor's and status's every line, setup's
|
|
329
|
+
closing line, git's own errors, a missing `repown`, the macOS and Linux helpers):
|
|
330
|
+
[docs/TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md).
|
|
309
331
|
|
|
310
332
|
A refused push:
|
|
311
333
|
|
|
@@ -314,6 +336,7 @@ FAIL guard 1 commit(s) bound for refs/heads/main were not authored as octo
|
|
|
314
336
|
6e7b31adb someone@example.invalid someone else's commit
|
|
315
337
|
|
|
316
338
|
These addresses become permanent once pushed.
|
|
339
|
+
fix: repown reauthor (on that branch: rewrites the unpushed ones as the pinned account; asks first, never pushes)
|
|
317
340
|
|
|
318
341
|
|
|
319
342
|
Push stopped by the repown identity guard (above).
|
|
@@ -347,7 +370,7 @@ $ repown use octocat
|
|
|
347
370
|
OK identity Octo Cat <octocat@users.noreply.github.com> push-as:octocat
|
|
348
371
|
|
|
349
372
|
No stored credential for "octocat" yet -- the first push signs in
|
|
350
|
-
once, then never again.
|
|
373
|
+
once, then never again. To sign in and check now: repown doctor --online
|
|
351
374
|
|
|
352
375
|
Next: repown guard on (check every push before it leaves)
|
|
353
376
|
|
|
@@ -383,6 +406,7 @@ want it back: `gh auth setup-git`. Details, and submodules:
|
|
|
383
406
|
| --- | --- |
|
|
384
407
|
| every scenario, with diagrams | [docs/HOW-IT-WORKS.md](docs/HOW-IT-WORKS.md) |
|
|
385
408
|
| environment variables, where accounts are kept, per-clone keys, scripts and JSON | [docs/CONFIGURATION.md](docs/CONFIGURATION.md) |
|
|
409
|
+
| what a message means, and the command that fixes it | [docs/TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md) |
|
|
386
410
|
| short answers, and how repown compares with `includeIf`, SSH aliases and `gh auth switch` | [docs/FAQ.md](docs/FAQ.md) |
|
|
387
411
|
| to contribute, see where each feature lives in the code, or try it on throwaway repositories | [CONTRIBUTING.md](CONTRIBUTING.md) |
|
|
388
412
|
| to report a vulnerability privately | [SECURITY.md](SECURITY.md) |
|
|
@@ -1,49 +1,90 @@
|
|
|
1
|
-
// `repown doctor --online`: ask
|
|
2
|
-
// push (ADR-031). Opt-in, never in the push path (ADR-004):
|
|
3
|
-
// offline.
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// `repown doctor --online`: ask the remote a plain `git push` uses, once, whether it accepts
|
|
2
|
+
// this clone's sign-in for a push (ADR-031). Opt-in, never in the push path (ADR-004):
|
|
3
|
+
// without the flag doctor stays offline.
|
|
4
|
+
//
|
|
5
|
+
// Everything said about the sign-in (account, helper, host, SSO link) describes the URL the
|
|
6
|
+
// probe really pushes to (`remote get-url --push`, after insteadOf and pushInsteadOf), never
|
|
7
|
+
// the fetch URL: an HTTPS fetch with an SSH push signs in with a key, not a token.
|
|
8
|
+
import { inspectRepo, keysOf } from '../core/inspect.js';
|
|
9
|
+
import { carriesSecret } from '../core/push-state.js';
|
|
10
|
+
import { pushTarget } from '../core/push-destination.js';
|
|
6
11
|
import { classifySignIn, describeSignIn } from '../core/signin-check.js';
|
|
7
12
|
import { parseGitUrl } from '../core/url.js';
|
|
8
13
|
import * as out from '../ui/format.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
import { gitFor } from '../ui/args.js';
|
|
15
|
+
import { interactive } from '../ui/prompt.js';
|
|
16
|
+
import { repairFor } from '../core/signin-repair.js';
|
|
17
|
+
import { guideSignIn } from './signin-guide.js';
|
|
18
|
+
import { terminalIo } from './signin-terminal.js';
|
|
19
|
+
/**
|
|
20
|
+
* Asks once; in a terminal, offers each repair and asks again after it. Each round reads the
|
|
21
|
+
* clone afresh, since a repair (fix, use) changes the config the next check depends on.
|
|
22
|
+
*/
|
|
23
|
+
export async function askOnline(args, repo, pinnedOf) {
|
|
24
|
+
if (!interactive())
|
|
25
|
+
return checkOnline(repo, pinnedOf(repo));
|
|
26
|
+
let round = 0;
|
|
27
|
+
const check = async () => {
|
|
28
|
+
const fresh = round === 0 ? repo : await inspectRepo(gitFor(args));
|
|
29
|
+
return checkOnline(fresh, pinnedOf(fresh), round++ === 0);
|
|
30
|
+
};
|
|
31
|
+
return guideSignIn(check, terminalIo(args));
|
|
32
|
+
}
|
|
33
|
+
/** Prints the verdict and returns it with its repair; nothing to ask with is a warning, never a pass. */
|
|
34
|
+
export async function checkOnline(repo, pinned, heading = true) {
|
|
35
|
+
if (heading)
|
|
36
|
+
out.heading('This clone, asked online');
|
|
37
|
+
const target = repo.isRepo ? await targetOf(repo) : null;
|
|
38
|
+
const blocked = await nothingToAsk(repo, target);
|
|
39
|
+
if (blocked || !target) {
|
|
40
|
+
out.warn('sign-in', blocked ?? 'not checked');
|
|
41
|
+
return { level: 'warn', remote: target?.remote ?? 'origin', repair: null };
|
|
16
42
|
}
|
|
17
|
-
|
|
18
|
-
|
|
43
|
+
out.detail('asking ' + target.remote + ' with a dry-run push…');
|
|
44
|
+
const verdict = ownLink(classifySignIn(await repo.git.signInProbe(target.remote)), target.https);
|
|
45
|
+
const ctx = { ...target, pinned, github: target.https?.host.toLowerCase() === 'github.com' };
|
|
46
|
+
const level = printed(describeSignIn(verdict, ctx));
|
|
47
|
+
return { level, remote: target.remote, repair: level === 'fail' ? repairFor(verdict, ctx) : null };
|
|
48
|
+
}
|
|
49
|
+
async function targetOf(repo) {
|
|
50
|
+
const remote = await pushRemote(repo);
|
|
51
|
+
const raw = await repo.git.remotePushUrl(remote);
|
|
52
|
+
const parsed = raw ? parseGitUrl(raw) : null;
|
|
53
|
+
const https = parsed?.scheme === 'https' ? parsed : null;
|
|
54
|
+
const host = parsed?.host || null;
|
|
55
|
+
if (!raw || !https)
|
|
56
|
+
return { remote, raw, https, host, account: null, fromUrl: false, helper: null };
|
|
57
|
+
const [account, helper] = await Promise.all([sentUser(repo.git, raw, https), repo.git.getUrlMatch('credential.helper', raw)]);
|
|
58
|
+
return { remote, raw, https, host, account, fromUrl: !!https.user && account !== null, helper };
|
|
19
59
|
}
|
|
20
|
-
/** The
|
|
21
|
-
function
|
|
22
|
-
|
|
60
|
+
/** The remote a plain push sends HEAD's branch to; origin when that is a URL or can't be read. */
|
|
61
|
+
async function pushRemote(repo) {
|
|
62
|
+
if (repo.branch?.kind !== 'branch')
|
|
63
|
+
return 'origin';
|
|
64
|
+
const target = await pushTarget(repo.git, repo.branch.name);
|
|
65
|
+
return target?.isRemote ? target.name : 'origin';
|
|
23
66
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
67
|
+
/** The username git sends: the URL's own (never a secret), else the pin where repown pins one. */
|
|
68
|
+
async function sentUser(git, raw, url) {
|
|
69
|
+
if (url.user)
|
|
70
|
+
return carriesSecret(raw) ? null : url.user;
|
|
71
|
+
return keysOf(raw).length > 0 ? git.getUrlMatch('credential.username', raw) : null;
|
|
27
72
|
}
|
|
28
|
-
/** The SSO link comes from the remote: shown only when it points at
|
|
29
|
-
function ownLink(verdict,
|
|
73
|
+
/** The SSO link comes from the remote: shown only when it points at the push URL's own host. */
|
|
74
|
+
function ownLink(verdict, url) {
|
|
30
75
|
if (verdict.kind !== 'sso' || !verdict.link)
|
|
31
76
|
return verdict;
|
|
32
77
|
const host = URL.canParse(verdict.link) ? new URL(verdict.link).hostname.toLowerCase() : null;
|
|
33
|
-
return host !== null && host ===
|
|
78
|
+
return host !== null && host === url?.host.toLowerCase() ? verdict : { kind: 'sso', link: null };
|
|
34
79
|
}
|
|
35
80
|
/** Why there is no push to try, or null when there is one. */
|
|
36
|
-
async function nothingToAsk(repo) {
|
|
37
|
-
if (!
|
|
38
|
-
return 'not checked: --online asks
|
|
81
|
+
async function nothingToAsk(repo, target) {
|
|
82
|
+
if (!target || target.raw === null)
|
|
83
|
+
return 'not checked: --online asks the remote a push goes to, and there is no clone with one here.';
|
|
39
84
|
if (await repo.git.revParse('HEAD') === null)
|
|
40
85
|
return 'not checked: there is no commit to try a push with yet. Commit once, then: repown doctor --online';
|
|
41
86
|
return null;
|
|
42
87
|
}
|
|
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
88
|
function printed(report) {
|
|
48
89
|
const message = out.printable(report.message);
|
|
49
90
|
if (report.level === 'pass')
|
|
@@ -57,10 +98,11 @@ function printed(report) {
|
|
|
57
98
|
return report.level;
|
|
58
99
|
}
|
|
59
100
|
/** The closing line, with what the online check found added to the offline verdict. */
|
|
60
|
-
export function closingWithOnline(verdict, code, level) {
|
|
101
|
+
export function closingWithOnline(verdict, code, level, named = 'origin') {
|
|
102
|
+
const remote = out.printable(named);
|
|
61
103
|
if (level === 'fail')
|
|
62
|
-
return code === 0 ? '1 problem:
|
|
104
|
+
return code === 0 ? '1 problem: ' + remote + ' refused the sign-in (above)' : verdict + ' · and ' + remote + ' refused the sign-in';
|
|
63
105
|
if (level === 'warn')
|
|
64
106
|
return verdict + ' · sign-in not checked online';
|
|
65
|
-
return verdict + ' ·
|
|
107
|
+
return verdict + ' · ' + remote + ' accepts the sign-in';
|
|
66
108
|
}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import { inspectRepo, inspectAuth, activeAccountLabel, pinsCredential } from '../core/inspect.js';
|
|
17
17
|
import { loadRegistry } from '../core/registry.js';
|
|
18
18
|
import { flagBool, gitFor } from '../ui/args.js';
|
|
19
|
-
import {
|
|
19
|
+
import { askOnline, closingWithOnline } from './doctor-online.js';
|
|
20
20
|
import { snapshotOf } from '../core/config-snapshot.js';
|
|
21
21
|
import { parseGitUrl } from '../core/url.js';
|
|
22
22
|
import * as out from '../ui/format.js';
|
|
@@ -47,11 +47,27 @@ export default {
|
|
|
47
47
|
closeDoctor(scoped(repo, found) + warningTally(warned));
|
|
48
48
|
return found.code;
|
|
49
49
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const online = await askOnline(args, repo, pinnedOf);
|
|
51
|
+
// A repair changed the machine after the offline report: say so rather than repeat it.
|
|
52
|
+
if (online.repaired) {
|
|
53
|
+
closeDoctor(closingWithOnline(REPAIRED, online.level === 'fail' ? 1 : 0, online.level, online.remote) + warningTally(warned));
|
|
54
|
+
return onlineCode(online.level, 0);
|
|
55
|
+
}
|
|
56
|
+
closeDoctor(closingWithOnline(scoped(repo, found), found.code, online.level, online.remote) + warningTally(warned));
|
|
57
|
+
return onlineCode(online.level, found.code);
|
|
53
58
|
},
|
|
54
59
|
};
|
|
60
|
+
/** The closing line's start once a repair ran: the report above it was read before. */
|
|
61
|
+
export const REPAIRED = 'a repair ran (the report above was read before it; repown doctor shows the state now)';
|
|
62
|
+
/** Exit code: a refusal is 1; a check that couldn't run is 3, never a pass's 0 (ADR-032). */
|
|
63
|
+
export const NOT_CHECKED = 3;
|
|
64
|
+
function onlineCode(level, offline) {
|
|
65
|
+
if (level === 'fail')
|
|
66
|
+
return 1;
|
|
67
|
+
if (offline !== 0)
|
|
68
|
+
return offline;
|
|
69
|
+
return level === 'warn' ? NOT_CHECKED : 0;
|
|
70
|
+
}
|
|
55
71
|
export function accountRows(registry, auth, pinned) {
|
|
56
72
|
const rows = mergeNames(registry, auth).map((item) => toRow(item, auth, pinned));
|
|
57
73
|
return reportOf(rows, registry, auth);
|
|
@@ -358,12 +374,20 @@ function ghHelperFiles(auth) {
|
|
|
358
374
|
out.detail(' ' + file);
|
|
359
375
|
}
|
|
360
376
|
function diagnoseUnknownHelper(auth) {
|
|
361
|
-
|
|
377
|
+
if (!auth.helper)
|
|
378
|
+
return diagnoseNoHelper();
|
|
379
|
+
const helper = out.printable(auth.helper);
|
|
362
380
|
out.warn('helper', 'github.com is served by "' + helper + '", which repown has no opinion about.');
|
|
363
381
|
out.detail('The per-repository pin (credential.<url>.username) only works if');
|
|
364
382
|
out.detail('that helper honours it.');
|
|
365
383
|
return { code: 0, verdict: unchecked(helper) };
|
|
366
384
|
}
|
|
385
|
+
/** Nothing serves github.com, so a push has nothing to sign in with: say so, and the fix. */
|
|
386
|
+
function diagnoseNoHelper() {
|
|
387
|
+
out.warn('helper', 'no credential helper serves github.com, so a push has nothing to sign in with.');
|
|
388
|
+
out.detail('Install Git Credential Manager (Git for Windows includes it), then: git credential-manager configure');
|
|
389
|
+
return { code: 0, verdict: 'unchecked: no credential helper serves github.com: git credential-manager configure' };
|
|
390
|
+
}
|
|
367
391
|
function unchecked(helper) {
|
|
368
392
|
return 'unchecked: repown can\'t tell whether ' + helper + ' honours the per-clone pin';
|
|
369
393
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The guided repair after a failed sign-in check (ADR-032): offer the repair, run it on a yes,
|
|
2
|
+
// check again; an SSO approval waits for Enter instead. Terminal only: the callers decide that,
|
|
3
|
+
// and without one doctor --online prints its advice and stops.
|
|
4
|
+
//
|
|
5
|
+
// The loop can't run forever: every repair but the SSO wait is tried once, a no or a q stops
|
|
6
|
+
// it, and a repair that didn't run stops it without another check.
|
|
7
|
+
import { repairQuestion, triedOnce, SSO_WAIT } from '../core/signin-repair.js';
|
|
8
|
+
export async function guideSignIn(check, io) {
|
|
9
|
+
const tried = new Set();
|
|
10
|
+
let repaired = false;
|
|
11
|
+
let result = await check();
|
|
12
|
+
while (result.level === 'fail' && result.repair) {
|
|
13
|
+
if (!offerable(result.repair, tried)) {
|
|
14
|
+
io.say(UNHELPED);
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
if (!await attempt(result.repair, io))
|
|
18
|
+
break;
|
|
19
|
+
repaired ||= result.repair.kind !== 'sso';
|
|
20
|
+
result = await check();
|
|
21
|
+
}
|
|
22
|
+
return repaired ? { ...result, repaired } : result;
|
|
23
|
+
}
|
|
24
|
+
/** Said when the same repair comes back after it ran: it is not offered again. */
|
|
25
|
+
export const UNHELPED = 'that repair ran, and the remote still refuses the sign-in; repown won\'t offer it again. The advice above is what is left.';
|
|
26
|
+
/** Records the repair as tried; false when it already was. */
|
|
27
|
+
function offerable(repair, tried) {
|
|
28
|
+
const key = triedOnce(repair);
|
|
29
|
+
if (key === null)
|
|
30
|
+
return true;
|
|
31
|
+
if (tried.has(key))
|
|
32
|
+
return false;
|
|
33
|
+
tried.add(key);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
async function attempt(repair, io) {
|
|
37
|
+
if (repair.kind === 'sso')
|
|
38
|
+
return io.waitEnter(SSO_WAIT);
|
|
39
|
+
const question = repairQuestion(repair);
|
|
40
|
+
if (question !== null && !await io.confirm(question))
|
|
41
|
+
return false;
|
|
42
|
+
return io.run(repair);
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// The guided repair in a plain terminal, for `repown doctor --online` (ADR-032): questions
|
|
2
|
+
// through `confirm`, the SSO wait through `waitForEnter`, and each repair through the
|
|
3
|
+
// command that owns it (`repown fix`, `repown use`) or GCM's own sign-in. Never a copy.
|
|
4
|
+
import { flagString } from '../ui/args.js';
|
|
5
|
+
import { confirm, waitForEnter } from '../ui/prompt.js';
|
|
6
|
+
import * as out from '../ui/format.js';
|
|
7
|
+
import { printable } from '../ui/format.js';
|
|
8
|
+
import { gcmGithubLogin } from '../core/credential/gcm.js';
|
|
9
|
+
import fixCommand from './fix.js';
|
|
10
|
+
import useCommand from './use.js';
|
|
11
|
+
export function terminalIo(args) {
|
|
12
|
+
// The user asked for the check, so each repair defaults to Yes; Enter runs it.
|
|
13
|
+
return { confirm: (question) => confirm(printable(question), true), waitEnter: waitForEnter, say: (line) => out.warn('sign-in', line), run: (repair) => runRepair(repair, args) };
|
|
14
|
+
}
|
|
15
|
+
/** Runs a repair as its own command would, in the same directory doctor was asked about. */
|
|
16
|
+
export async function runRepair(repair, args) {
|
|
17
|
+
const cwd = flagString(args, 'cwd');
|
|
18
|
+
const flags = (extra) => new Map([...(cwd ? [['cwd', cwd]] : []), ...extra]);
|
|
19
|
+
// fix previews what it removes, and where, then asks its own question (default No).
|
|
20
|
+
if (repair.kind === 'fix')
|
|
21
|
+
return await fixCommand.run({ positional: [], flags: flags([]) }) === 0;
|
|
22
|
+
if (repair.kind === 'use')
|
|
23
|
+
return await useCommand.run({ positional: [repair.account], flags: flags([]) }) === 0;
|
|
24
|
+
return gcmGithubLogin(repair.account);
|
|
25
|
+
}
|
package/dist/commands/use.js
CHANGED
|
@@ -295,6 +295,6 @@ async function credentialConcern(account, repo) {
|
|
|
295
295
|
else if (auth.gcmPresent && auth.stored.ok && !auth.stored.value.includes(account)) {
|
|
296
296
|
out.line();
|
|
297
297
|
out.line(' No stored credential for "' + account + '" yet -- the first push signs in');
|
|
298
|
-
out.line(' once, then never again.
|
|
298
|
+
out.line(' once, then never again. To sign in and check now: repown doctor --online');
|
|
299
299
|
}
|
|
300
300
|
}
|
package/dist/core/blockers.js
CHANGED
|
@@ -16,6 +16,7 @@ export function blockers(facts, choice) {
|
|
|
16
16
|
...unpushedBlocker(facts.unpushed, choice),
|
|
17
17
|
...elsewhereBlocker(facts.elsewhere, facts.destination, branch, choice),
|
|
18
18
|
...signinBlocker(facts, branch, choice.account),
|
|
19
|
+
...urlUserBlocker(facts.urlUser, branch, choice.account),
|
|
19
20
|
...facts.env.map((name) => envBlocker(name, choice)),
|
|
20
21
|
...facts.configOverrides.map((key) => configBlocker(key, choice.email)),
|
|
21
22
|
...ownerBlocker(facts.destination, branch, choice),
|
|
@@ -56,6 +57,27 @@ function signinBlocker(facts, branch, account) {
|
|
|
56
57
|
blocks: true,
|
|
57
58
|
}];
|
|
58
59
|
}
|
|
60
|
+
/** A username in the push URL outranks the pinned credential username: git signs in as it. */
|
|
61
|
+
function urlUserBlocker(found, branch, account) {
|
|
62
|
+
if (!found || found.user.toLowerCase() === account.toLowerCase())
|
|
63
|
+
return [];
|
|
64
|
+
const holder = found.key ? printable(found.key) : printable(found.remote) + "'s push URL, as git resolves it,";
|
|
65
|
+
const user = printable(found.user);
|
|
66
|
+
return [{
|
|
67
|
+
kind: 'urluser',
|
|
68
|
+
summary: 'the push URL signs in as ' + user,
|
|
69
|
+
lines: [holder + ' names the user ' + user + ', so git signs in as ' + user + ' for pushes from ' + branch + ', not ' + account, urlUserFix(found)],
|
|
70
|
+
blocks: true,
|
|
71
|
+
}];
|
|
72
|
+
}
|
|
73
|
+
function urlUserFix(found) {
|
|
74
|
+
const rule = 'remove the user from the url.<base>.insteadOf or pushInsteadOf rule that adds it (' + (copyableCommand(['git', 'config', '--get-regexp', '^url[.]']) ?? 'git config --list') + ' lists them)';
|
|
75
|
+
if (!found.key || !found.clean)
|
|
76
|
+
return found.key ? 'remove ' + printable(found.user) + '@ from ' + printable(found.key) : rule;
|
|
77
|
+
const push = found.key.endsWith('.pushurl') ? ['--push'] : [];
|
|
78
|
+
const command = copyableCommand(['git', 'remote', 'set-url', ...push, ...positional(found.remote), found.clean]);
|
|
79
|
+
return command ? 'remove it: ' + command : 'remove ' + printable(found.user) + '@ from ' + printable(found.key);
|
|
80
|
+
}
|
|
59
81
|
/** Counted with the guard's own exclusion, so a fork's upstream commits are not missed. */
|
|
60
82
|
function elsewhereBlocker(elsewhere, destination, branch, choice) {
|
|
61
83
|
if (!elsewhere.ok) {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// deliberately rather than rediscovered.
|
|
14
14
|
import { join, dirname } from 'node:path';
|
|
15
15
|
import { existsSync } from 'node:fs';
|
|
16
|
-
import { run, succeeded, lines, notInstalled } from '../exec.js';
|
|
16
|
+
import { run, inherit, succeeded, lines, notInstalled } from '../exec.js';
|
|
17
17
|
import { ok, err } from '../result.js';
|
|
18
18
|
const NAMES = ['git-credential-manager', 'git-credential-manager-core'];
|
|
19
19
|
/** Directories that hold GCM but are not necessarily on PATH. */
|
|
@@ -81,3 +81,13 @@ export async function listAccounts(gcmPath, namespace) {
|
|
|
81
81
|
}
|
|
82
82
|
return ok(lines(result));
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* GCM's own github.com sign-in, with the terminal handed to it (ADR-032): the browser opens,
|
|
86
|
+
* the user signs in, and GCM stores the token. repown sees nothing GCM prints. Measured on
|
|
87
|
+
* GCM 2.6.1, over an account GCM already holds too (ADR-032).
|
|
88
|
+
* Offered only for github.com with GCM as the helper.
|
|
89
|
+
*/
|
|
90
|
+
export async function gcmGithubLogin(account, runner = inherit) {
|
|
91
|
+
const result = await runner('git', ['credential-manager', 'github', 'login', '--username', account, '--browser', '--force']);
|
|
92
|
+
return result.code === 0 && !result.spawnError;
|
|
93
|
+
}
|
package/dist/core/exec.js
CHANGED
|
@@ -111,8 +111,9 @@ function once(act) {
|
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
* The terminal belongs to the child. Only `gh auth login`
|
|
115
|
-
* from a terminal: repown cannot
|
|
114
|
+
* The terminal belongs to the child. Only `gh auth login` and Git Credential
|
|
115
|
+
* Manager's `github login` use this, and only from a terminal: repown cannot
|
|
116
|
+
* see what the child prints.
|
|
116
117
|
*/
|
|
117
118
|
export function inherit(file, args, options = {}) {
|
|
118
119
|
return new Promise((resolve) => {
|
package/dist/core/guard/check.js
CHANGED
|
@@ -210,6 +210,8 @@ async function rangeFor(git, ref, exclude) {
|
|
|
210
210
|
const known = !isZero(ref.remoteSha) && await git.hasCommit(ref.remoteSha);
|
|
211
211
|
return known ? [ref.remoteSha + '..' + ref.localSha, ...exclude] : [ref.localSha, ...exclude];
|
|
212
212
|
}
|
|
213
|
+
/** reauthor rewrites this branch's commits no remote has, after asking; it never pushes (ADR-026). */
|
|
214
|
+
const REAUTHOR_FIX = 'fix: repown reauthor (on that branch: rewrites the unpushed ones as the pinned account; asks first, never pushes)';
|
|
213
215
|
/** Each commit shows the address that is WRONG -- the committer's, when the author is right. */
|
|
214
216
|
function foreignRefusal(ref, foreign, expected) {
|
|
215
217
|
const shown = foreign.slice(0, 10).map((commit) => {
|
|
@@ -221,7 +223,7 @@ function foreignRefusal(ref, foreign, expected) {
|
|
|
221
223
|
return {
|
|
222
224
|
reason: foreign.length + ' commit(s) bound for ' + ref.remoteRef +
|
|
223
225
|
' were not authored as ' + expected + ', or were committed by someone else.',
|
|
224
|
-
detail: [...shown, ...more, '', 'These addresses become permanent once pushed.'],
|
|
226
|
+
detail: [...shown, ...more, '', 'These addresses become permanent once pushed.', REAUTHOR_FIX],
|
|
225
227
|
};
|
|
226
228
|
}
|
|
227
229
|
/** A fetch cures a missing object; it does nothing for history git printed in a shape repown cannot parse. */
|
package/dist/core/push-state.js
CHANGED
|
@@ -18,16 +18,17 @@ export async function readPushFacts(git, unpushed, env = process.env) {
|
|
|
18
18
|
const rewritable = await rewritableOf(git, target);
|
|
19
19
|
// A remote target's push URLs, read once for the sign-in and later-URL checks.
|
|
20
20
|
const pushed = target?.isRemote ? git.remoteUrls(target.name, true) : null;
|
|
21
|
-
const [configOverrides, signin, repoint, destination, laterUrls, divergence, elsewhere, upstream] = await Promise.all([
|
|
21
|
+
const [configOverrides, signin, urlUser, repoint, destination, laterUrls, divergence, elsewhere, upstream] = await Promise.all([
|
|
22
22
|
overridesIn(git),
|
|
23
23
|
signinOf(git, target, { rewritable: rewritable !== null, pushed }),
|
|
24
|
+
urlUserOf(git, target, pushed),
|
|
24
25
|
repointOf(git, branch),
|
|
25
26
|
rewritable ? null : destinationOf(git, target),
|
|
26
27
|
laterUrlsOf(git, target, pushed),
|
|
27
28
|
divergenceOf(git, target), elsewhereOf(git, target), upstreamOf(git, branch, target),
|
|
28
29
|
]);
|
|
29
30
|
return {
|
|
30
|
-
unpushed, env: hostileSet(env), configOverrides, elsewhere, signin, repoint, destination, laterUrls, rewritable, divergence,
|
|
31
|
+
unpushed, env: hostileSet(env), configOverrides, elsewhere, signin, urlUser, repoint, destination, laterUrls, rewritable, divergence,
|
|
31
32
|
detached: head?.kind === 'detached', upstream,
|
|
32
33
|
};
|
|
33
34
|
}
|
|
@@ -35,10 +36,16 @@ async function overridesIn(git) {
|
|
|
35
36
|
const values = await Promise.all(OVERRIDES.map((key) => git.getConfig(key)));
|
|
36
37
|
return OVERRIDES.filter((_, index) => values[index]);
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* A bare username shaped like an account name: a login's characters, at most 39 of them
|
|
41
|
+
* (GitHub's limit), and not a legacy 40-hex token. Anything else in the userinfo may be a
|
|
42
|
+
* token used as the username, so it is never printed or passed on (ADR-032).
|
|
43
|
+
*/
|
|
44
|
+
const ACCOUNT_LIKE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,38}$/;
|
|
38
45
|
/** A password or a token in the userinfo. A bare username (GCM's own advice) is not a secret. */
|
|
39
|
-
function carriesSecret(raw) {
|
|
46
|
+
export function carriesSecret(raw) {
|
|
40
47
|
const user = raw ? parseGitUrl(raw)?.user : null;
|
|
41
|
-
return !!user && (user.includes(':') || /^(gh[pousr]_|github_pat_)/i.test(user));
|
|
48
|
+
return !!user && (user.includes(':') || /^(gh[pousr]_|github_pat_)/i.test(user) || !ACCOUNT_LIKE.test(user));
|
|
42
49
|
}
|
|
43
50
|
async function signinOf(git, target, { rewritable, pushed }) {
|
|
44
51
|
const found = pushed && target ? await remoteSignin(git, target.name, await pushed)
|
|
@@ -84,6 +91,27 @@ async function configuredSignin(git, remote) {
|
|
|
84
91
|
const [key, values] = pushurls.length > 0 ? [pushurl, pushurls] : ['remote.' + remote + '.url', await git.getAllConfig('remote.' + remote + '.url')];
|
|
85
92
|
return values.some(carriesSecret) ? { key } : null;
|
|
86
93
|
}
|
|
94
|
+
async function urlUserOf(git, target, pushed) {
|
|
95
|
+
const urls = pushed && target ? await pushed : null;
|
|
96
|
+
const found = urls?.ok ? urls.value.find(namesUser) : undefined;
|
|
97
|
+
if (!found || !target)
|
|
98
|
+
return null;
|
|
99
|
+
const user = parseGitUrl(found).user;
|
|
100
|
+
for (const key of ['remote.' + target.name + '.pushurl', 'remote.' + target.name + '.url']) {
|
|
101
|
+
const values = await git.getAllConfig(key);
|
|
102
|
+
if (values.includes(found))
|
|
103
|
+
return { remote: target.name, user, key, clean: values.length === 1 ? withoutUser(found, user) : null };
|
|
104
|
+
}
|
|
105
|
+
return { remote: target.name, user, key: null, clean: null };
|
|
106
|
+
}
|
|
107
|
+
/** An HTTPS URL with a bare username: never one that carries a secret (that is `signin`). */
|
|
108
|
+
function namesUser(raw) {
|
|
109
|
+
const url = parseGitUrl(raw);
|
|
110
|
+
return url?.scheme === 'https' && !!url.user && !carriesSecret(raw);
|
|
111
|
+
}
|
|
112
|
+
function withoutUser(raw, user) {
|
|
113
|
+
return raw.replace('//' + user + '@', '//');
|
|
114
|
+
}
|
|
87
115
|
async function repointOf(git, branch) {
|
|
88
116
|
const unknown = branch ? await unknownDestination(git, branch) : null;
|
|
89
117
|
if (unknown?.kind !== 'url' || !unknown.remote)
|
|
@@ -1,39 +1,52 @@
|
|
|
1
|
-
// What
|
|
1
|
+
// What the push remote says to a dry-run push, as the clone's pinned account (ADR-031).
|
|
2
2
|
//
|
|
3
3
|
// A read is no check: github.com answers `ls-remote` of a public repository without asking for
|
|
4
4
|
// the credential at all, so a revoked token reads as fine (measured). The push endpoint always
|
|
5
5
|
// asks. `git push --dry-run` stops after the ref advertisement and sends nothing.
|
|
6
6
|
//
|
|
7
7
|
// The WHOLE stderr is read: the SSO refusal's fix is the `visit <url>` line git prints before
|
|
8
|
-
// its last one.
|
|
8
|
+
// its last one, and an SSH refusal's cause is its first line (ADR-032).
|
|
9
9
|
import { succeeded } from './exec.js';
|
|
10
10
|
import { networkReason } from './git.js';
|
|
11
11
|
import { copyableCommand } from './shell.js';
|
|
12
|
+
import { isGcm } from './credential/gcm.js';
|
|
13
|
+
import { isGh } from './credential/gh.js';
|
|
12
14
|
/** First match wins: SSO's 403 also reads as "unable to access", so it goes first. */
|
|
13
15
|
const PATTERNS = [
|
|
14
16
|
[/SAML SSO/, (stderr) => ({ kind: 'sso', link: /visit (https:\/\/\S+)/.exec(stderr)?.[1] ?? null })],
|
|
17
|
+
[/Permission to \S+ denied to deploy key/, () => ({ kind: 'deploy-key' })],
|
|
15
18
|
[/Permission to \S+ denied to /, (stderr) => ({ kind: 'denied', as: /denied to ([^\s.]+)/.exec(stderr)?.[1] ?? '' })],
|
|
16
19
|
[/Invalid username or token|Authentication failed/, () => ({ kind: 'rejected' })],
|
|
17
20
|
[/Repository not found/, () => ({ kind: 'not-found' })],
|
|
18
21
|
[/unable to get password|Cannot prompt because user interactivity has been disabled|could not read Username|terminal prompts disabled/, () => ({ kind: 'no-sign-in' })],
|
|
22
|
+
[/Host key verification failed/, () => ({ kind: 'host-key' })],
|
|
23
|
+
[/Permission denied \(publickey/, () => ({ kind: 'ssh-key' })],
|
|
19
24
|
];
|
|
25
|
+
/** A porcelain `!` line: the remote refused the ref itself, so the sign-in had already passed. */
|
|
26
|
+
const REF_REJECTED = /^!\t/m;
|
|
20
27
|
export function classifySignIn(result) {
|
|
21
28
|
if (succeeded(result))
|
|
22
29
|
return { kind: 'ok' };
|
|
23
30
|
if (result.timedOut)
|
|
24
31
|
return { kind: 'unchecked', reason: 'timed out' };
|
|
25
32
|
const found = PATTERNS.find(([pattern]) => pattern.test(result.stderr));
|
|
26
|
-
|
|
33
|
+
if (found)
|
|
34
|
+
return found[1](result.stderr);
|
|
35
|
+
return REF_REJECTED.test(result.stdout) ? { kind: 'ok' } : { kind: 'unchecked', reason: networkReason(result) };
|
|
27
36
|
}
|
|
28
37
|
export function describeSignIn(verdict, ctx) {
|
|
29
38
|
const whose = ctx.account ? ctx.account + '\'s sign-in' : 'this clone\'s sign-in';
|
|
39
|
+
const fail = (message, fix) => ({ level: 'fail', message: ctx.remote + message, fix });
|
|
30
40
|
switch (verdict.kind) {
|
|
31
|
-
case 'ok': return { level: 'pass', message: (ctx.account ? '
|
|
32
|
-
case 'sso': return
|
|
33
|
-
case 'rejected': return
|
|
41
|
+
case 'ok': return { level: 'pass', message: ctx.remote + (ctx.account ? ' accepts ' + whose + ' for a push' : ' accepts a push from this clone') + ' (a dry run: nothing was sent)', fix: [] };
|
|
42
|
+
case 'sso': return fail(' refused ' + whose + ': the organisation enforces SAML SSO, and this sign-in isn\'t authorised for it.', ssoFix(verdict.link));
|
|
43
|
+
case 'rejected': return fail(' rejected ' + whose + ': the token or password git held was expired, revoked or wrong, and git has asked the helper to forget it.', signInFix(ctx));
|
|
34
44
|
case 'denied': return denied(verdict.as, ctx);
|
|
35
|
-
case 'not-found': return
|
|
36
|
-
case 'no-sign-in': return
|
|
45
|
+
case 'not-found': return fail(' was not found with ' + whose + ': that account can\'t see it (the wrong account, or no access).', ['check the account (repown status), or ask for access']);
|
|
46
|
+
case 'no-sign-in': return fail(': no sign-in is stored' + (ctx.account ? ' for ' + ctx.account : '') + ', so a push would ask for one.', signInFix(ctx));
|
|
47
|
+
case 'deploy-key': return fail(' refused the push: the SSH key is a deploy key without write access here.', ['give that deploy key write access, or sign in with an account\'s own key']);
|
|
48
|
+
case 'ssh-key': return fail(' refused this machine\'s SSH key: it isn\'t added to an account that can push here.', sshFix('see which account the key signs in as: ', ctx));
|
|
49
|
+
case 'host-key': return fail(': ssh doesn\'t trust ' + (ctx.host ?? 'the host') + '\'s host key yet, so it stopped before signing in.', sshFix('check and trust it once: ', ctx));
|
|
37
50
|
case 'unchecked': return { level: 'warn', message: 'couldn\'t check the sign-in: ' + verdict.reason, fix: [] };
|
|
38
51
|
}
|
|
39
52
|
}
|
|
@@ -41,19 +54,57 @@ function ssoFix(link) {
|
|
|
41
54
|
const then = 'then: repown doctor --online';
|
|
42
55
|
return link ? ['authorise it: ' + link, then] : ['authorise this sign-in in the organisation\'s SSO settings', then];
|
|
43
56
|
}
|
|
44
|
-
/** GCM's own
|
|
45
|
-
function
|
|
46
|
-
if (
|
|
47
|
-
return [];
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
/** How to sign in again, by helper; GCM's own command only where it was measured. */
|
|
58
|
+
function signInFix(ctx) {
|
|
59
|
+
if (isGh(ctx.helper))
|
|
60
|
+
return ['gh signs in as its active account; undo it: repown fix'];
|
|
61
|
+
// A username in the URL outranks the pin, so the URL is the fix (ADR-032), not a login as it.
|
|
62
|
+
if (urlNamesOther(ctx))
|
|
63
|
+
return [fromUrlFix(ctx.account)];
|
|
64
|
+
if (!ctx.helper)
|
|
65
|
+
return ['no credential helper serves this URL; install Git Credential Manager, then: repown doctor --online'];
|
|
66
|
+
if (!isGcm(ctx.helper))
|
|
67
|
+
return ['sign in again through the credential helper (' + ctx.helper + '); a push in a terminal asks'];
|
|
68
|
+
const command = ctx.github && ctx.account ? gcmLogin(ctx.account) : null;
|
|
69
|
+
return [command ? 'sign in again: ' + command : 'sign in again through Git Credential Manager; a push in a terminal asks'];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The push URL names a user other than the pinned account, so removing it is the fix. The
|
|
73
|
+
* pinned account itself in the URL changes nothing: git sends the same name either way.
|
|
74
|
+
*/
|
|
75
|
+
export function urlNamesOther(ctx) {
|
|
76
|
+
if (!ctx.fromUrl)
|
|
77
|
+
return false;
|
|
78
|
+
return !ctx.account || !ctx.pinned || ctx.account.toLowerCase() !== ctx.pinned.toLowerCase();
|
|
79
|
+
}
|
|
80
|
+
function fromUrlFix(user) {
|
|
81
|
+
return 'the push URL names ' + (user ?? 'a user') + ', so git signs in as it; remove it (repown status prints the command)';
|
|
82
|
+
}
|
|
83
|
+
/** GCM's sign-in for github.com (measured, GCM 2.6.1); null when no shell quotes the account. */
|
|
84
|
+
export function gcmLogin(account) {
|
|
85
|
+
return copyableCommand(['git', 'credential-manager', 'github', 'login', '--username', account, '--browser', '--force']);
|
|
86
|
+
}
|
|
87
|
+
/** git sent the pinned username, but the helper answered with another account's token. */
|
|
88
|
+
function storedFor(ctx) {
|
|
89
|
+
return ['the stored sign-in for ' + ctx.account + ' is another account\'s', ...signInFix(ctx)];
|
|
90
|
+
}
|
|
91
|
+
function sshFix(label, ctx) {
|
|
92
|
+
const command = ctx.host ? copyableCommand(['ssh', '-T', 'git@' + ctx.host]) : null;
|
|
93
|
+
return [command ? label + command : 'check this machine\'s SSH key and known_hosts for the remote'];
|
|
50
94
|
}
|
|
51
95
|
/** Signed in as someone who can't push: the pinned account when it differs, else write access. */
|
|
52
96
|
function denied(as, ctx) {
|
|
53
97
|
const pinned = ctx.pinned;
|
|
54
98
|
if (!pinned || !as || as.toLowerCase() === pinned.toLowerCase()) {
|
|
55
|
-
return { level: 'fail', message: '
|
|
99
|
+
return { level: 'fail', message: ctx.remote + ' refused the push: ' + (as || 'this sign-in') + ' can\'t push here.', fix: ['ask the owner for write access'] };
|
|
56
100
|
}
|
|
101
|
+
const message = ctx.remote + ' refused the push: git signed in as ' + as + ', not ' + pinned + ', and ' + as + ' can\'t push here.';
|
|
102
|
+
if (!ctx.account)
|
|
103
|
+
return { level: 'fail', message, fix: sshFix('the SSH key signs in as ' + as + '; see which key: ', ctx) };
|
|
104
|
+
if (ctx.account.toLowerCase() === pinned.toLowerCase())
|
|
105
|
+
return { level: 'fail', message, fix: storedFor(ctx) };
|
|
106
|
+
if (ctx.fromUrl)
|
|
107
|
+
return { level: 'fail', message, fix: [fromUrlFix(as)] };
|
|
57
108
|
const command = copyableCommand(['repown', 'use', pinned]);
|
|
58
|
-
return { level: 'fail', message
|
|
109
|
+
return { level: 'fail', message, fix: [command ? 'use the pinned account: ' + command : 'pin ' + pinned + ' again with repown use'] };
|
|
59
110
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Which repair a failed sign-in check can offer to run, and what to ask first (ADR-032). Pure:
|
|
2
|
+
// doctor --online and setup's last step share it, and each draws the question its own way.
|
|
3
|
+
//
|
|
4
|
+
// An offer is made only where the fix is measured and local or the user's own sign-in:
|
|
5
|
+
// `repown fix` (a config edit), GCM's github.com login (the user signs in, repown sees
|
|
6
|
+
// nothing), the SSO page (the user approves it; repown only waits), `repown use` (a config
|
|
7
|
+
// edit). Everything else stays printed advice.
|
|
8
|
+
import { isGcm } from './credential/gcm.js';
|
|
9
|
+
import { isGh } from './credential/gh.js';
|
|
10
|
+
import { urlNamesOther } from './signin-check.js';
|
|
11
|
+
/** Null when there is nothing repown can run for this verdict. */
|
|
12
|
+
export function repairFor(verdict, ctx) {
|
|
13
|
+
if (verdict.kind === 'sso')
|
|
14
|
+
return { kind: 'sso', link: verdict.link };
|
|
15
|
+
if (verdict.kind === 'rejected' || verdict.kind === 'no-sign-in')
|
|
16
|
+
return signInRepair(ctx);
|
|
17
|
+
return verdict.kind === 'denied' ? deniedRepair(verdict.as, ctx) : null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Signed in as another account: `repown use` helps only where it changes the username git
|
|
21
|
+
* sends (HTTPS, not the URL's own); when git already sends the pinned one, the stored token is
|
|
22
|
+
* someone else's, so sign in again. Over SSH the key decides, and nothing here changes it.
|
|
23
|
+
*/
|
|
24
|
+
function deniedRepair(as, ctx) {
|
|
25
|
+
const same = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
26
|
+
if (urlNamesOther(ctx) || !ctx.pinned || !as || same(as, ctx.pinned) || !ctx.account)
|
|
27
|
+
return null;
|
|
28
|
+
return same(ctx.account, ctx.pinned) ? signInRepair(ctx) : { kind: 'use', account: ctx.pinned };
|
|
29
|
+
}
|
|
30
|
+
function signInRepair(ctx) {
|
|
31
|
+
if (isGh(ctx.helper))
|
|
32
|
+
return { kind: 'fix' };
|
|
33
|
+
// A username in the URL other than the pin is the blocker to remove, never an account to sign in as.
|
|
34
|
+
return isGcm(ctx.helper) && ctx.github && ctx.account && !urlNamesOther(ctx) ? { kind: 'login', account: ctx.account } : null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The question before running it, or null when the repair asks its own: `repown fix` shows
|
|
38
|
+
* which entries it removes, in which file, before its own question (default No). The SSO
|
|
39
|
+
* repair asks nothing and waits instead.
|
|
40
|
+
*/
|
|
41
|
+
export function repairQuestion(repair) {
|
|
42
|
+
switch (repair.kind) {
|
|
43
|
+
case 'fix': return null;
|
|
44
|
+
case 'login': return 'Sign in to GitHub as ' + repair.account + ' now? (Git Credential Manager opens your browser)';
|
|
45
|
+
case 'use': return 'Pin ' + repair.account + ' to this clone again now?';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** What the SSO wait says: the link is printed with the verdict above it. */
|
|
49
|
+
export const SSO_WAIT = 'Authorise the sign-in in your browser (the link above), then press Enter to check again; type q to stop.';
|
|
50
|
+
/** An SSO wait may repeat (the user decides when it's done); any other repair is tried once. */
|
|
51
|
+
export function triedOnce(repair) {
|
|
52
|
+
return repair.kind === 'sso' ? null : repair.kind + ':' + ('account' in repair ? repair.account : '');
|
|
53
|
+
}
|
package/dist/ui/help.js
CHANGED
|
@@ -13,7 +13,7 @@ export function renderTopHelp(entries) {
|
|
|
13
13
|
...globalOptionsHelp(),
|
|
14
14
|
...environmentHelp(),
|
|
15
15
|
' Exit codes: 0 success, 1 failure or refusal, 2 usage error,',
|
|
16
|
-
' 130 cancelled (setup, the start screen).',
|
|
16
|
+
' 3 not checked (doctor --online), 130 cancelled (setup, the start screen).',
|
|
17
17
|
'',
|
|
18
18
|
];
|
|
19
19
|
}
|
package/dist/ui/prompt.js
CHANGED
|
@@ -29,15 +29,35 @@ export async function ask(label, suggestion) {
|
|
|
29
29
|
rl.close();
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return false;
|
|
32
|
+
/** One question; null when the user pressed Ctrl-C or the input ended, which every caller takes as a stop. */
|
|
33
|
+
async function answerOf(question) {
|
|
35
34
|
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
35
|
+
const ended = new Promise((resolve) => rl.once('close', () => resolve(null)));
|
|
36
36
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
return await Promise.race([rl.question(question), ended]);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error.name === 'AbortError')
|
|
41
|
+
return null;
|
|
42
|
+
throw new Error('the question could not be asked', { cause: error });
|
|
39
43
|
}
|
|
40
44
|
finally {
|
|
41
45
|
rl.close();
|
|
42
46
|
}
|
|
43
47
|
}
|
|
48
|
+
/** y or n; an empty answer is `fallback` (No unless the caller says the step is recommended). */
|
|
49
|
+
export async function confirm(question, fallback = false) {
|
|
50
|
+
if (!interactive())
|
|
51
|
+
return false;
|
|
52
|
+
const answer = (await answerOf(' ' + question + (fallback ? ' [Y/n] ' : ' [y/N] ')))?.trim().toLowerCase();
|
|
53
|
+
if (answer === undefined)
|
|
54
|
+
return false;
|
|
55
|
+
return answer === '' ? fallback : answer === 'y' || answer === 'yes';
|
|
56
|
+
}
|
|
57
|
+
/** Waits for Enter; false when the user types q or Ctrl-C (or there is no terminal to wait in). */
|
|
58
|
+
export async function waitForEnter(message) {
|
|
59
|
+
if (!interactive())
|
|
60
|
+
return false;
|
|
61
|
+
const answer = await answerOf(' ' + message + ' ');
|
|
62
|
+
return answer !== null && answer.trim().toLowerCase() !== 'q';
|
|
63
|
+
}
|
package/dist/wizard/setup-run.js
CHANGED
|
@@ -27,6 +27,8 @@ import { blockers } from '../core/blockers.js';
|
|
|
27
27
|
import { readPushFacts } from '../core/push-state.js';
|
|
28
28
|
import { guardStateAt, hookLocation } from '../core/guard/hook.js';
|
|
29
29
|
import { readUnpushed } from '../core/unpushed.js';
|
|
30
|
+
import { interactive } from '../ui/prompt.js';
|
|
31
|
+
import { signInAfterSetup, signInRefused, signInSuffix, terminalSignIn } from './setup-signin.js';
|
|
30
32
|
const CANCELLED = 130;
|
|
31
33
|
export async function runSetup(args, deps) {
|
|
32
34
|
const registry = await readRegistry();
|
|
@@ -49,6 +51,7 @@ export async function runSetup(args, deps) {
|
|
|
49
51
|
args, git, given: given.value, prompter, accountKind: deps.accountKind, readAuth: deps.auth ?? inspectAuth,
|
|
50
52
|
...(deps.preview ? { preview: deps.preview } : {}),
|
|
51
53
|
...(deps.lead === undefined ? {} : { lead: deps.lead }),
|
|
54
|
+
signIn: unattended ? null : deps.signIn !== undefined ? deps.signIn : interactive() ? terminalSignIn(args) : null,
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
57
|
finally {
|
|
@@ -60,7 +63,7 @@ function notARepo(git) {
|
|
|
60
63
|
out.detail('run it inside a clone: cd path/to/repo, then repown setup');
|
|
61
64
|
return 1;
|
|
62
65
|
}
|
|
63
|
-
async function continueSetup({ args, git, given, prompter, accountKind, readAuth, preview, lead }) {
|
|
66
|
+
async function continueSetup({ args, git, given, prompter, accountKind, readAuth, preview, lead, signIn }) {
|
|
64
67
|
prompter?.intro?.('repown setup');
|
|
65
68
|
drawLead(prompter, lead);
|
|
66
69
|
prompter?.busy?.('Reading this clone and this machine');
|
|
@@ -74,7 +77,7 @@ async function continueSetup({ args, git, given, prompter, accountKind, readAuth
|
|
|
74
77
|
return answers.error;
|
|
75
78
|
if (!prompter)
|
|
76
79
|
return runUnattended(answers.value, ctx.value, git, readAuth);
|
|
77
|
-
return runGuided(answers.value, ctx.value, { git, prompter, readAuth });
|
|
80
|
+
return runGuided(answers.value, ctx.value, { git, prompter, readAuth, signIn });
|
|
78
81
|
}
|
|
79
82
|
/** The bare-repown sentence, inside the frame when the prompter can draw it. */
|
|
80
83
|
function drawLead(prompter, lead) {
|
|
@@ -189,21 +192,42 @@ async function runUnattended(answers, ctx, git, readAuth) {
|
|
|
189
192
|
}
|
|
190
193
|
async function runGuided(given, ctx, guided) {
|
|
191
194
|
const outcome = await wizard(setupFlow(ctx), ctx, given, guided.prompter);
|
|
192
|
-
if (outcome.status === 'done')
|
|
193
|
-
guided
|
|
194
|
-
return 0;
|
|
195
|
-
}
|
|
195
|
+
if (outcome.status === 'done')
|
|
196
|
+
return settled(guided);
|
|
196
197
|
if (outcome.status !== 'run')
|
|
197
198
|
return stoppedBefore(outcome.status, guided.prompter);
|
|
198
199
|
return runAccepted(outcome.answers, ctx, guided);
|
|
199
200
|
}
|
|
200
|
-
|
|
201
|
+
/**
|
|
202
|
+
* Already set up: nothing to run, and the sign-in check is still offered, as after a run only
|
|
203
|
+
* with nothing in the way of the next push (ADR-032); the review above listed what is.
|
|
204
|
+
*/
|
|
205
|
+
async function settled({ git, prompter, signIn }) {
|
|
206
|
+
prompter.outro?.('Nothing changed: this clone was already set up');
|
|
207
|
+
if (!signIn)
|
|
208
|
+
return 0;
|
|
209
|
+
prompter.close();
|
|
210
|
+
const first = await firstBlocking(git);
|
|
211
|
+
if (first) {
|
|
212
|
+
out.detail(out.marked('warn', process.stderr, 'sign-in not checked online: the next push will fail: ' + printable(first.summary)));
|
|
213
|
+
return 0;
|
|
214
|
+
}
|
|
215
|
+
const online = await signInAfterSetup(signIn, git);
|
|
216
|
+
if (online)
|
|
217
|
+
out.detail(signInLine(online));
|
|
218
|
+
return 0;
|
|
219
|
+
}
|
|
220
|
+
function signInLine(online) {
|
|
221
|
+
const refused = signInRefused(online);
|
|
222
|
+
return refused ? out.marked('warn', process.stderr, refused) : out.marked('ok', process.stderr, 'set up' + signInSuffix(online));
|
|
223
|
+
}
|
|
224
|
+
async function runAccepted(answers, ctx, { git, prompter, readAuth, signIn }) {
|
|
201
225
|
prompter.outro?.('Running the commands');
|
|
202
226
|
const confirm = gateFor(prompter, answers, ctx);
|
|
203
227
|
// Recommended hands the terminal over now. Step by step keeps it for each question.
|
|
204
228
|
if (!confirm)
|
|
205
229
|
prompter.close();
|
|
206
|
-
const state = { ...runState(git, readAuth, ctx), ...reported(answers, ctx, !ghNoted(answers, ctx)) };
|
|
230
|
+
const state = { ...runState(git, readAuth, ctx), ...reported(answers, ctx, !ghNoted(answers, ctx)), signIn, release: () => prompter.close() };
|
|
207
231
|
const code = await execute(planCommands(answers, ctx), confirm ? { ...state, confirm } : state);
|
|
208
232
|
if (confirm)
|
|
209
233
|
prompter.close();
|
|
@@ -264,7 +288,9 @@ function reported(answers, ctx, repeatGh) {
|
|
|
264
288
|
async function execute(plan, state) {
|
|
265
289
|
const before = await readCloneSnapshot(state.git, state.watchedKeys);
|
|
266
290
|
const ran = await walk(plan, state.git, state.confirm);
|
|
267
|
-
await
|
|
291
|
+
const end = ran.code === null ? await endOf(ran.done, state) : null;
|
|
292
|
+
const online = end && !end.found.some((blocker) => blocker.blocks) ? await onlineAfter(state) : null;
|
|
293
|
+
await reportRun(before, ran, state, { end, online });
|
|
268
294
|
return ran.code ?? 0;
|
|
269
295
|
}
|
|
270
296
|
async function walk(plan, git, confirm) {
|
|
@@ -328,22 +354,32 @@ function halt(remaining, code, why) {
|
|
|
328
354
|
out.detail(' ' + out.accent(process.stderr, formatCommand(planned.argv)));
|
|
329
355
|
return code;
|
|
330
356
|
}
|
|
357
|
+
async function endOf(done, state) {
|
|
358
|
+
const pinned = done.find((planned) => planned.argv[0] === 'use')?.argv.at(-1);
|
|
359
|
+
const account = pinned ?? (state.pinnedAlready ? state.account : null);
|
|
360
|
+
return account ? { account, found: await blockersNow(state.git, account) } : null;
|
|
361
|
+
}
|
|
362
|
+
/** The last step: the prompter gives the terminal back first, since the check may hand it on. */
|
|
363
|
+
async function onlineAfter(state) {
|
|
364
|
+
if (!state.signIn)
|
|
365
|
+
return null;
|
|
366
|
+
state.release?.();
|
|
367
|
+
return signInAfterSetup(state.signIn, state.git);
|
|
368
|
+
}
|
|
331
369
|
/** On stderr, like the step lines: stdout carries only what the commands themselves print. */
|
|
332
|
-
async function reportRun(before, ran, state) {
|
|
370
|
+
async function reportRun(before, ran, state, end) {
|
|
333
371
|
if (ran.code === null)
|
|
334
|
-
|
|
372
|
+
announce(ran.skipped, end);
|
|
335
373
|
await printClone(before, state);
|
|
336
374
|
const auth = wantsAuth(ran, state) ? await state.readAuth(state.git) : null;
|
|
337
375
|
printMachine(ran.done, auth);
|
|
338
376
|
if (ran.code === null)
|
|
339
377
|
closeRun(auth, state);
|
|
340
378
|
}
|
|
341
|
-
|
|
379
|
+
function announce(skipped, { end, online }) {
|
|
342
380
|
process.stderr.write('\n');
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (account)
|
|
346
|
-
closing(account, await blockersNow(state.git, account));
|
|
381
|
+
if (end)
|
|
382
|
+
closing(end, online);
|
|
347
383
|
for (const planned of skipped)
|
|
348
384
|
out.detail('skipped: ' + printable(planned.what));
|
|
349
385
|
}
|
|
@@ -351,17 +387,27 @@ async function announce(done, skipped, state) {
|
|
|
351
387
|
* `done` only with nothing left in the way of the next push; otherwise the first, then each one
|
|
352
388
|
* (ADR-026). What blocks nothing (the guard is off) still gets its lines, under `done`.
|
|
353
389
|
*/
|
|
354
|
-
function closing(account, found) {
|
|
390
|
+
function closing({ account, found }, online) {
|
|
355
391
|
const blocking = found.filter((blocker) => blocker.blocks);
|
|
356
392
|
const more = blocking.length > 1 ? ' (and ' + (blocking.length - 1) + ' more below)' : '';
|
|
357
393
|
const [first] = blocking;
|
|
358
|
-
|
|
359
|
-
|
|
394
|
+
const refused = signInRefused(online);
|
|
395
|
+
if (first)
|
|
396
|
+
out.detail(out.marked('warn', process.stderr, 'set up for ' + printable(account) + '; the next push will fail: ' + printable(first.summary) + more));
|
|
397
|
+
else if (refused)
|
|
398
|
+
out.detail(out.marked('warn', process.stderr, 'set up for ' + printable(account) + '; ' + printable(refused)));
|
|
399
|
+
else
|
|
400
|
+
out.detail(out.marked('ok', process.stderr, 'done: this clone is set up for ' + printable(account) + signInSuffix(online)));
|
|
360
401
|
// A mark pushes the closing words two columns right; the blockers stay two deeper still.
|
|
361
402
|
const indent = useColour(process.stderr) ? ' ' : ' ';
|
|
362
403
|
for (const line of found.flatMap((blocker) => blocker.lines))
|
|
363
404
|
out.detail(indent + printable(line));
|
|
364
405
|
}
|
|
406
|
+
/** What stops the next push of a settled clone, read now; none without a pinned account. */
|
|
407
|
+
async function firstBlocking(git) {
|
|
408
|
+
const account = await git.getConfig('repown.account', 'local');
|
|
409
|
+
return account ? (await blockersNow(git, account)).find((blocker) => blocker.blocks) : undefined;
|
|
410
|
+
}
|
|
365
411
|
/** Re-read after the run: a step may have fixed what the review showed, or not. */
|
|
366
412
|
async function blockersNow(git, account) {
|
|
367
413
|
const email = await git.getConfig('user.email', 'local') ?? '';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Setup's last step (ADR-032): once the clone is set up with nothing in the way of the next
|
|
2
|
+
// push, ask whether to check the sign-in with the remote, and run doctor --online's check and
|
|
3
|
+
// guided repair if so. Terminal only, never under --no-input. The answer joins setup's closing
|
|
4
|
+
// line, so setup says "done" with the sign-in checked, or says what is left.
|
|
5
|
+
import { inspectRepo } from '../core/inspect.js';
|
|
6
|
+
import { gitFor } from '../ui/args.js';
|
|
7
|
+
import { confirm } from '../ui/prompt.js';
|
|
8
|
+
import { printable } from '../ui/format.js';
|
|
9
|
+
import { checkOnline } from '../commands/doctor-online.js';
|
|
10
|
+
import { guideSignIn } from '../commands/signin-guide.js';
|
|
11
|
+
import { terminalIo } from '../commands/signin-terminal.js';
|
|
12
|
+
/** Why there is no push to try yet: the closing line says it, so a skip never reads as a pass. */
|
|
13
|
+
export const NO_COMMIT = 'no commit to try a push with yet';
|
|
14
|
+
export const NO_REMOTE = 'no remote to ask yet';
|
|
15
|
+
export const SIGNIN_QUESTION = 'Check the sign-in with the remote now? (one dry-run push: nothing is sent)';
|
|
16
|
+
export function terminalSignIn(args) {
|
|
17
|
+
return {
|
|
18
|
+
offer: () => confirm(SIGNIN_QUESTION, true),
|
|
19
|
+
check: () => {
|
|
20
|
+
let first = true;
|
|
21
|
+
const once = async () => {
|
|
22
|
+
const repo = await inspectRepo(gitFor(args));
|
|
23
|
+
const pinned = repo.identity.owner ?? repo.identity.account;
|
|
24
|
+
const result = await checkOnline(repo, pinned, first);
|
|
25
|
+
first = false;
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
return guideSignIn(once, terminalIo(args));
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Skipped, with the reason, when there is nothing to ask with: no commit, or no remote. */
|
|
33
|
+
export async function signInAfterSetup(step, git) {
|
|
34
|
+
if (await git.revParse('HEAD') === null)
|
|
35
|
+
return { kind: 'skipped', why: NO_COMMIT };
|
|
36
|
+
const remotes = await git.readRemotes();
|
|
37
|
+
if (!remotes.ok || remotes.value.length === 0)
|
|
38
|
+
return { kind: 'skipped', why: NO_REMOTE };
|
|
39
|
+
if (!await step.offer())
|
|
40
|
+
return { kind: 'declined' };
|
|
41
|
+
return { kind: 'checked', check: await step.check() };
|
|
42
|
+
}
|
|
43
|
+
/** What the closing line adds; a refusal is said instead of "done" (closingWords). */
|
|
44
|
+
export function signInSuffix(outcome) {
|
|
45
|
+
if (!outcome)
|
|
46
|
+
return '';
|
|
47
|
+
if (outcome.kind === 'skipped')
|
|
48
|
+
return ' · sign-in not checked online (' + outcome.why + ')';
|
|
49
|
+
if (outcome.kind === 'declined' || outcome.check.level === 'warn')
|
|
50
|
+
return ' · sign-in not checked online';
|
|
51
|
+
return outcome.check.level === 'pass' ? ' · ' + printable(outcome.check.remote) + ' accepts the sign-in' : '';
|
|
52
|
+
}
|
|
53
|
+
export function signInRefused(outcome) {
|
|
54
|
+
return outcome?.kind === 'checked' && outcome.check.level === 'fail' ? printable(outcome.check.remote) + ' refused the sign-in (above)' : null;
|
|
55
|
+
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "repown",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.7.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.
|
|
3
|
+
"version": "0.7.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",
|