@able-autonomy/able 0.0.17 → 0.0.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/package.json +1 -1
- package/src/workspaces/new.ts +23 -14
package/package.json
CHANGED
package/src/workspaces/new.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
// able ws new <slug> [--brief] [--no-fetch]: a worktree on `feat/<slug>` cut from origin's trunk, in `workspaces.dir`,
|
|
2
|
-
// what a worktree can't inherit: the host's `copy` files and its `onCreate` commands, with this workspace's facts
|
|
3
|
-
// `ABLE_WS_*`. Services are not started: `able ws start` does that. Every check runs before anything is created.
|
|
1
|
+
// able ws new <slug> [--no-brief] [--no-fetch]: a worktree on `feat/<slug>` cut from origin's trunk, in `workspaces.dir`,
|
|
2
|
+
// then what a worktree can't inherit: the host's `copy` files and its `onCreate` commands, with this workspace's facts
|
|
3
|
+
// in `ABLE_WS_*`. Services are not started: `able ws start` does that. Every check runs before anything is created.
|
|
4
4
|
//
|
|
5
|
-
//
|
|
6
|
-
// it
|
|
7
|
-
//
|
|
5
|
+
// The workspace's brief, `<journal>/workspaces/<slug>.md`, is published first when origin's trunk doesn't carry it as
|
|
6
|
+
// the main checkout has it: the file alone is committed after its checks (when it has changes) and the trunk pushed, so
|
|
7
|
+
// the cut carries it. Already on origin as it is here: nothing to publish. Nowhere: refused, unless `--no-brief`.
|
|
8
|
+
// Running it again after a failure picks up where it stopped: a brief committed but not pushed is pushed, since the
|
|
9
|
+
// only unpushed changes it allows are the brief's own. `--brief`, the old way to ask for this, is still accepted.
|
|
8
10
|
|
|
9
11
|
import { copyFileSync, existsSync, mkdirSync } from 'node:fs'
|
|
10
12
|
import { dirname, join, relative, resolve } from 'node:path'
|
|
11
13
|
import { loadConfig, trailerArgs } from '../../config.ts'
|
|
12
14
|
import { runChecks } from '../checks.ts'
|
|
13
|
-
import { count, failOnMerge, fetchTrunk, git, gitLoud, mainRoot } from '../git.ts'
|
|
15
|
+
import { count, failOnMerge, fetchTrunk, git, gitLoud, gitQuiet, lines, mainRoot } from '../git.ts'
|
|
14
16
|
import { runCommand } from '../run.ts'
|
|
15
17
|
import { status, working } from '../status.ts'
|
|
16
18
|
import { bold, dim, fail, green, yellow } from '../ui.ts'
|
|
@@ -18,7 +20,7 @@ import { branchOf, readState, workspaces, writeState } from './state.ts'
|
|
|
18
20
|
|
|
19
21
|
const args = process.argv.slice(4)
|
|
20
22
|
const slug = args.find((a) => !a.startsWith('-'))
|
|
21
|
-
if (!slug) fail('usage: able ws new <slug> [--brief] [--no-fetch]')
|
|
23
|
+
if (!slug) fail('usage: able ws new <slug> [--no-brief] [--no-fetch]')
|
|
22
24
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) fail(`invalid name '${slug}': lowercase letters, digits and dashes only`)
|
|
23
25
|
|
|
24
26
|
const main = mainRoot()
|
|
@@ -43,15 +45,22 @@ if (!args.includes('--no-fetch')) {
|
|
|
43
45
|
fetchTrunk(main, config.trunk)
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const { trunk, journal } = config
|
|
49
|
+
const file = `${journal}/workspaces/${slug}.md`
|
|
50
|
+
const local = existsSync(join(main, file))
|
|
51
|
+
const onOrigin = gitQuiet(main, 'cat-file', '-e', `origin/${trunk}:${file}`)
|
|
52
|
+
// Untracked, edited, or committed differently from origin's trunk: the cut wouldn't carry it as it is here.
|
|
53
|
+
const differs = local && (Boolean(git(main, 'status', '--porcelain', '--', file)) || !gitQuiet(main, 'diff', '--quiet', `origin/${trunk}`, '--', file))
|
|
54
|
+
if (!local && !onOrigin && !args.includes('--no-brief')) fail(`no brief at ${file}; write it first, or pass --no-brief for a workspace without one`)
|
|
55
|
+
|
|
56
|
+
if (differs) {
|
|
50
57
|
if (git(main, 'rev-parse', '--abbrev-ref', 'HEAD') !== trunk) fail(`the main checkout is not on ${trunk}`)
|
|
51
58
|
failOnMerge(main)
|
|
52
59
|
step('publishing the brief')
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
// Unpushed work other than the brief would leave with it. The brief's own commit (a run that stopped before its
|
|
61
|
+
// push) is fine: this run pushes it.
|
|
62
|
+
const others = lines(main, 'diff', '--name-only', `origin/${trunk}...${trunk}`).filter((f) => f !== file)
|
|
63
|
+
if (others.length) fail(`${trunk} has unpushed changes that would leave with the brief:\n${git(main, 'log', '--oneline', `origin/${trunk}..${trunk}`)}`)
|
|
55
64
|
if (git(main, 'status', '--porcelain', '--', file)) {
|
|
56
65
|
const at = { slug: 'main', path: main, portOffset: 0, main }
|
|
57
66
|
if (!runChecks(config, [file], at)) fail('a check failed; nothing committed')
|