@jwilger/pi-development-system 0.8.6 → 0.8.8
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,12 +1,17 @@
|
|
|
1
1
|
import { splitLines } from "./git-intent.ts";
|
|
2
|
-
import { resolveGit } from "./git-invocations.ts";
|
|
2
|
+
import { opaqueMentions, resolveGit } from "./git-invocations.ts";
|
|
3
3
|
import { stripHeredocs } from "./heredoc.ts";
|
|
4
4
|
|
|
5
5
|
export type CommitExtraction =
|
|
6
6
|
| { readonly kind: "not-commit" }
|
|
7
7
|
| { readonly kind: "message"; readonly message: string }
|
|
8
8
|
| { readonly kind: "file"; readonly path: string }
|
|
9
|
-
| {
|
|
9
|
+
| {
|
|
10
|
+
readonly kind: "unknown";
|
|
11
|
+
readonly trailers: readonly string[];
|
|
12
|
+
/** A `-m` value is a substitution or variable: the message exists but cannot be read. */
|
|
13
|
+
readonly opaqueMessage: boolean;
|
|
14
|
+
};
|
|
10
15
|
|
|
11
16
|
type Options = {
|
|
12
17
|
messages: string[];
|
|
@@ -77,9 +82,10 @@ function readOptions(args: readonly string[]): Options {
|
|
|
77
82
|
return options;
|
|
78
83
|
}
|
|
79
84
|
|
|
80
|
-
const unknown = (trailers: readonly string[] = []): CommitExtraction => ({
|
|
85
|
+
const unknown = (trailers: readonly string[] = [], opaqueMessage = false): CommitExtraction => ({
|
|
81
86
|
kind: "unknown",
|
|
82
87
|
trailers,
|
|
88
|
+
opaqueMessage,
|
|
83
89
|
});
|
|
84
90
|
|
|
85
91
|
const STDIN_PATHS = new Set(["-", "/dev/stdin", "/proc/self/fd/0"]);
|
|
@@ -104,7 +110,7 @@ function extractOne(args: readonly string[], heredoc: string | undefined): Commi
|
|
|
104
110
|
if (options.file !== undefined) return { kind: "file", path: options.file };
|
|
105
111
|
const parts = [...options.messages];
|
|
106
112
|
if (options.opaque) {
|
|
107
|
-
if (heredoc === undefined) return unknown(options.trailers);
|
|
113
|
+
if (heredoc === undefined) return unknown(options.trailers, true);
|
|
108
114
|
parts.push(heredoc);
|
|
109
115
|
}
|
|
110
116
|
if (parts.length === 0) return unknown(options.trailers);
|
|
@@ -120,7 +126,7 @@ export function extractCommits(command: string): CommitExtraction[] {
|
|
|
120
126
|
const found = resolution.invocations.flatMap((g) =>
|
|
121
127
|
g.sub === "commit" ? [extractOne(g.args, heredocFrom(lines, g.line, bodies))] : [],
|
|
122
128
|
);
|
|
123
|
-
const hidden = resolution
|
|
129
|
+
const hidden = opaqueMentions(resolution, "commit");
|
|
124
130
|
return hidden ? [...found, unknown()] : found;
|
|
125
131
|
}
|
|
126
132
|
|
|
@@ -27,12 +27,13 @@ export type GitInvocation = {
|
|
|
27
27
|
export type GitResolution = {
|
|
28
28
|
readonly invocations: readonly GitInvocation[];
|
|
29
29
|
/** True when git may run through something the parser cannot see into (xargs, `$CMD`, …). */
|
|
30
|
-
|
|
30
|
+
/** Words of segments that may run git in a way that cannot be read (`$GIT push`, `xargs git …`). */
|
|
31
|
+
readonly opaque: readonly string[];
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
type Collector = {
|
|
34
35
|
invocations: GitInvocation[];
|
|
35
|
-
opaque:
|
|
36
|
+
opaque: string[];
|
|
36
37
|
dir: string | undefined;
|
|
37
38
|
line: number;
|
|
38
39
|
};
|
|
@@ -58,7 +59,7 @@ function visitGit(rest: readonly string[], into: Collector): void {
|
|
|
58
59
|
}
|
|
59
60
|
const sub = rest[j];
|
|
60
61
|
if (sub === undefined) return;
|
|
61
|
-
if (sub.startsWith("$")) into.opaque
|
|
62
|
+
if (sub.startsWith("$")) into.opaque.push(...rest);
|
|
62
63
|
else {
|
|
63
64
|
const args = rest.slice(j + 1);
|
|
64
65
|
const line = into.line;
|
|
@@ -89,11 +90,12 @@ function visitSegment(tokens: readonly string[], into: Collector): void {
|
|
|
89
90
|
if (head === undefined) return;
|
|
90
91
|
const rest = tokens.slice(firstCommand(tokens) + 1);
|
|
91
92
|
const base = basename(head);
|
|
92
|
-
if (head.startsWith("$")) into.opaque
|
|
93
|
+
if (head.startsWith("$")) into.opaque.push(...tokens);
|
|
93
94
|
else if (base === "cd") visitCd(rest, into);
|
|
94
95
|
else if (SHELLS.has(base) || base === "eval") visitScript(base, rest, into);
|
|
95
|
-
else if (OPAQUE.has(base))
|
|
96
|
-
|
|
96
|
+
else if (OPAQUE.has(base)) {
|
|
97
|
+
if (gitIndex(rest) >= 0) into.opaque.push(...rest);
|
|
98
|
+
} else if (base === "git") visitGit(rest, into);
|
|
97
99
|
else visitWrapped(base, rest, into);
|
|
98
100
|
}
|
|
99
101
|
|
|
@@ -105,7 +107,7 @@ function visitWrapped(base: string, rest: readonly string[], into: Collector): v
|
|
|
105
107
|
|
|
106
108
|
function merge(into: Collector, other: GitResolution): void {
|
|
107
109
|
into.invocations.push(...other.invocations.map((g) => ({ ...g, line: into.line })));
|
|
108
|
-
|
|
110
|
+
into.opaque.push(...other.opaque);
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
/**
|
|
@@ -113,7 +115,7 @@ function merge(into: Collector, other: GitResolution): void {
|
|
|
113
115
|
* `timeout`, `if … then`), `bash -c`/`eval` scripts and `$(…)` substitutions. Heredoc bodies are data.
|
|
114
116
|
*/
|
|
115
117
|
export function resolveGit(command: string): GitResolution {
|
|
116
|
-
const into: Collector = { invocations: [], opaque:
|
|
118
|
+
const into: Collector = { invocations: [], opaque: [], dir: undefined, line: 0 };
|
|
117
119
|
let heredocEnd: string | undefined;
|
|
118
120
|
// Heredoc bodies are data (an apostrophe in one must not unbalance quote tracking).
|
|
119
121
|
const lines = splitLines(stripHeredocs(command).rest);
|
|
@@ -129,3 +131,7 @@ export function resolveGit(command: string): GitResolution {
|
|
|
129
131
|
}
|
|
130
132
|
return into;
|
|
131
133
|
}
|
|
134
|
+
|
|
135
|
+
/** Whether something unreadable in the command may be running `git <subcommand>`. */
|
|
136
|
+
export const opaqueMentions = (resolution: GitResolution, subcommand: string): boolean =>
|
|
137
|
+
resolution.opaque.includes(subcommand);
|
package/src/core/push-command.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveGit } from "./git-invocations.ts";
|
|
1
|
+
import { opaqueMentions, resolveGit } from "./git-invocations.ts";
|
|
2
2
|
|
|
3
3
|
export type PushTarget = {
|
|
4
4
|
readonly remote: string | undefined;
|
|
@@ -73,7 +73,7 @@ export function pushTargets(command: string): PushTarget[] {
|
|
|
73
73
|
g.sub === "push" && !isDryRun(g.args) ? [toTarget(g.args, g.dir)] : [],
|
|
74
74
|
);
|
|
75
75
|
// git run through something opaque (xargs, `$CMD`): a push cannot be ruled out, so assume the worst.
|
|
76
|
-
const opaquePush = resolution
|
|
76
|
+
const opaquePush = opaqueMentions(resolution, "push");
|
|
77
77
|
return opaquePush
|
|
78
78
|
? [
|
|
79
79
|
...targets,
|
|
@@ -170,6 +170,12 @@ export function registerCommitGuard(deps: CommitGuardDeps): void {
|
|
|
170
170
|
why: "the message file cannot be read before the commit runs, so its rationale cannot be checked; use -m or a heredoc",
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
|
+
if (extractions.some((e) => e.kind === "unknown" && e.opaqueMessage)) {
|
|
174
|
+
all.push({
|
|
175
|
+
gate: RATIONALE,
|
|
176
|
+
why: "the message is built by a substitution or variable and cannot be checked; use a literal -m or a heredoc",
|
|
177
|
+
});
|
|
178
|
+
}
|
|
173
179
|
for (const message of known) {
|
|
174
180
|
for (const need of await needsOf(deps, ctx, message, command)) {
|
|
175
181
|
if (!all.some((n) => n.gate === need.gate)) all.push(need);
|