@tryglen/cli 0.28.3 → 0.28.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.
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
declare const canonicalRemoteUrl: (raw: string) => string | null;
|
|
2
|
+
/** Outcome of the `rev-parse --show-toplevel` probe that gates every other git
|
|
3
|
+
* field. Reported to the server so a dropped repo/branch ref is attributable. */
|
|
4
|
+
type WorkspaceProbe = "ok" | "not_a_repo" | "git_missing" | "git_timeout" | "git_denied" | "git_empty_output" | "git_failed";
|
|
2
5
|
type WorkspaceContext = {
|
|
3
6
|
readonly cwd?: string;
|
|
4
7
|
readonly repoName?: string;
|
|
5
8
|
readonly branch?: string;
|
|
6
9
|
readonly commit?: string;
|
|
7
10
|
readonly remoteUrl?: string;
|
|
11
|
+
readonly probe?: WorkspaceProbe;
|
|
8
12
|
};
|
|
9
13
|
declare const gitContext: (cwd: string) => WorkspaceContext;
|
|
10
14
|
export { canonicalRemoteUrl, gitContext };
|
|
11
|
-
export type { WorkspaceContext };
|
|
15
|
+
export type { WorkspaceContext, WorkspaceProbe };
|
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { basename } from "node:path";
|
|
3
|
-
const
|
|
3
|
+
const GIT_TIMEOUT_MS = 150;
|
|
4
|
+
const runGit = (cwd, args) => {
|
|
4
5
|
try {
|
|
5
|
-
|
|
6
|
+
const output = execFileSync("git", ["-C", cwd, ...args], {
|
|
6
7
|
stdio: ["ignore", "pipe", "ignore"],
|
|
7
|
-
timeout:
|
|
8
|
+
timeout: GIT_TIMEOUT_MS,
|
|
8
9
|
encoding: "utf8",
|
|
9
|
-
}).trim() || null
|
|
10
|
+
}).trim() || null;
|
|
11
|
+
// Exit 0 with nothing on stdout shouldn't happen for the commands we run;
|
|
12
|
+
// classify it rather than silently folding it into "not a repo".
|
|
13
|
+
return { output, probe: output ? "ok" : "git_empty_output" };
|
|
10
14
|
}
|
|
11
|
-
catch {
|
|
12
|
-
return null;
|
|
15
|
+
catch (error) {
|
|
16
|
+
return { output: null, probe: classifyGitFailure(error) };
|
|
13
17
|
}
|
|
14
18
|
};
|
|
19
|
+
/** Why `git` did not answer. Every one of these currently collapses to the same
|
|
20
|
+
* observable state — a workspace with a cwd and no repoName — and they need
|
|
21
|
+
* completely different responses, so they are reported separately.
|
|
22
|
+
*
|
|
23
|
+
* `git_timeout` is measured, not fixed, here: GIT_TIMEOUT_MS stays at its
|
|
24
|
+
* original value so the logs say whether it is actually being hit before anyone
|
|
25
|
+
* changes it. (`rev-parse --show-toplevel` measures 10-20ms on a 69MB .git, so
|
|
26
|
+
* there is ~10x headroom locally — but that says nothing about a contended
|
|
27
|
+
* machine or a network filesystem.) */
|
|
28
|
+
const classifyGitFailure = (error) => {
|
|
29
|
+
const err = error;
|
|
30
|
+
if (err?.code === "ENOENT")
|
|
31
|
+
return "git_missing";
|
|
32
|
+
if (err?.code === "ETIMEDOUT" || err?.killed === true)
|
|
33
|
+
return "git_timeout";
|
|
34
|
+
if (err?.code === "EACCES")
|
|
35
|
+
return "git_denied";
|
|
36
|
+
// A non-zero exit from `rev-parse --show-toplevel` is git working correctly
|
|
37
|
+
// and telling us this path is not inside a checkout.
|
|
38
|
+
if (typeof err?.status === "number" && err.status !== 0)
|
|
39
|
+
return "not_a_repo";
|
|
40
|
+
return "git_failed";
|
|
41
|
+
};
|
|
42
|
+
const git = (cwd, args) => runGit(cwd, args).output;
|
|
15
43
|
const SSH_PATTERN = /^(?:ssh:\/\/)?[^@]+@([^:/]+)(?::\d+)?[:/](.+?)(?:\.git)?$/;
|
|
16
44
|
const HTTPS_PATTERN = /^https?:\/\/(?:[^@/]+@)?([^/]+)\/(.+?)(?:\.git)?\/?\s*$/;
|
|
17
45
|
const canonicalRemoteUrl = (raw) => {
|
|
@@ -33,9 +61,10 @@ const canonicalRemoteUrl = (raw) => {
|
|
|
33
61
|
return null;
|
|
34
62
|
};
|
|
35
63
|
const gitContext = (cwd) => {
|
|
36
|
-
const
|
|
64
|
+
const top = runGit(cwd, ["rev-parse", "--show-toplevel"]);
|
|
65
|
+
const toplevel = top.output;
|
|
37
66
|
if (!toplevel)
|
|
38
|
-
return { cwd };
|
|
67
|
+
return { cwd, probe: top.probe };
|
|
39
68
|
const branch = git(cwd, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
40
69
|
const commit = git(cwd, ["rev-parse", "--short", "HEAD"]);
|
|
41
70
|
const trackingRemote = branch && branch !== "HEAD"
|
|
@@ -48,6 +77,7 @@ const gitContext = (cwd) => {
|
|
|
48
77
|
const normalized = remote ? canonicalRemoteUrl(remote) : null;
|
|
49
78
|
return {
|
|
50
79
|
cwd,
|
|
80
|
+
probe: "ok",
|
|
51
81
|
repoName: basename(toplevel),
|
|
52
82
|
...(branch ? { branch } : {}),
|
|
53
83
|
...(commit ? { commit } : {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-context.js","sourceRoot":"","sources":["../../src/_utils/git-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,GAAG,GAAG,CAAC,GAAW,
|
|
1
|
+
{"version":3,"file":"git-context.js","sourceRoot":"","sources":["../../src/_utils/git-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B,MAAM,MAAM,GAAG,CACb,GAAW,EACX,IAAc,EACoC,EAAE;IACpD,IAAI,CAAC;QACH,MAAM,MAAM,GACV,YAAY,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE;YACxC,KAAK,EAAE,CAAC,QAA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