@bakers-build/addon-workspace-git 0.11.1-next.2 → 0.11.1-next.4
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/dist/src/index.d.ts +5 -2
- package/dist/src/index.js +6 -5
- package/dist/src/run-clone.d.ts +6 -0
- package/dist/src/run-clone.js +22 -1
- package/package.json +4 -4
package/dist/src/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { restoreWritable } from './fs.js';
|
|
|
4
4
|
export { pushCurrentEnv, runBranchGit, setNoAutoSetupMerge, } from './git-config.js';
|
|
5
5
|
export { loadInstructions } from './instructions.js';
|
|
6
6
|
export { removeGitWorktree, type WorktreeGitExec, } from './remove-git-worktree.js';
|
|
7
|
-
export { ensureRunClone, removeRunCloneWorkspace, targetOf, } from './run-clone.js';
|
|
7
|
+
export { ensureRunClone, leaveRunClone, removeRunCloneWorkspace, targetOf, } from './run-clone.js';
|
|
8
8
|
export declare const DEFAULT_WORKTREE_DIR = ".bakers-worktrees";
|
|
9
9
|
/** Runs `git <args>` in a cwd; resolves with stdout when it has one. */
|
|
10
10
|
export type GitRunner = (args: string[], cwd: string) => Promise<string | undefined>;
|
|
@@ -40,7 +40,10 @@ export declare class GitWorkspace implements BbWorkspace {
|
|
|
40
40
|
* is unused: the conductor passes the ticket's `branch_name`, which push and
|
|
41
41
|
* PR use, so the workspace never renders a branch of its own.
|
|
42
42
|
*/
|
|
43
|
-
ensure(_identifier: string, branch?: string, baseRef?: string
|
|
43
|
+
ensure(_identifier: string, branch?: string, baseRef?: string, options?: {
|
|
44
|
+
clone?: boolean;
|
|
45
|
+
shared?: boolean;
|
|
46
|
+
}): Promise<EnsuredWorkspace>;
|
|
44
47
|
/** Create `branch` at the root's HEAD unless it exists; an existing one stays put. */
|
|
45
48
|
private ensureBranch;
|
|
46
49
|
/** Tear down the ticket worktree with git ({@link removeGitWorktree}). */
|
package/dist/src/index.js
CHANGED
|
@@ -9,12 +9,12 @@ import { deriveCheckoutRoot, exec, } from '@bakers-build/core';
|
|
|
9
9
|
import { runBranchGit } from './git-config.js';
|
|
10
10
|
import { loadInstructions } from './instructions.js';
|
|
11
11
|
import { removeGitWorktree, ticketWorktrees } from './remove-git-worktree.js';
|
|
12
|
-
import { ensureRunClone, removeRunCloneWorkspace, targetOf, } from './run-clone.js';
|
|
12
|
+
import { ensureRunClone, leaveRunClone, removeRunCloneWorkspace, targetOf, } from './run-clone.js';
|
|
13
13
|
export { restoreWritable } from './fs.js';
|
|
14
14
|
export { pushCurrentEnv, runBranchGit, setNoAutoSetupMerge, } from './git-config.js';
|
|
15
15
|
export { loadInstructions } from './instructions.js';
|
|
16
16
|
export { removeGitWorktree, } from './remove-git-worktree.js';
|
|
17
|
-
export { ensureRunClone, removeRunCloneWorkspace, targetOf, } from './run-clone.js';
|
|
17
|
+
export { ensureRunClone, leaveRunClone, removeRunCloneWorkspace, targetOf, } from './run-clone.js';
|
|
18
18
|
// shortcut: one default for all executors, upgrade when an executor needs another value.
|
|
19
19
|
export const DEFAULT_WORKTREE_DIR = '.bakers-worktrees';
|
|
20
20
|
const defaultGitRunner = (args, cwd) => exec('git', args, { cwd });
|
|
@@ -46,7 +46,7 @@ export class GitWorkspace {
|
|
|
46
46
|
* is unused: the conductor passes the ticket's `branch_name`, which push and
|
|
47
47
|
* PR use, so the workspace never renders a branch of its own.
|
|
48
48
|
*/
|
|
49
|
-
async ensure(_identifier, branch, baseRef) {
|
|
49
|
+
async ensure(_identifier, branch, baseRef, options) {
|
|
50
50
|
if (!branch)
|
|
51
51
|
throw new Error('git workspace requires a branch name');
|
|
52
52
|
// A ref git accepts has no `..`, leading `/`, `-` or `.`, so the path
|
|
@@ -66,7 +66,7 @@ export class GitWorkspace {
|
|
|
66
66
|
? undefined
|
|
67
67
|
: await runBranchGit(this.root, this.logger);
|
|
68
68
|
const extra = env ? { env } : {};
|
|
69
|
-
if (this.clone) {
|
|
69
|
+
if (options?.clone ?? this.clone) {
|
|
70
70
|
const created = !existsSync(path);
|
|
71
71
|
await this.ensureBranch(branch);
|
|
72
72
|
const target = targetOf(baseRef);
|
|
@@ -83,7 +83,7 @@ export class GitWorkspace {
|
|
|
83
83
|
workspace: path,
|
|
84
84
|
branch,
|
|
85
85
|
...(target ? { target } : {}),
|
|
86
|
-
shared: this.shared,
|
|
86
|
+
shared: options?.shared ?? this.shared,
|
|
87
87
|
});
|
|
88
88
|
return {
|
|
89
89
|
path,
|
|
@@ -93,6 +93,7 @@ export class GitWorkspace {
|
|
|
93
93
|
...extra,
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
+
leaveRunClone(path);
|
|
96
97
|
// Reuse the branch's worktree wherever it lives: old `<root>-worktrees/`
|
|
97
98
|
// checkouts keep working and are never moved.
|
|
98
99
|
const listed = await this.runGit(['-C', this.root, 'worktree', 'list', '--porcelain'], this.root);
|
package/dist/src/run-clone.d.ts
CHANGED
|
@@ -12,3 +12,9 @@ export declare const targetOf: (baseRef: string | undefined) => string | undefin
|
|
|
12
12
|
* `worktreePath` is no run clone, so the caller tears down a linked worktree.
|
|
13
13
|
*/
|
|
14
14
|
export declare function removeRunCloneWorkspace(worktreePath: string | undefined): WorktreeTeardown | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Leave a run clone for a run that does not isolate: bring its commits to the
|
|
17
|
+
* ticket branch, refuse uncommitted work, then remove the clone so the caller
|
|
18
|
+
* adds a linked worktree at the same path. No-op when `workspace` is no clone.
|
|
19
|
+
*/
|
|
20
|
+
export declare function leaveRunClone(workspace: string): void;
|
package/dist/src/run-clone.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import { existsSync, rmSync } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { createRunClone, loadRunClone, registerRunCloneWorktree, removeRunClone, saveRunClone, transferIsolatedCommit, } from '@bakers-build/core';
|
|
3
5
|
import { restoreWritable } from './fs.js';
|
|
4
6
|
/**
|
|
5
7
|
* {@link createRunClone}, once more after restoring owner-write when the first
|
|
@@ -32,3 +34,22 @@ export function removeRunCloneWorkspace(worktreePath) {
|
|
|
32
34
|
removeRunClone(worktreePath);
|
|
33
35
|
return 'removed';
|
|
34
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Leave a run clone for a run that does not isolate: bring its commits to the
|
|
39
|
+
* ticket branch, refuse uncommitted work, then remove the clone so the caller
|
|
40
|
+
* adds a linked worktree at the same path. No-op when `workspace` is no clone.
|
|
41
|
+
*/
|
|
42
|
+
export function leaveRunClone(workspace) {
|
|
43
|
+
const record = loadRunClone(workspace);
|
|
44
|
+
if (!record)
|
|
45
|
+
return;
|
|
46
|
+
const tip = transferIsolatedCommit(record);
|
|
47
|
+
saveRunClone({ ...record, expected: tip });
|
|
48
|
+
// Registered, host Git reads the work tree with the host's overrides, never the run's config.
|
|
49
|
+
registerRunCloneWorktree({ ...record, expected: tip });
|
|
50
|
+
const changes = execFileSync('git', ['--git-dir', join(workspace, '.git'), 'status', '--porcelain'], { cwd: workspace, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
51
|
+
if (changes)
|
|
52
|
+
throw new Error(`run clone: ${workspace} has uncommitted work; commit or remove it, then dispatch again`);
|
|
53
|
+
if (removeRunCloneWorkspace(workspace) !== 'removed')
|
|
54
|
+
throw new Error(`run clone: ${workspace} could not be removed`);
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/addon-workspace-git",
|
|
3
|
-
"version": "0.11.1-next.
|
|
3
|
+
"version": "0.11.1-next.4",
|
|
4
4
|
"description": "bakers.build conductor workspace addon: plain git-worktree workspace + the WORKFLOW.md instruction loader.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"directory": "bakers-cli/addons/workspace-git"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@bakers-build/conductor": "^0.11.1-next.
|
|
26
|
-
"@bakers-build/core": "^0.11.1-next.
|
|
25
|
+
"@bakers-build/conductor": "^0.11.1-next.4",
|
|
26
|
+
"@bakers-build/core": "^0.11.1-next.4"
|
|
27
27
|
},
|
|
28
28
|
"bakersBuild": {
|
|
29
|
-
"commit": "
|
|
29
|
+
"commit": "567bf12252184152b86d67a8a083d09755d29e0b",
|
|
30
30
|
"channel": "next"
|
|
31
31
|
}
|
|
32
32
|
}
|