@procedures/git 0.67.0 → 0.68.1
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/CHANGELOG.md +37 -0
- package/README.md +12 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +11 -4
- package/dist/module.js.map +1 -1
- package/dist/procedures/git/clone.d.ts.map +1 -1
- package/dist/procedures/git/clone.js +2 -1
- package/dist/procedures/git/clone.js.map +1 -1
- package/dist/procedures/git/limits.d.ts +75 -0
- package/dist/procedures/git/limits.d.ts.map +1 -0
- package/dist/procedures/git/limits.js +116 -0
- package/dist/procedures/git/limits.js.map +1 -0
- package/dist/procedures/git/remote.d.ts.map +1 -1
- package/dist/procedures/git/remote.js +2 -1
- package/dist/procedures/git/remote.js.map +1 -1
- package/dist/procedures/git/root.d.ts +18 -5
- package/dist/procedures/git/root.d.ts.map +1 -1
- package/dist/procedures/git/root.js +52 -29
- package/dist/procedures/git/root.js.map +1 -1
- package/dist/procedures/git/run.d.ts +2 -1
- package/dist/procedures/git/run.d.ts.map +1 -1
- package/dist/procedures/git/run.js +6 -2
- package/dist/procedures/git/run.js.map +1 -1
- package/package.json +4 -4
- package/src/module.ts +12 -4
- package/src/procedures/git/clone.ts +2 -1
- package/src/procedures/git/limits.ts +138 -0
- package/src/procedures/git/remote.ts +2 -1
- package/src/procedures/git/root.ts +57 -27
- package/src/procedures/git/run.ts +6 -2
|
@@ -89,14 +89,23 @@ export function remoteUrlInGitRoot(url: string): string {
|
|
|
89
89
|
* configuration file. Git gives these options to the git commands that it starts.
|
|
90
90
|
*/
|
|
91
91
|
export function safeConfig(hooks: string): string[] {
|
|
92
|
+
return noProgramConfig(hooks, "never");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The `-c` options that stop git from starting a program of the repository: no hook, no
|
|
97
|
+
* `core.fsmonitor`, no `ext::`, no remote helper and no git in a submodule. `file` is the rule of
|
|
98
|
+
* the transport of a local path. A root gives `never`, because the path can be outside the root.
|
|
99
|
+
*/
|
|
100
|
+
export function noProgramConfig(hooks: string, file: "always" | "never"): string[] {
|
|
92
101
|
return [
|
|
93
102
|
// No hook runs: the folder is empty
|
|
94
103
|
`core.hooksPath=${hooks}`,
|
|
95
104
|
"core.fsmonitor=false",
|
|
96
|
-
// Only the
|
|
97
|
-
//
|
|
105
|
+
// Only the transports of git: no ext:: and no remote helper. The rule of a transport overrides
|
|
106
|
+
// protocol.allow, so file and ext get their own rule.
|
|
98
107
|
"protocol.allow=never",
|
|
99
|
-
|
|
108
|
+
`protocol.file.allow=${file}`,
|
|
100
109
|
"protocol.ext.allow=never",
|
|
101
110
|
"protocol.https.allow=always",
|
|
102
111
|
"protocol.http.allow=always",
|
|
@@ -224,9 +233,8 @@ async function makeSetup(): Promise<GitRootSetup> {
|
|
|
224
233
|
// The configuration of a repository
|
|
225
234
|
// =============================================================================
|
|
226
235
|
|
|
227
|
-
/** The keys (section.name, or section.subsection.name as section.*.name) that start a program
|
|
228
|
-
const
|
|
229
|
-
// Programs
|
|
236
|
+
/** The keys (section.name, or section.subsection.name as section.*.name) that start a program. */
|
|
237
|
+
const PROGRAM_KEYS: ReadonlySet<string> = new Set([
|
|
230
238
|
"core.sshcommand",
|
|
231
239
|
"core.gitproxy",
|
|
232
240
|
"core.askpass",
|
|
@@ -260,7 +268,12 @@ const REFUSED_KEYS: ReadonlySet<string> = new Set([
|
|
|
260
268
|
"uploadpack.packobjectshook",
|
|
261
269
|
"trailer.*.command",
|
|
262
270
|
"trailer.*.cmd",
|
|
263
|
-
//
|
|
271
|
+
// A transport that the -c options do not name, for example the remote helper of foo://
|
|
272
|
+
"protocol.*.allow",
|
|
273
|
+
]);
|
|
274
|
+
|
|
275
|
+
/** The keys that name a file outside the repository. */
|
|
276
|
+
const OUTSIDE_KEYS: ReadonlySet<string> = new Set([
|
|
264
277
|
"core.worktree",
|
|
265
278
|
"core.excludesfile",
|
|
266
279
|
"core.attributesfile",
|
|
@@ -281,12 +294,11 @@ const REFUSED_KEYS: ReadonlySet<string> = new Set([
|
|
|
281
294
|
]),
|
|
282
295
|
]);
|
|
283
296
|
|
|
284
|
-
/**
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const REFUSED_SECTIONS: ReadonlySet<string> = new Set(["pager", "hook", "protocol", "bundle"]);
|
|
297
|
+
/** The sections that start a program: `pager.<command>` and the hooks of the configuration. */
|
|
298
|
+
const PROGRAM_SECTIONS: ReadonlySet<string> = new Set(["pager", "hook"]);
|
|
299
|
+
|
|
300
|
+
/** The sections that a root also refuses as a whole: `protocol.*` allows a transport again, and a bundle URI can be a local file. */
|
|
301
|
+
const ROOT_SECTIONS: ReadonlySet<string> = new Set(["protocol", "bundle"]);
|
|
290
302
|
|
|
291
303
|
/** The keys that start the signing program when they are not false. */
|
|
292
304
|
const SIGNING_KEYS: ReadonlySet<string> = new Set(["commit.gpgsign", "tag.gpgsign", "tag.forcesignannotated", "push.gpgsign"]);
|
|
@@ -306,15 +318,27 @@ function partsOf(key: string): { section: string; subsection: string | undefined
|
|
|
306
318
|
};
|
|
307
319
|
}
|
|
308
320
|
|
|
309
|
-
/** True when a
|
|
321
|
+
/** True when a set of keys has the key of these parts. */
|
|
322
|
+
function hasKey(keys: ReadonlySet<string>, section: string, subsection: string | undefined, name: string): boolean {
|
|
323
|
+
if (keys.has(subsection === undefined ? `${section}.${name}` : `${section}.*.${name}`)) return true;
|
|
324
|
+
// gpg.ssh.defaultKeyCommand and gpg.ssh.allowedSignersFile have a fixed subsection
|
|
325
|
+
return subsection !== undefined && keys.has(`${section}.${subsection.toLowerCase()}.${name}`);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** True when a key of the configuration of a repository starts a program or names a file outside it. A root refuses these keys. */
|
|
310
329
|
export function isRefusedConfigKey(key: string, value: string | undefined): boolean {
|
|
311
330
|
const { section, subsection, name } = partsOf(key);
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
331
|
+
return ROOT_SECTIONS.has(section) || hasKey(OUTSIDE_KEYS, section, subsection, name) || startsProgram(key, value);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* True when a key of the configuration of a repository starts a program. The key counts also when
|
|
336
|
+
* the next git command does not start that program: the examination does not know the next commands.
|
|
337
|
+
*/
|
|
338
|
+
export function startsProgram(key: string, value: string | undefined): boolean {
|
|
339
|
+
const { section, subsection, name } = partsOf(key);
|
|
340
|
+
if (PROGRAM_SECTIONS.has(section) || hasKey(PROGRAM_KEYS, section, subsection, name)) return true;
|
|
341
|
+
if (subsection === undefined && SIGNING_KEYS.has(`${section}.${name}`)) return !FALSE_VALUES.has((value ?? "true").trim().toLowerCase());
|
|
318
342
|
// A remote helper: `<transport>::<address>`, also as the base of url.<base>.insteadOf
|
|
319
343
|
if (section === "remote" && (name === "url" || name === "pushurl")) return (value ?? "").includes("::");
|
|
320
344
|
if (section === "url" && (subsection ?? "").includes("::")) return true;
|
|
@@ -330,6 +354,12 @@ export interface ConfigEntry {
|
|
|
330
354
|
readonly value: string | undefined;
|
|
331
355
|
}
|
|
332
356
|
|
|
357
|
+
/**
|
|
358
|
+
* The scopes of the configuration of the host: its programs are programs of the host, not of the
|
|
359
|
+
* project. A root has no system configuration, and its global configuration is a file of this process.
|
|
360
|
+
*/
|
|
361
|
+
const HOST_SCOPES: ReadonlySet<string> = new Set(["system", "global", "command"]);
|
|
362
|
+
|
|
333
363
|
/** This function reads the output of `git config --list --show-scope -z`: the scope, then the key and the value. */
|
|
334
364
|
export function parseConfigList(output: string): ConfigEntry[] {
|
|
335
365
|
const fields = output.split("\0");
|
|
@@ -344,15 +374,15 @@ export function parseConfigList(output: string): ConfigEntry[] {
|
|
|
344
374
|
}
|
|
345
375
|
|
|
346
376
|
/**
|
|
347
|
-
* This function gives the keys of the configuration of a repository that
|
|
348
|
-
*
|
|
349
|
-
*
|
|
377
|
+
* This function gives the keys of the configuration of a repository that `refuses` refuses. The
|
|
378
|
+
* default is the rule of a root, `isRefusedConfigKey()`. It examines the files of the repository
|
|
379
|
+
* (the scopes `local` and `worktree`), not the configuration of the host (`HOST_SCOPES`).
|
|
350
380
|
*/
|
|
351
|
-
export function refusedConfigKeys(entries: readonly ConfigEntry[]): string[] {
|
|
381
|
+
export function refusedConfigKeys(entries: readonly ConfigEntry[], refuses: (key: string, value: string | undefined) => boolean = isRefusedConfigKey): string[] {
|
|
352
382
|
const refused = new Set<string>();
|
|
353
383
|
for (const entry of entries) {
|
|
354
|
-
if (
|
|
355
|
-
if (
|
|
384
|
+
if (HOST_SCOPES.has(entry.scope)) continue;
|
|
385
|
+
if (refuses(entry.key, entry.value)) refused.add(entry.key);
|
|
356
386
|
}
|
|
357
387
|
return [...refused];
|
|
358
388
|
}
|
|
@@ -372,7 +402,7 @@ async function isInRoot(root: ResolvedRoot, path: string): Promise<boolean> {
|
|
|
372
402
|
}
|
|
373
403
|
|
|
374
404
|
/** True when a file or a folder exists. */
|
|
375
|
-
async function exists(path: string): Promise<boolean> {
|
|
405
|
+
export async function exists(path: string): Promise<boolean> {
|
|
376
406
|
return access(path).then(
|
|
377
407
|
() => true,
|
|
378
408
|
() => false,
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { runCommand } from "@procedures/shell/command";
|
|
10
10
|
import { GIT_MAX_BUFFER } from "./args.js";
|
|
11
|
+
import { currentGitLimits, limitedGitCommand } from "./limits.js";
|
|
11
12
|
import { confinedGitCommand, currentGitRoot } from "./root.js";
|
|
12
13
|
|
|
13
14
|
/** The part of the procedure context that the git procedures read. */
|
|
@@ -48,11 +49,14 @@ export class GitError extends Error {
|
|
|
48
49
|
/**
|
|
49
50
|
* This function runs `git <args>` and gives its stdout. It throws a `GitError` when git fails,
|
|
50
51
|
* and an `AbortError` when the signal aborts. In the handler of a git procedure under a root
|
|
51
|
-
* (`underGitRoot()`), git stays in the root: `confinedGitCommand()` of `root.ts`.
|
|
52
|
+
* (`underGitRoot()`), git stays in the root: `confinedGitCommand()` of `root.ts`. Under a capability
|
|
53
|
+
* without `process` (`underGitLimits()`), git starts no program of the repository: `limits.ts`.
|
|
52
54
|
*/
|
|
53
55
|
export async function git(args: string[], options: GitRunOptions = {}): Promise<string> {
|
|
54
56
|
const root = currentGitRoot();
|
|
55
|
-
const
|
|
57
|
+
const limits = currentGitLimits();
|
|
58
|
+
const confined = root === undefined ? { args, cwd: options.cwd, env: options.env } : await confinedGitCommand(root, args, options.cwd, options.env);
|
|
59
|
+
const command = limits === undefined ? confined : await limitedGitCommand(limits, confined, root !== undefined);
|
|
56
60
|
const result = await runCommand("git", {
|
|
57
61
|
args: command.args,
|
|
58
62
|
cwd: command.cwd,
|