@jwilger/pi-development-system 0.8.5 → 0.8.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.
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { splitLines } from "./git-intent.ts";
|
|
2
2
|
import { resolveGit } from "./git-invocations.ts";
|
|
3
|
+
import { stripHeredocs } from "./heredoc.ts";
|
|
3
4
|
|
|
4
5
|
export type CommitExtraction =
|
|
5
6
|
| { readonly kind: "not-commit" }
|
|
@@ -7,22 +8,6 @@ export type CommitExtraction =
|
|
|
7
8
|
| { readonly kind: "file"; readonly path: string }
|
|
8
9
|
| { readonly kind: "unknown"; readonly trailers: readonly string[] };
|
|
9
10
|
|
|
10
|
-
const HEREDOC =
|
|
11
|
-
/<<-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1([^\n]*)\n([\s\S]*?)\n[ \t]*\2[ \t]*(?:\n|$)/g;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Heredoc bodies are data: take them out so their quotes cannot confuse line splitting. The rest of
|
|
15
|
-
* the opening line stays (`| git commit -F -`) with a `#HD<n>` marker naming the removed body.
|
|
16
|
-
*/
|
|
17
|
-
function stripHeredocs(command: string): { rest: string; bodies: string[] } {
|
|
18
|
-
const bodies: string[] = [];
|
|
19
|
-
const rest = command.replace(HEREDOC, (...m: unknown[]) => {
|
|
20
|
-
bodies.push(String(m[4]).trim());
|
|
21
|
-
return `${String(m[3])} #HD${bodies.length - 1}\n`;
|
|
22
|
-
});
|
|
23
|
-
return { rest, bodies };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
11
|
type Options = {
|
|
27
12
|
messages: string[];
|
|
28
13
|
trailers: string[];
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
substitutions,
|
|
14
14
|
WRAPPERS,
|
|
15
15
|
} from "./git-intent.ts";
|
|
16
|
+
import { stripHeredocs } from "./heredoc.ts";
|
|
16
17
|
|
|
17
18
|
export type GitInvocation = {
|
|
18
19
|
readonly sub: string;
|
|
@@ -114,7 +115,8 @@ function merge(into: Collector, other: GitResolution): void {
|
|
|
114
115
|
export function resolveGit(command: string): GitResolution {
|
|
115
116
|
const into: Collector = { invocations: [], opaque: false, dir: undefined, line: 0 };
|
|
116
117
|
let heredocEnd: string | undefined;
|
|
117
|
-
|
|
118
|
+
// Heredoc bodies are data (an apostrophe in one must not unbalance quote tracking).
|
|
119
|
+
const lines = splitLines(stripHeredocs(command).rest);
|
|
118
120
|
for (const [index, line] of lines.entries()) {
|
|
119
121
|
into.line = index;
|
|
120
122
|
if (heredocEnd !== undefined) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const HEREDOC =
|
|
2
|
+
/<<-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1([^\n]*)\n([\s\S]*?)\n[ \t]*\2[ \t]*(?:\n|$)/g;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Heredoc bodies are data: take them out so their quotes cannot confuse line splitting. The rest of
|
|
6
|
+
* the opening line stays (`| git commit -F -`) with a `#HD<n>` marker naming the removed body.
|
|
7
|
+
*/
|
|
8
|
+
export function stripHeredocs(command: string): { rest: string; bodies: string[] } {
|
|
9
|
+
const bodies: string[] = [];
|
|
10
|
+
const rest = command.replace(HEREDOC, (...m: unknown[]) => {
|
|
11
|
+
bodies.push(String(m[4]).trim());
|
|
12
|
+
return `${String(m[3])} #HD${bodies.length - 1}\n`;
|
|
13
|
+
});
|
|
14
|
+
return { rest, bodies };
|
|
15
|
+
}
|
|
@@ -63,7 +63,8 @@ function messageNeeds(message: string): Need[] {
|
|
|
63
63
|
|
|
64
64
|
/** `-a`/`--all`, or a `git add` in the same command, widen the commit beyond what is staged. */
|
|
65
65
|
const stagesEverything = (command: string): boolean =>
|
|
66
|
-
/\bgit\
|
|
66
|
+
/\bgit\s+add\b/.test(command) ||
|
|
67
|
+
/\bgit\b[^;&|\n]*\bcommit\b[^;&|\n]*\s(?:-[a-zA-Z]*a[a-zA-Z]*|--all|--include)(?=\s|$|[;&|])/.test(
|
|
67
68
|
command,
|
|
68
69
|
);
|
|
69
70
|
|