@bakers-build/addon-workspace-git 0.9.1-next.5 → 0.9.1-next.6

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.
@@ -4,6 +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
8
  /** Default branch template: `<prefix><key>-<title-slug>` (readable). */
8
9
  export declare const DEFAULT_BRANCH_TEMPLATE = "{branch_prefix}{key}-{title_slug}";
9
10
  /** Runs `git <args>` in a cwd; resolves with stdout when it has one. */
@@ -28,6 +29,10 @@ export interface GitWorkspaceOptions {
28
29
  /** Receives the warning when `branch.autoSetupMerge` cannot be written. */
29
30
  logger?: ConductorLogger;
30
31
  runGit?: GitRunner;
32
+ /** The runtime isolates: a fresh run clone per ensure instead of a linked worktree. */
33
+ clone?: boolean;
34
+ /** Run clones borrow the root's objects (`git clone --shared`). */
35
+ shared?: boolean;
31
36
  }
32
37
  export declare class GitWorkspace implements BbWorkspace {
33
38
  private readonly runGit;
@@ -37,12 +42,14 @@ export declare class GitWorkspace implements BbWorkspace {
37
42
  private readonly branchTemplate;
38
43
  private readonly autoSetupMerge;
39
44
  private readonly logger;
45
+ private readonly clone;
46
+ private readonly shared;
40
47
  constructor(options: GitWorkspaceOptions);
41
48
  /** Render the branch name for a ticket from the configured template. */
42
49
  branchFor(identifier: string, title?: string): string;
43
50
  keyFor(identifier: string): string;
44
51
  private pathFor;
45
- ensure(identifier: string, title?: string, _baseRef?: string): Promise<EnsuredWorkspace>;
52
+ ensure(identifier: string, title?: string, baseRef?: string): Promise<EnsuredWorkspace>;
46
53
  /** Tear down the ticket worktree with git ({@link removeGitWorktree}). */
47
54
  remove(branch: string, worktreePath?: string): Promise<WorktreeTeardown>;
48
55
  }
@@ -51,6 +58,7 @@ export interface GitWorkspaceAddonOptions {
51
58
  branch_prefix?: string;
52
59
  branch_template?: string;
53
60
  auto_setup_merge?: boolean;
61
+ shared?: boolean;
54
62
  }
55
63
  export declare function gitWorkspace(opts?: GitWorkspaceAddonOptions): WorkspacePlugin;
56
64
  export default gitWorkspace;
package/dist/src/index.js CHANGED
@@ -9,10 +9,12 @@ import { deriveCheckoutRoot, exec, slugify, } from '@bakers-build/core';
9
9
  import { runBranchGit } from './git-config.js';
10
10
  import { loadInstructions } from './instructions.js';
11
11
  import { removeGitWorktree } from './remove-git-worktree.js';
12
+ import { ensureRunClone, removeRunCloneWorkspace, targetOf, } from './run-clone.js';
12
13
  export { restoreWritable } from './fs.js';
13
14
  export { pushCurrentEnv, runBranchGit, setNoAutoSetupMerge, } from './git-config.js';
14
15
  export { loadInstructions } from './instructions.js';
15
16
  export { removeGitWorktree, } from './remove-git-worktree.js';
17
+ export { ensureRunClone, removeRunCloneWorkspace, targetOf, } from './run-clone.js';
16
18
  /** Default branch template: `<prefix><key>-<title-slug>` (readable). */
17
19
  export const DEFAULT_BRANCH_TEMPLATE = '{branch_prefix}{key}-{title_slug}';
18
20
  function renderBranchTemplate(template, vars) {
@@ -39,6 +41,8 @@ export class GitWorkspace {
39
41
  branchTemplate;
40
42
  autoSetupMerge;
41
43
  logger;
44
+ clone;
45
+ shared;
42
46
  constructor(options) {
43
47
  this.runGit = options.runGit ?? defaultGitRunner;
44
48
  this.root = resolve(options.root);
@@ -49,6 +53,8 @@ export class GitWorkspace {
49
53
  this.branchTemplate = options.branchTemplate ?? DEFAULT_BRANCH_TEMPLATE;
50
54
  this.autoSetupMerge = options.autoSetupMerge ?? false;
51
55
  this.logger = options.logger;
56
+ this.clone = options.clone ?? false;
57
+ this.shared = options.shared ?? false;
52
58
  }
53
59
  /** Render the branch name for a ticket from the configured template. */
54
60
  branchFor(identifier, title) {
@@ -65,7 +71,7 @@ export class GitWorkspace {
65
71
  pathFor(key) {
66
72
  return resolve(join(this.worktreesRoot, key));
67
73
  }
68
- async ensure(identifier, title, _baseRef) {
74
+ async ensure(identifier, title, baseRef) {
69
75
  const key = this.keyFor(identifier);
70
76
  // Reject empty and dot-leading keys: a dot-leading key would produce an
71
77
  // invalid git ref (e.g. `bakers/.hidden`) and covers '.'/'..' too.
@@ -77,6 +83,47 @@ export class GitWorkspace {
77
83
  ? undefined
78
84
  : await runBranchGit(this.root, this.logger);
79
85
  const extra = env ? { env } : {};
86
+ if (this.clone) {
87
+ const created = !existsSync(path);
88
+ const branch = this.branchFor(identifier, title);
89
+ // Like `worktree add -B` on first use, but an existing branch stays put.
90
+ try {
91
+ await this.runGit([
92
+ '-C',
93
+ this.root,
94
+ 'rev-parse',
95
+ '--verify',
96
+ '--quiet',
97
+ `refs/heads/${branch}`,
98
+ ], this.root);
99
+ }
100
+ catch {
101
+ await this.runGit(['-C', this.root, 'branch', branch], this.root);
102
+ }
103
+ const target = targetOf(baseRef);
104
+ if (target && baseRef?.startsWith('origin/')) {
105
+ try {
106
+ await this.runGit(['-C', this.root, 'fetch', '--quiet', 'origin', '--', target], this.root);
107
+ }
108
+ catch {
109
+ // Offline or no remote: the clone carries the target as last fetched.
110
+ }
111
+ }
112
+ const clone = ensureRunClone({
113
+ parent: this.root,
114
+ workspace: path,
115
+ branch,
116
+ ...(target ? { target } : {}),
117
+ shared: this.shared,
118
+ });
119
+ return {
120
+ path,
121
+ instructions: loadInstructions(path),
122
+ created,
123
+ clone,
124
+ ...extra,
125
+ };
126
+ }
80
127
  if (existsSync(path)) {
81
128
  return {
82
129
  path,
@@ -97,7 +144,10 @@ export class GitWorkspace {
97
144
  };
98
145
  }
99
146
  /** Tear down the ticket worktree with git ({@link removeGitWorktree}). */
100
- remove(branch, worktreePath) {
147
+ async remove(branch, worktreePath) {
148
+ const removed = removeRunCloneWorkspace(worktreePath);
149
+ if (removed)
150
+ return removed;
101
151
  return removeGitWorktree(this.root, branch, worktreePath, async (args, cwd) => (await this.runGit(['-C', cwd, ...args], cwd)) ?? '', this.logger ?? noopLogger);
102
152
  }
103
153
  }
@@ -118,6 +168,8 @@ export function gitWorkspace(opts = {}) {
118
168
  : {}),
119
169
  ...(opts.auto_setup_merge ? { autoSetupMerge: true } : {}),
120
170
  ...(deps?.logger ? { logger: deps.logger } : {}),
171
+ clone: config.runtime?.isolates === true,
172
+ ...(opts.shared ? { shared: true } : {}),
121
173
  });
122
174
  },
123
175
  };
@@ -0,0 +1,14 @@
1
+ import type { WorktreeTeardown } from '@bakers-build/conductor/contract';
2
+ import { type RunClone, type RunCloneOptions } from '@bakers-build/core';
3
+ /**
4
+ * {@link createRunClone}, once more after restoring owner-write when the first
5
+ * refresh fails: a site may have hardened directories it must rewrite.
6
+ */
7
+ export declare function ensureRunClone(options: RunCloneOptions): RunClone;
8
+ /** `origin/<branch>` → `<branch>`: the ref a run clone carries as its target. */
9
+ export declare const targetOf: (baseRef: string | undefined) => string | undefined;
10
+ /**
11
+ * Remove a run clone's directory and Git directory. `undefined` when
12
+ * `worktreePath` is no run clone, so the caller tears down a linked worktree.
13
+ */
14
+ export declare function removeRunCloneWorkspace(worktreePath: string | undefined): WorktreeTeardown | undefined;
@@ -0,0 +1,34 @@
1
+ import { existsSync, rmSync } from 'node:fs';
2
+ import { createRunClone, loadRunClone, removeRunClone, } from '@bakers-build/core';
3
+ import { restoreWritable } from './fs.js';
4
+ /**
5
+ * {@link createRunClone}, once more after restoring owner-write when the first
6
+ * refresh fails: a site may have hardened directories it must rewrite.
7
+ */
8
+ export function ensureRunClone(options) {
9
+ try {
10
+ return createRunClone(options);
11
+ }
12
+ catch (err) {
13
+ if (!existsSync(options.workspace))
14
+ throw err;
15
+ restoreWritable(options.workspace);
16
+ return createRunClone(options);
17
+ }
18
+ }
19
+ /** `origin/<branch>` → `<branch>`: the ref a run clone carries as its target. */
20
+ export const targetOf = (baseRef) => baseRef?.replace(/^origin\//, '');
21
+ /**
22
+ * Remove a run clone's directory and Git directory. `undefined` when
23
+ * `worktreePath` is no run clone, so the caller tears down a linked worktree.
24
+ */
25
+ export function removeRunCloneWorkspace(worktreePath) {
26
+ if (!worktreePath || !loadRunClone(worktreePath))
27
+ return undefined;
28
+ restoreWritable(worktreePath);
29
+ rmSync(worktreePath, { recursive: true, force: true });
30
+ if (existsSync(worktreePath))
31
+ return 'unverified';
32
+ removeRunClone(worktreePath);
33
+ return 'removed';
34
+ }
@@ -18,6 +18,11 @@
18
18
  "type": "boolean",
19
19
  "description": "`false` sets `branch.autoSetupMerge=false` in the root repository before creating a worktree, so run branches have no upstream and push with `push.default=current`; `true` leaves Git alone but does not revert an earlier change.",
20
20
  "default": false
21
+ },
22
+ "shared": {
23
+ "type": "boolean",
24
+ "default": false,
25
+ "description": "Isolating runtimes only: run clones borrow the parent repository's objects (git clone --shared) instead of copying them. Faster and smaller, but never prune or repack the parent with -d while a run is open."
21
26
  }
22
27
  },
23
28
  "additionalProperties": false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-workspace-git",
3
- "version": "0.9.1-next.5",
3
+ "version": "0.9.1-next.6",
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.9.1-next.5",
26
- "@bakers-build/core": "^0.9.1-next.5"
25
+ "@bakers-build/conductor": "^0.9.1-next.6",
26
+ "@bakers-build/core": "^0.9.1-next.6"
27
27
  },
28
28
  "bakersBuild": {
29
- "commit": "d9242cad6cabee1faf010b5d46ac1bac33f6e0a1",
29
+ "commit": "e7d9921d51d5c045f29ca7e35d1e6a348e6ddf08",
30
30
  "channel": "next"
31
31
  }
32
32
  }