poe-code 3.0.366 → 3.0.367

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "3.0.366",
3
+ "version": "3.0.367",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -8,3 +8,4 @@ export declare function buildCloneUrl(locator: Extract<ParsedLocator, {
8
8
  export declare function cloneOrUpdate(locator: Extract<ParsedLocator, {
9
9
  scheme: "github";
10
10
  }>, options: WorkspaceResolverOptions): Promise<string>;
11
+ export declare function fetchRef(cacheDir: string, ref: string, options: WorkspaceResolverOptions): Promise<void>;
@@ -23,11 +23,14 @@ export async function cloneOrUpdate(locator, options) {
23
23
  }
24
24
  }
25
25
  if (locator.ref) {
26
- await assertExecSuccess(await options.exec("git", ["fetch", "origin"], { cwd: cacheDir }), "git fetch failed");
27
- await assertExecSuccess(await options.exec("git", ["checkout", "--", locator.ref], { cwd: cacheDir }), "git checkout failed");
26
+ await fetchRef(cacheDir, locator.ref, options);
27
+ await assertExecSuccess(await options.exec("git", ["checkout", "FETCH_HEAD", "--"], { cwd: cacheDir }), "git checkout failed");
28
28
  }
29
29
  return cacheDir;
30
30
  }
31
+ export async function fetchRef(cacheDir, ref, options) {
32
+ await assertExecSuccess(await options.exec("git", ["fetch", "origin", "--", ref], { cwd: cacheDir }), "git fetch failed");
33
+ }
31
34
  async function pathExists(fs, target) {
32
35
  try {
33
36
  await fs.stat(target);
@@ -7,9 +7,15 @@ export async function createWritableCheckout(locator, sourceCwd, options) {
7
7
  await assertPathHasNoSymbolicLinks(options.fs, cwd);
8
8
  await options.fs.mkdir(path.dirname(cwd), { recursive: true });
9
9
  await assertPathHasNoSymbolicLinks(options.fs, cwd);
10
- await assertExecSuccess(await options.exec("git", ["worktree", "add", "--detach", cwd, revision], {
11
- cwd: sourceCwd
12
- }), "git worktree add failed");
10
+ try {
11
+ await assertExecSuccess(await options.exec("git", ["worktree", "add", "--detach", cwd, revision], {
12
+ cwd: sourceCwd
13
+ }), "git worktree add failed");
14
+ }
15
+ catch (error) {
16
+ await removeCheckout(cwd, sourceCwd, options).catch(() => undefined);
17
+ throw error;
18
+ }
13
19
  try {
14
20
  await options.fs.mkdir(cwd, { recursive: true });
15
21
  }
@@ -1,13 +1,15 @@
1
1
  import path from "node:path";
2
2
  import { hasOwnErrorCode } from "./error-codes.js";
3
- import { cloneOrUpdate } from "./github/clone.js";
3
+ import { cloneOrUpdate, fetchRef } from "./github/clone.js";
4
4
  import { createWritableCheckout } from "./github/isolation.js";
5
5
  import { parseLocator } from "./parse.js";
6
6
  export async function resolveWorkspace(input, options) {
7
7
  const locator = parseLocator(input);
8
8
  if (locator.scheme === "local") {
9
+ const cwd = path.isAbsolute(locator.path) ? locator.path : path.resolve(options.baseDir, locator.path);
10
+ await assertPathExists(options.fs, cwd, cwd, locator);
9
11
  return {
10
- cwd: path.isAbsolute(locator.path) ? locator.path : path.resolve(options.baseDir, locator.path),
12
+ cwd,
11
13
  locator
12
14
  };
13
15
  }
@@ -18,11 +20,17 @@ export async function resolveWorkspace(input, options) {
18
20
  const needsIsolatedCheckout = mode === "edit" || mode === "auto" || (mode === "read" && locator.ref !== undefined);
19
21
  const cacheLocator = needsIsolatedCheckout ? { ...locator, ref: undefined } : locator;
20
22
  const cacheDir = await cloneOrUpdate(cacheLocator, options);
23
+ const checkoutLocator = needsIsolatedCheckout && locator.ref !== undefined
24
+ ? { ...locator, ref: "FETCH_HEAD" }
25
+ : locator;
21
26
  let writable;
22
27
  try {
28
+ if (needsIsolatedCheckout && locator.ref !== undefined) {
29
+ await fetchRef(cacheDir, locator.ref, options);
30
+ }
23
31
  writable =
24
32
  needsIsolatedCheckout
25
- ? await createWritableCheckout(locator, cacheDir, options)
33
+ ? await createWritableCheckout(checkoutLocator, cacheDir, options)
26
34
  : undefined;
27
35
  const workspaceRoot = writable?.cwd ?? cacheDir;
28
36
  const cwd = locator.subdir ? path.join(workspaceRoot, locator.subdir) : workspaceRoot;