@sous-io/sous 0.2.17 → 0.2.18
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/docs/markdown/commands.md +36 -6
- package/docs/markdown/repositories-authoring.md +23 -2
- package/docs/markdown/repositories-consuming.md +44 -2
- package/docs/markdown/repositories-file-formats.md +2 -1
- package/package.json +1 -1
- package/recipes/core/sous-skills/sous.recipe.yaml +1 -1
- package/src/commands/repo/unlink.ts +333 -20
- package/src/commands/subscription/update.ts +215 -0
- package/src/lib/repos/formats/links-map.ts +5 -3
- package/src/lib/repos/git-clone.ts +71 -0
- package/src/lib/repos/links.ts +2 -1
- package/src/lib/repos/locked-recipes.ts +22 -0
- package/src/lib/repos/resolver.ts +25 -2
- package/src/lib/repos/seed.ts +64 -5
- package/src/lib/repos/store/hash.ts +68 -8
- package/src/lib/repos/subscription-service.ts +744 -20
- package/src/lib/repos/update-plan.ts +234 -0
|
@@ -231,9 +231,22 @@ Example: `sous repo link sous-recipes ~/Projects/sous-recipes`, or `sous repo li
|
|
|
231
231
|
--generate-branch --latest --yes`
|
|
232
232
|
|
|
233
233
|
### `sous repo unlink REPO`
|
|
234
|
-
Stops reading a repository from a working copy
|
|
235
|
-
it appears in `sous.links.json` (see
|
|
236
|
-
|
|
234
|
+
Stops reading a repository from a working copy, goes back to the versions the lockfile pins, and rebuilds the
|
|
235
|
+
project; `REPO` is the short name as it appears in `sous.links.json` (see
|
|
236
|
+
[File formats](repositories-file-formats.md)). On its own it also fetches the repository's index, with a short
|
|
237
|
+
timeout, and reports any newer published version the ranges allow, without moving anything; when the index
|
|
238
|
+
cannot be fetched in time it says it could not check. The checkout stays where it is unless `--remove` is passed.
|
|
239
|
+
Takes `--dry-run`, `--no-build`, `--answer` and `--answers-file`.
|
|
240
|
+
|
|
241
|
+
- `--global`: remove the machine-wide link, not this project's.
|
|
242
|
+
- `--update`: move this repository's pins to the newest versions their ranges allow before rebuilding. It runs
|
|
243
|
+
the same code as `sous subscription update REPO`.
|
|
244
|
+
- `--remove`: delete the checkout as well, but only one sous cloned itself; a checkout linked by path is refused
|
|
245
|
+
with an error. Uncommitted changes, commits no remote has and stashes are listed first and asked about.
|
|
246
|
+
- `-y, --yes`: answer every question this command asks: deleting a checkout that holds work, the update plan,
|
|
247
|
+
and the trust question for a repository a newer version needs (also `--force`, `--trust`).
|
|
248
|
+
|
|
249
|
+
Example: `sous repo unlink sous-recipes --update`
|
|
237
250
|
|
|
238
251
|
### `sous repo init [DIRECTORY]`
|
|
239
252
|
Creates a new recipe repository in a directory, defaulting to the current one; `--dry-run` prints the files it
|
|
@@ -306,6 +319,20 @@ Example: `sous subscription add workflow/task-files@^1.2.0 --answer apiUrl=https
|
|
|
306
319
|
Removes a subscription and everything only it brought in, then rebuilds so those files are gone. Also spelled
|
|
307
320
|
`sous unsubscribe`. Takes `--dry-run` and `--no-build`. Example: `sous subscription remove workflow/task-files`
|
|
308
321
|
|
|
322
|
+
### `sous subscription update [REF]`
|
|
323
|
+
Moves the lockfile's pins to the newest published versions their ranges allow, then rebuilds the project. With
|
|
324
|
+
no `REF` it covers every subscription; a `REF` naming a repository, a namespace or a recipe narrows it, and
|
|
325
|
+
everything outside it stays where it is pinned. It fetches every trusted repository's index first, never widens
|
|
326
|
+
a range, moves dependencies with the closure, and changes only the lockfile, never the subscriptions. It prints
|
|
327
|
+
the plan and asks once; with nothing to update it says so and asks nothing. See
|
|
328
|
+
[Moving to newer versions](repositories-consuming.md#moving-to-newer-versions). Takes `--no-build`, `--answer`
|
|
329
|
+
and `--answers-file`, and `--dry-run`, which fetches the indexes but downloads no recipe and writes nothing.
|
|
330
|
+
|
|
331
|
+
- `-y, --yes`: accept the plan, and trust any repository a newer version needs (also `--force`, `--trust`).
|
|
332
|
+
- `--accept-first`: when `REF` matches several things, take the first one listed.
|
|
333
|
+
|
|
334
|
+
Example: `sous subscription update workflow/task-files`
|
|
335
|
+
|
|
309
336
|
### `sous subscription list`
|
|
310
337
|
Lists the subscriptions this project declares, switched-off ones included, with the range each resolves within,
|
|
311
338
|
the versions the lockfile pins, the latest version each of those recipes has published, where it came from and
|
|
@@ -317,7 +344,8 @@ only the subscriptions that have pinned something. Example: `sous subscription l
|
|
|
317
344
|
|
|
318
345
|
`namespace` reads the cached indexes and the lockfile, so it works offline. A trusted repository whose index has
|
|
319
346
|
never been fetched is named at the end of a listing, not left out. Both commands take the
|
|
320
|
-
[browsing flags](#flags-that-browse); with `--installed` the recipe count is the number installed.
|
|
347
|
+
[browsing flags](#flags-that-browse); with `--installed` the recipe count is the number installed. The core version this installation of sous
|
|
348
|
+
ships is listed even while the cached index does not publish it yet.
|
|
321
349
|
|
|
322
350
|
### `sous namespace list`
|
|
323
351
|
Lists every namespace the trusted repositories publish, how many recipes each holds, and how much of it this
|
|
@@ -354,8 +382,10 @@ Prints what `.sous/sous.lock.json` pins: the recipe, the version, the repository
|
|
|
354
382
|
### `sous lock rebuild`
|
|
355
383
|
Recomputes the whole lockfile from the subscriptions the config declares and the cached indexes, starting from
|
|
356
384
|
empty, so an entry nothing holds any more is dropped rather than carried through: the repair for a file that
|
|
357
|
-
drifted through a hand edit or a bad merge. It asks nothing, grants no trust and downloads nothing.
|
|
358
|
-
|
|
385
|
+
drifted through a hand edit or a bad merge. It asks nothing, grants no trust and downloads nothing. The core
|
|
386
|
+
version this installation of sous ships resolves even when the cached index has not published it yet, exactly
|
|
387
|
+
as it does in a build. To move pins to versions published since the last fetch, use `sous subscription update`.
|
|
388
|
+
Takes `--dry-run`. Example: `sous lock rebuild --dry-run`
|
|
359
389
|
|
|
360
390
|
## vars
|
|
361
391
|
|
|
@@ -289,8 +289,29 @@ and freshness checks no longer apply to it. Builds say so every time.
|
|
|
289
289
|
Run 'sous repo unlink my-recipes' to go back to published versions.
|
|
290
290
|
```
|
|
291
291
|
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
### Unlink, and pick up your release
|
|
293
|
+
|
|
294
|
+
Linking never touches the lockfile, so `sous repo unlink my-recipes` goes back to exactly the versions pinned
|
|
295
|
+
before the link, and rebuilds the project so its outputs match them. It also fetches the repository's index,
|
|
296
|
+
with a short timeout, and says whether a newer version the ranges allow has been published since; it moves
|
|
297
|
+
nothing, and when the index cannot be fetched in time it says it could not check. Unlinking a name linked in
|
|
298
|
+
the other scope says which scope holds it.
|
|
299
|
+
|
|
300
|
+
Once your change is released, one of these moves the project onto it:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
sous repo unlink my-recipes --update # unlink, move this repository's pins, then rebuild
|
|
304
|
+
sous subscription update my-recipes # the same move, when nothing is linked any more
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
`--update` runs exactly the code `sous subscription update my-recipes` runs: every pin the repository supplies
|
|
308
|
+
moves to the newest version its range allows, after one plan and one question. See
|
|
309
|
+
[Moving to newer versions](repositories-consuming.md#moving-to-newer-versions).
|
|
310
|
+
|
|
311
|
+
The checkout stays where it is unless you pass `--remove`, because `sous repo submit` uses a leftover checkout to
|
|
312
|
+
revise a proposal that is still open. `--remove` deletes it only when sous cloned it; a checkout you linked by
|
|
313
|
+
path is yours, and sous refuses with an error. Before deleting, sous lists anything in the checkout that exists
|
|
314
|
+
nowhere else (uncommitted changes, commits no remote has, and stashes) and asks; `--yes` answers ahead.
|
|
294
315
|
|
|
295
316
|
### How a checkout compares with upstream
|
|
296
317
|
|
|
@@ -220,7 +220,48 @@ build` instead. The `Latest version` column beside it is read from the cache, or
|
|
|
220
220
|
`sous repo list` shows each trusted repository with its provider, origin, whether it is linked, its
|
|
221
221
|
recipe count and its URL; `--verbose` adds a `Namespaces:` line under each row. `sous lock show`
|
|
222
222
|
prints the other half: every version your lockfile pins, where it came from and who holds it. When
|
|
223
|
-
that file has drifted, `sous lock rebuild` recomputes it from your subscriptions
|
|
223
|
+
that file has drifted, `sous lock rebuild` recomputes it from your subscriptions and the cached
|
|
224
|
+
indexes, fetching nothing.
|
|
225
|
+
|
|
226
|
+
## Moving to newer versions
|
|
227
|
+
|
|
228
|
+
A build holds the versions the lockfile pins, so a newer release reaches the project only when
|
|
229
|
+
something moves the pin. `sous subscription update` is that step:
|
|
230
|
+
|
|
231
|
+
```term
|
|
232
|
+
$ sous subscription update workflow/qa-variables
|
|
233
|
+
Updating the recipe 'qa-recipes:workflow/qa-variables' changes the lockfile:
|
|
234
|
+
|
|
235
|
+
• Adding workflow/qa-helper version 1.0.0
|
|
236
|
+
• Updating workflow/qa-variables from version 0.1.0 to version 0.2.0
|
|
237
|
+
|
|
238
|
+
Update the lockfile? (y/N)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
It fetches every trusted repository's index first, so a version published a minute ago counts.
|
|
242
|
+
With no reference it covers every subscription; a reference names a repository, a namespace or a
|
|
243
|
+
recipe, at any level of qualification, and everything outside it stays exactly where it is pinned.
|
|
244
|
+
What it will and will not do:
|
|
245
|
+
|
|
246
|
+
- A pin moves only within the range its subscription declares, or the range the recipe depending
|
|
247
|
+
on it declares; a range is never widened. Prereleases count only for a subscription that opted
|
|
248
|
+
into them.
|
|
249
|
+
- Dependencies move with the closure: a dependency a newer version adds is pinned, and one it
|
|
250
|
+
dropped leaves the lockfile unless something else still holds it.
|
|
251
|
+
- Only the lockfile changes. Your subscriptions stay exactly as they are written.
|
|
252
|
+
- It prints the plan and asks once; `--yes` accepts it, and a run with no terminal and no `--yes`
|
|
253
|
+
fails naming the flag. With nothing to update it says so and asks nothing.
|
|
254
|
+
- A repository a newer version needs that the project does not trust goes through the usual trust
|
|
255
|
+
question, and new questions the newer versions ask are asked the way subscribing asks them.
|
|
256
|
+
- A repository whose index cannot be fetched is skipped and named, and its pins stay put.
|
|
257
|
+
- A linked repository's pins move too, and the plan notes that builds keep reading the checkout
|
|
258
|
+
until it is unlinked.
|
|
259
|
+
- The built-in `core` subscription never moves: its range is exactly the running sous version, so
|
|
260
|
+
upgrading sous is what moves it.
|
|
261
|
+
|
|
262
|
+
It rebuilds the project afterwards. `--dry-run` fetches the indexes and prints the plan, and
|
|
263
|
+
downloads no recipe and writes nothing, so the dependencies and questions of a version this machine
|
|
264
|
+
does not hold yet are named rather than listed. `--no-build` skips the rebuild.
|
|
224
265
|
|
|
225
266
|
## Remove a subscription
|
|
226
267
|
|
|
@@ -290,7 +331,8 @@ lapsed (`store.freshnessSeconds`, five minutes by default), or when a command fo
|
|
|
290
331
|
check never breaks a build, because the cached index is used instead. Always-pull changes what
|
|
291
332
|
happens after that check, not how often it happens: a repository or subscription marked
|
|
292
333
|
`alwaysPull` takes a newer in-range version rather than the locked one; set it with
|
|
293
|
-
`--always-pull`, or on either entry in the config.
|
|
334
|
+
`--always-pull`, or on either entry in the config. Without it, `sous subscription update` is how a
|
|
335
|
+
pin moves; see [Moving to newer versions](#moving-to-newer-versions).
|
|
294
336
|
|
|
295
337
|
Every other repository the lockfile pins from is checked on the same window, only to tell you what
|
|
296
338
|
is newer. A build lists each recipe with a newer version inside the range declared for it, beside
|
|
@@ -252,7 +252,8 @@ freshness checks; entries are keyed by the repository's configured short name.
|
|
|
252
252
|
```
|
|
253
253
|
|
|
254
254
|
`path` is absolute; `origin` is `clone` when sous cloned the working copy itself and `path` when it was
|
|
255
|
-
pointed at an existing checkout
|
|
255
|
+
pointed at an existing checkout. Unlinking removes the entry and leaves the checkout in place, unless
|
|
256
|
+
`sous repo unlink --remove` is asked to delete one sous cloned; it never deletes a `path` checkout. Both the
|
|
256
257
|
project's `.sous/sous.links.json` and `$SOUS_HOME/sous.links.json` are read, and the project's entries win.
|
|
257
258
|
|
|
258
259
|
## Configuration keys
|
package/package.json
CHANGED
|
@@ -1,35 +1,72 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
1
3
|
import { Args, Flags } from "@oclif/core";
|
|
2
4
|
import { BaseCommand } from "../../base-command.js";
|
|
3
|
-
import {
|
|
5
|
+
import { buildProjectOutputs } from "../../lib/build-service.js";
|
|
6
|
+
import { ConfigError, isConfigError } from "../../lib/errors.js";
|
|
4
7
|
import {
|
|
8
|
+
NonInteractiveError,
|
|
9
|
+
isInteractive,
|
|
10
|
+
nonInteractiveError,
|
|
11
|
+
wantsHelp,
|
|
12
|
+
} from "../../lib/interactive.js";
|
|
13
|
+
import {
|
|
14
|
+
globalReposDir,
|
|
15
|
+
projectReposDir,
|
|
5
16
|
readGlobalLinks,
|
|
6
17
|
readProjectLinks,
|
|
7
18
|
writeGlobalLinks,
|
|
8
19
|
writeProjectLinks,
|
|
9
20
|
} from "../../lib/repos/links.js";
|
|
21
|
+
import { hasNoUnsavedWork, unsavedWork, type UnsavedWork } from "../../lib/repos/git-clone.js";
|
|
22
|
+
import {
|
|
23
|
+
subscriptionServiceFor,
|
|
24
|
+
type SubscriptionService,
|
|
25
|
+
} from "../../lib/repos/subscription-service.js";
|
|
26
|
+
import type { RepoLink } from "../../lib/repos/formats/links-map.js";
|
|
27
|
+
import { collectProvidedAnswers } from "../../lib/vars/index.js";
|
|
28
|
+
import { formatAskReport } from "../../lib/vars/ask.js";
|
|
10
29
|
import {
|
|
30
|
+
BULLET,
|
|
11
31
|
blankLine,
|
|
12
32
|
dryRunNotice,
|
|
13
33
|
footer,
|
|
34
|
+
heading,
|
|
35
|
+
indent,
|
|
14
36
|
log,
|
|
37
|
+
note,
|
|
38
|
+
paragraph,
|
|
15
39
|
section,
|
|
16
40
|
showCommandVars,
|
|
17
41
|
showVariables,
|
|
42
|
+
subheading,
|
|
43
|
+
warning,
|
|
18
44
|
} from "../../utils/formatting.js";
|
|
45
|
+
import { askYesNo } from "../../utils/prompts.js";
|
|
46
|
+
import { answerFlags, confirmationFlag } from "../../utils/flags.js";
|
|
19
47
|
|
|
20
48
|
/**
|
|
21
|
-
* `sous repo unlink` stops reading a repository from a working copy
|
|
22
|
-
*
|
|
49
|
+
* `sous repo unlink` stops reading a repository from a working copy, goes back
|
|
50
|
+
* to the versions the lockfile pins, and rebuilds the project.
|
|
51
|
+
*
|
|
52
|
+
* Linking never touches the lockfile, so unlinking returns to exactly the
|
|
53
|
+
* versions pinned before the link. Three ways to finish, one per flag:
|
|
54
|
+
*
|
|
55
|
+
* - On its own, it fetches the repository's index with a short timeout and
|
|
56
|
+
* reports, as a fact, any newer published version the ranges allow. Nothing
|
|
57
|
+
* moves.
|
|
58
|
+
* - `--update` runs the same code as `sous subscription update <repository>`,
|
|
59
|
+
* so the pins move to those newer versions before the rebuild.
|
|
60
|
+
* - `--remove` deletes the checkout, and only one sous cloned itself. A
|
|
61
|
+
* checkout linked by path belongs to its owner and is never deleted. Work
|
|
62
|
+
* that exists nowhere else is listed first and asked about.
|
|
23
63
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* a directory that may hold uncommitted work is not something a command like
|
|
27
|
-
* this should decide on its own. The path is printed so the user can delete it
|
|
28
|
-
* themselves if they want to.
|
|
64
|
+
* Without `--remove` the checkout stays exactly where it is, because `sous repo
|
|
65
|
+
* submit` uses a leftover checkout to revise a proposal that is still open.
|
|
29
66
|
*/
|
|
30
67
|
export default class RepoUnlink extends BaseCommand {
|
|
31
68
|
static description =
|
|
32
|
-
"Stop reading a repository from a working copy and go back to
|
|
69
|
+
"Stop reading a repository from a working copy and go back to its pinned versions";
|
|
33
70
|
|
|
34
71
|
/**
|
|
35
72
|
* The other spelling of the topic. It lives under a hidden topic, so it is
|
|
@@ -39,6 +76,8 @@ export default class RepoUnlink extends BaseCommand {
|
|
|
39
76
|
|
|
40
77
|
static examples = [
|
|
41
78
|
"<%= config.bin %> repo unlink sous-recipes",
|
|
79
|
+
"<%= config.bin %> repo unlink sous-recipes --update",
|
|
80
|
+
"<%= config.bin %> repo unlink sous-recipes --remove",
|
|
42
81
|
"<%= config.bin %> repo unlink sous-recipes --global",
|
|
43
82
|
];
|
|
44
83
|
|
|
@@ -52,14 +91,31 @@ export default class RepoUnlink extends BaseCommand {
|
|
|
52
91
|
static flags = {
|
|
53
92
|
...BaseCommand.baseFlags,
|
|
54
93
|
global: Flags.boolean({
|
|
94
|
+
description: "Remove the machine-wide link rather than this project's link",
|
|
95
|
+
default: false,
|
|
96
|
+
}),
|
|
97
|
+
update: Flags.boolean({
|
|
55
98
|
description:
|
|
56
|
-
"
|
|
99
|
+
"Move this repository's pins to the newest versions their ranges allow before rebuilding",
|
|
57
100
|
default: false,
|
|
58
101
|
}),
|
|
102
|
+
remove: Flags.boolean({
|
|
103
|
+
description: "Delete the checkout as well, when sous cloned it",
|
|
104
|
+
default: false,
|
|
105
|
+
}),
|
|
106
|
+
// One flag answers every question this command can ask: deleting a
|
|
107
|
+
// checkout that holds work, the update plan, and the trust question for a
|
|
108
|
+
// repository a newer version needs.
|
|
109
|
+
yes: confirmationFlag({ extraAliases: ["trust"] }),
|
|
59
110
|
"dry-run": Flags.boolean({
|
|
60
111
|
description: "Print what would change without writing anything",
|
|
61
112
|
default: false,
|
|
62
113
|
}),
|
|
114
|
+
"no-build": Flags.boolean({
|
|
115
|
+
description: "Unlink without rebuilding the project",
|
|
116
|
+
default: false,
|
|
117
|
+
}),
|
|
118
|
+
...answerFlags(),
|
|
63
119
|
};
|
|
64
120
|
|
|
65
121
|
async run(): Promise<void> {
|
|
@@ -67,12 +123,13 @@ export default class RepoUnlink extends BaseCommand {
|
|
|
67
123
|
const { sousDir } = this.configContext;
|
|
68
124
|
const isGlobal = flags.global;
|
|
69
125
|
const name = args.repo;
|
|
126
|
+
const dryRun = flags["dry-run"];
|
|
70
127
|
|
|
71
128
|
showCommandVars({
|
|
72
129
|
Project: this.projectLabel,
|
|
73
130
|
Repository: name,
|
|
74
131
|
Scope: isGlobal ? "this machine" : "this project",
|
|
75
|
-
"Dry Run":
|
|
132
|
+
"Dry Run": dryRun,
|
|
76
133
|
});
|
|
77
134
|
|
|
78
135
|
section("Unlinking a repository");
|
|
@@ -84,31 +141,287 @@ export default class RepoUnlink extends BaseCommand {
|
|
|
84
141
|
throw new ConfigError(this.notLinkedMessage(name, isGlobal, sousDir));
|
|
85
142
|
}
|
|
86
143
|
|
|
87
|
-
|
|
144
|
+
const service = subscriptionServiceFor({
|
|
145
|
+
configContext: this.configContext,
|
|
146
|
+
settings: this.settings,
|
|
147
|
+
shellEnv: this.shellEnv,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Everything that can refuse is settled before anything is written, so a
|
|
151
|
+
// refusal leaves the link exactly as it was.
|
|
152
|
+
if (flags.update && service.currentRepos()[name] === undefined) {
|
|
153
|
+
throw new ConfigError(
|
|
154
|
+
`'${name}' is linked, but this project does not trust a repository by that ` +
|
|
155
|
+
`name, so it has no pins to update.\n` +
|
|
156
|
+
` Nothing was changed; the link is still in place.`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
if (flags.remove) this.assertRemovable(name, entry, isGlobal, sousDir);
|
|
160
|
+
const work = flags.remove ? unsavedWork(entry.path) : undefined;
|
|
161
|
+
|
|
162
|
+
if (dryRun) {
|
|
88
163
|
dryRunNotice(`would unlink '${name}', which points at ${entry.path}`);
|
|
89
|
-
dryRunNotice(
|
|
164
|
+
dryRunNotice(
|
|
165
|
+
flags.remove
|
|
166
|
+
? "the checkout would be deleted"
|
|
167
|
+
: "the checkout itself would be left where it is"
|
|
168
|
+
);
|
|
169
|
+
if (work !== undefined && !hasNoUnsavedWork(work)) this.describeUnsavedWork(work);
|
|
170
|
+
if (flags.update) await service.update({ repo: name, dryRun: true });
|
|
90
171
|
footer();
|
|
91
172
|
return;
|
|
92
173
|
}
|
|
93
174
|
|
|
175
|
+
if (work !== undefined) await this.confirmRemoval(entry.path, work, flags.yes);
|
|
176
|
+
|
|
94
177
|
delete map.links[name];
|
|
95
178
|
const linksPath = isGlobal ? writeGlobalLinks(map) : writeProjectLinks(sousDir, map);
|
|
96
179
|
|
|
97
180
|
showVariables({
|
|
98
181
|
Repository: name,
|
|
99
|
-
|
|
100
|
-
|
|
182
|
+
Checkout: entry.path,
|
|
183
|
+
Updated: linksPath,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
blankLine();
|
|
187
|
+
paragraph(`'${name}' is read from the versions the lockfile pins again.`);
|
|
188
|
+
|
|
189
|
+
if (flags.update) {
|
|
190
|
+
await this.updatePins(service, name, flags);
|
|
191
|
+
} else {
|
|
192
|
+
await this.reportNewerVersions(service, name);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (flags.remove) {
|
|
196
|
+
fs.rmSync(entry.path, { recursive: true, force: true });
|
|
197
|
+
blankLine();
|
|
198
|
+
paragraph(`The checkout sous cloned at ${entry.path} was deleted.`);
|
|
199
|
+
} else {
|
|
200
|
+
blankLine();
|
|
201
|
+
paragraph(
|
|
202
|
+
entry.origin === "clone"
|
|
203
|
+
? `The checkout sous cloned is still at ${entry.path}.`
|
|
204
|
+
: `The checkout at ${entry.path} was yours to begin with, and has not been touched.`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
footer();
|
|
209
|
+
|
|
210
|
+
if (!flags["no-build"]) await this.rebuildProject(name);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Refuses to delete a checkout sous did not create, or one that is not where
|
|
215
|
+
* sous clones to. The link records its origin; a path-linked checkout belongs
|
|
216
|
+
* to whoever linked it.
|
|
217
|
+
*
|
|
218
|
+
* @param name - The repository's short name.
|
|
219
|
+
* @param entry - The link being removed.
|
|
220
|
+
* @param isGlobal - Whether it is the machine-wide link.
|
|
221
|
+
* @param sousDir - The project's `.sous/` directory.
|
|
222
|
+
*/
|
|
223
|
+
private assertRemovable(
|
|
224
|
+
name: string,
|
|
225
|
+
entry: RepoLink,
|
|
226
|
+
isGlobal: boolean,
|
|
227
|
+
sousDir: string
|
|
228
|
+
): void {
|
|
229
|
+
if (entry.origin !== "clone") {
|
|
230
|
+
throw new ConfigError(
|
|
231
|
+
`Sous did not create the checkout at ${entry.path}, so it will not delete it.\n` +
|
|
232
|
+
` '${name}' was linked to a checkout that was already there. Nothing was ` +
|
|
233
|
+
`changed; unlink without '--remove' to keep the checkout, and delete it ` +
|
|
234
|
+
`yourself if you want it gone.`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const root = isGlobal ? globalReposDir() : projectReposDir(sousDir);
|
|
239
|
+
const relative = path.relative(root, entry.path);
|
|
240
|
+
if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
241
|
+
throw new ConfigError(
|
|
242
|
+
`The checkout at ${entry.path} is not inside ${root}, where sous clones ` +
|
|
243
|
+
`checkouts, so sous will not delete it.\n` +
|
|
244
|
+
` Nothing was changed; unlink without '--remove' and delete it yourself if ` +
|
|
245
|
+
`you want it gone.`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Lists what deleting the checkout would lose, and asks before going on. A
|
|
252
|
+
* checkout with nothing to lose is deleted without a question.
|
|
253
|
+
*
|
|
254
|
+
* @param checkout - The checkout's path.
|
|
255
|
+
* @param work - What an inspection of it found.
|
|
256
|
+
* @param yes - Whether the confirmation flag answered the question already.
|
|
257
|
+
*/
|
|
258
|
+
private async confirmRemoval(
|
|
259
|
+
checkout: string,
|
|
260
|
+
work: UnsavedWork,
|
|
261
|
+
yes: boolean
|
|
262
|
+
): Promise<void> {
|
|
263
|
+
if (hasNoUnsavedWork(work)) return;
|
|
264
|
+
|
|
265
|
+
this.describeUnsavedWork(work);
|
|
266
|
+
if (yes) return;
|
|
267
|
+
|
|
268
|
+
if (!isInteractive()) {
|
|
269
|
+
throw nonInteractiveError({
|
|
270
|
+
prompt: `whether to delete the checkout at ${checkout}, and the work listed above`,
|
|
271
|
+
remedy:
|
|
272
|
+
"pass '--yes' (spelled '-y', '--force' or '-f' if you prefer) to delete it " +
|
|
273
|
+
"without being asked.",
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const proceed = await askYesNo("Delete the checkout, and this work with it?");
|
|
278
|
+
if (!proceed) {
|
|
279
|
+
throw new ConfigError(
|
|
280
|
+
`Nothing was changed: the checkout at ${checkout} was not deleted, and the ` +
|
|
281
|
+
`link is still in place.`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Prints what exists only in the checkout, as a list.
|
|
288
|
+
*
|
|
289
|
+
* @param work - What an inspection of the checkout found.
|
|
290
|
+
*/
|
|
291
|
+
private describeUnsavedWork(work: UnsavedWork): void {
|
|
292
|
+
blankLine();
|
|
293
|
+
warning("The checkout holds work that exists nowhere else, and deleting it loses that work.");
|
|
294
|
+
blankLine();
|
|
295
|
+
|
|
296
|
+
const group = (title: string, items: string[]): void => {
|
|
297
|
+
if (items.length === 0) return;
|
|
298
|
+
log(indent(title));
|
|
299
|
+
for (const item of items) log(indent(`${BULLET} ${item}`, 4));
|
|
300
|
+
blankLine();
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
if (work.unknown !== undefined) {
|
|
304
|
+
group("Sous could not inspect it, so it may hold anything:", [work.unknown]);
|
|
305
|
+
}
|
|
306
|
+
group("Uncommitted changes:", work.uncommitted);
|
|
307
|
+
group("Commits no remote has:", work.unpushed);
|
|
308
|
+
group("Stashes:", work.stashes);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Moves the repository's pins through the same code `sous subscription
|
|
313
|
+
* update` runs. A failure there is reported with the fact that the link is
|
|
314
|
+
* already gone, since that part has happened.
|
|
315
|
+
*
|
|
316
|
+
* @param service - The subscription service.
|
|
317
|
+
* @param name - The repository's short name.
|
|
318
|
+
* @param flags - The confirmation and answer flags.
|
|
319
|
+
*/
|
|
320
|
+
private async updatePins(
|
|
321
|
+
service: SubscriptionService,
|
|
322
|
+
name: string,
|
|
323
|
+
flags: { yes: boolean; answer?: string[]; "answers-file"?: string }
|
|
324
|
+
): Promise<void> {
|
|
325
|
+
blankLine();
|
|
326
|
+
subheading("Updating the pins");
|
|
327
|
+
|
|
328
|
+
const provided = collectProvidedAnswers({
|
|
329
|
+
...(flags.answer === undefined ? {} : { answer: flags.answer }),
|
|
330
|
+
...(flags["answers-file"] === undefined ? {} : { answersFile: flags["answers-file"] }),
|
|
101
331
|
});
|
|
102
332
|
|
|
333
|
+
let outcome;
|
|
334
|
+
try {
|
|
335
|
+
outcome = await service.update({ repo: name, yes: flags.yes, answers: provided });
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (!isConfigError(error)) throw error;
|
|
338
|
+
// The unlink has already happened, so the message says so before the
|
|
339
|
+
// reason the update stopped. A blocked question keeps its kind, so the
|
|
340
|
+
// command's help is still printed under it.
|
|
341
|
+
const message =
|
|
342
|
+
`'${name}' was unlinked, but its pins were not updated.\n` +
|
|
343
|
+
`${(error as ConfigError).message}`;
|
|
344
|
+
throw wantsHelp(error) ? new NonInteractiveError(message) : new ConfigError(message);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (outcome.nothingToUpdate) return;
|
|
348
|
+
|
|
349
|
+
blankLine();
|
|
350
|
+
paragraph("The lockfile now pins the versions listed above.");
|
|
351
|
+
|
|
352
|
+
if (outcome.answers !== undefined) {
|
|
353
|
+
blankLine();
|
|
354
|
+
subheading("Variables");
|
|
355
|
+
for (const line of formatAskReport(outcome.answers)) log(line === "" ? "" : indent(line));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Says whether the repository publishes newer versions the ranges allow,
|
|
361
|
+
* without moving anything. The index is fetched with a short timeout; when it
|
|
362
|
+
* cannot be fetched, that is what is reported.
|
|
363
|
+
*
|
|
364
|
+
* @param service - The subscription service.
|
|
365
|
+
* @param name - The repository's short name.
|
|
366
|
+
*/
|
|
367
|
+
private async reportNewerVersions(service: SubscriptionService, name: string): Promise<void> {
|
|
368
|
+
if (service.currentRepos()[name] === undefined) return;
|
|
369
|
+
|
|
370
|
+
blankLine();
|
|
371
|
+
subheading("Published versions");
|
|
103
372
|
blankLine();
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
373
|
+
|
|
374
|
+
const report = await service.newerPublishedVersions(name);
|
|
375
|
+
if (!report.checked) {
|
|
376
|
+
note(
|
|
377
|
+
`Sous could not check '${name}' for newer published versions. ` +
|
|
378
|
+
`${report.reason.split("\n")[0]!.trim()}`
|
|
379
|
+
);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (report.newer.length === 0) {
|
|
384
|
+
paragraph(
|
|
385
|
+
`Every pin from '${name}' is the newest published version its range allows.`
|
|
386
|
+
);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
paragraph(
|
|
391
|
+
`'${name}' publishes newer versions within range. The lockfile still pins the ` +
|
|
392
|
+
`older ones:`
|
|
109
393
|
);
|
|
394
|
+
blankLine();
|
|
395
|
+
showVariables(
|
|
396
|
+
report.newer.map((entry) => ({
|
|
397
|
+
label: entry.key,
|
|
398
|
+
value: `${entry.from} pinned, ${entry.to} published`,
|
|
399
|
+
}))
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Rebuilds the project, so its outputs come from the pinned versions rather
|
|
405
|
+
* than the checkout when this command returns.
|
|
406
|
+
*
|
|
407
|
+
* @param name - The repository that was unlinked, for the failure message.
|
|
408
|
+
*/
|
|
409
|
+
private async rebuildProject(name: string): Promise<void> {
|
|
410
|
+
await this.reloadDiscoveredConfig();
|
|
411
|
+
|
|
412
|
+
heading("Building the project");
|
|
413
|
+
|
|
414
|
+
const succeeded = await buildProjectOutputs(this.settings, this.configContext);
|
|
110
415
|
|
|
111
416
|
footer();
|
|
417
|
+
|
|
418
|
+
if (!succeeded) {
|
|
419
|
+
throw new ConfigError(
|
|
420
|
+
`'${name}' was unlinked, but the build that followed failed, so this project's ` +
|
|
421
|
+
`outputs may still hold what the checkout contributed. The unlink itself is ` +
|
|
422
|
+
`recorded; fix what the build reported above and run 'sous build' again.`
|
|
423
|
+
);
|
|
424
|
+
}
|
|
112
425
|
}
|
|
113
426
|
|
|
114
427
|
/**
|