GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(shared): share the cwd snapshot with PATH searches and launch the… · pingdotgg/t3code@81e9154

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/shared/src
    • shell.test.ts
    • shell.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/shared/src/shell.test.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/shell.test.ts
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,13 +894,17 @@ console.log(JSON.stringify({ resolved, resolvedGit }));
894894
];
895895
const gitEntries = ["", "."].flatMap((entry) => {
896896
const PATH = `${entry}:${listed}`;
897+
// An empty entry launches the local git it found; "." keeps its relative spelling.
898+
const localGit = entry === "" ? path.join(cwd, "git") : "git";
897899
return [
898900
{ PATH, cwd: empty, cacheGroup: `xcode-first-${entry}`, expected: xcodeGit },
899-
{ PATH, cwd, cacheGroup: `xcode-first-${entry}`, expected: "git" },
900-
{ PATH, cwd, cacheGroup: `local-first-${entry}`, expected: "git" },
901+
{ PATH, cwd, cacheGroup: `xcode-first-${entry}`, expected: localGit },
902+
{ PATH, cwd, cacheGroup: `local-first-${entry}`, expected: localGit },
901903
{ PATH, cwd: empty, cacheGroup: `local-first-${entry}`, expected: xcodeGit },
902904
];
903905
});
906+
// A match from an absolute entry stays bare `git`, even when PATH also has a relative entry.
907+
gitEntries.push({ PATH: `.:${cwd}`, cwd: empty, cacheGroup: "absolute", expected: "git" });
904908
const stdout = NodeChildProcess.execFileSync(
905909
process.execPath,
906910
[
Collapse file

‎packages/shared/src/shell.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/shell.ts
+15-6Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -801,10 +801,11 @@ const findOnPath = Effect.fnUntraced(function* (
801801
platform: NodeJS.Platform,
802802
windowsPathExtensions: ReadonlyArray<string>,
803803
isLast: (match: string) => boolean,
804+
// The caller's snapshot, so a cache key and the search it stores agree on the directory.
805+
cwd: string | null | undefined,
804806
): Effect.fn.Return<ReadonlyArray<string>, never, FileSystem.FileSystem | Path.Path> {
805807
const path = yield* Path.Path;
806808
const pathEntries = pathEntriesForPlatform(pathValue, platform);
807-
const cwd = pathSearchCwd(pathValue, platform);
808809

809810
// A match through an empty component is anchored: callers may launch it from another cwd or
810811
// through a wrapper. A literal "." keeps its relative spelling; the first of the two wins, as
@@ -894,6 +895,7 @@ const resolveCommandPathForPlatform = Effect.fn("shell.resolveCommandPathForPlat
894895
platform,
895896
windowsPathExtensions,
896897
() => true,
898+
cwd,
897899
);
898900
if (cwd !== null) cacheCommandResolution(cache, cacheKey, resolvedPath, nowNanos);
899901
return resolvedPath;
@@ -918,12 +920,14 @@ export const resolveCommandPaths = Effect.fn("shell.resolveCommandPaths")(functi
918920
const platform = yield* HostProcess.Platform;
919921
const env = options.env ?? (yield* HostProcess.Environment);
920922
const windowsPathExtensions = platform === "win32" ? resolveWindowsPathExtensions(env) : [];
923+
const pathValue = resolvePathEnvironmentVariable(env);
921924
return yield* findOnPath(
922-
resolvePathEnvironmentVariable(env),
925+
pathValue,
923926
resolveCommandCandidates(command, platform, windowsPathExtensions, path.extname),
924927
platform,
925928
windowsPathExtensions,
926929
options.until,
930+
pathSearchCwd(pathValue, platform),
927931
);
928932
});
929933

@@ -1050,6 +1054,8 @@ const resolveMacosGit = Effect.fnUntraced(function* (
10501054
const locateXcodeGit = yield* XcodeGitLocation;
10511055
const cache = yield* CommandResolutionCache;
10521056
const pathValue = resolvePathEnvironmentVariable(env);
1057+
const nowNanos = yield* Clock.currentTimeNanos;
1058+
// Read after the clock, so the synchronous lookup below searches the directory the key names.
10531059
const cwd = pathSearchCwd(pathValue, "darwin");
10541060
const cacheKey = [
10551061
"xcode-git",
@@ -1059,7 +1065,6 @@ const resolveMacosGit = Effect.fnUntraced(function* (
10591065
env.DEVELOPER_DIR ?? "",
10601066
...(cwd === undefined ? [] : [cwd]),
10611067
].join(COMMAND_RESOLUTION_CACHE_KEY_SEPARATOR);
1062-
const nowNanos = yield* Clock.currentTimeNanos;
10631068
const cached = cwd === null ? undefined : cache.get(cacheKey);
10641069
// An Xcode update or removal deletes the binary; look again instead of failing the spawn.
10651070
if (
@@ -1070,12 +1075,16 @@ const resolveMacosGit = Effect.fnUntraced(function* (
10701075
) {
10711076
return cached.resolvedPath ?? "git";
10721077
}
1073-
const located =
1074-
resolveExecutable("git", "darwin", env) === MACOS_GIT_SHIM ? locateXcodeGit(env) : undefined;
1078+
const pathGit = resolveExecutable("git", "darwin", env);
1079+
const located = pathGit === MACOS_GIT_SHIM ? locateXcodeGit(env) : undefined;
10751080
const realGit =
10761081
located !== undefined && resolveExecutable(located, "darwin", env) !== undefined
10771082
? located
1078-
: null;
1083+
: // A match anchored to the cwd came through an empty PATH entry, which a child would search
1084+
// again from its own cwd; launch the file that was checked instead of bare `git`.
1085+
typeof cwd === "string" && pathGit === NodePath.posix.join(cwd, "git")
1086+
? pathGit
1087+
: null;
10791088
if (cwd !== null) cacheCommandResolution(cache, cacheKey, realGit, nowNanos);
10801089
return realGit ?? "git";
10811090
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.