@statewalker/vcs-commands 0.10.0 → 0.12.0
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/dist/commands/am/am-command.d.ts.map +1 -1
- package/dist/commands/archive/archive-command.d.ts +81 -7
- package/dist/commands/archive/archive-command.d.ts.map +1 -1
- package/dist/commands/archive/archive-entry.d.ts +48 -5
- package/dist/commands/archive/archive-entry.d.ts.map +1 -1
- package/dist/commands/archive/tar-archive.d.ts +5 -2
- package/dist/commands/archive/tar-archive.d.ts.map +1 -1
- package/dist/commands/archive/zip-archive.d.ts +9 -2
- package/dist/commands/archive/zip-archive.d.ts.map +1 -1
- package/dist/commands/attributes-source.d.ts +5 -0
- package/dist/commands/attributes-source.d.ts.map +1 -1
- package/dist/commands/cat-file/cat-file-command.d.ts +9 -0
- package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +9 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/default-branch.d.ts +12 -0
- package/dist/commands/default-branch.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/format-rev-command.d.ts +6 -4
- package/dist/commands/format-rev-command.d.ts.map +1 -1
- package/dist/commands/fsmonitor-ipc.d.ts +30 -0
- package/dist/commands/fsmonitor-ipc.d.ts.map +1 -0
- package/dist/commands/fsmonitor-refresh.d.ts.map +1 -1
- package/dist/commands/http-config.d.ts +4 -2
- package/dist/commands/http-config.d.ts.map +1 -1
- package/dist/commands/index.d.ts +2 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +6 -6
- package/dist/commands/log-output.d.ts +6 -0
- package/dist/commands/log-output.d.ts.map +1 -1
- package/dist/commands/ls-files-command.d.ts.map +1 -1
- package/dist/commands/ls-tree-command.d.ts.map +1 -1
- package/dist/commands/mv-command.d.ts.map +1 -1
- package/dist/commands/pathspec.d.ts.map +1 -1
- package/dist/commands/plumbing-shared.d.ts +72 -0
- package/dist/commands/plumbing-shared.d.ts.map +1 -0
- package/dist/commands/repack-command.d.ts +12 -3
- package/dist/commands/repack-command.d.ts.map +1 -1
- package/dist/commands/replace-command.d.ts.map +1 -1
- package/dist/commands/repo-command.d.ts +28 -6
- package/dist/commands/repo-command.d.ts.map +1 -1
- package/dist/commands/rerere-command.d.ts +12 -0
- package/dist/commands/rerere-command.d.ts.map +1 -1
- package/dist/commands/rerere.d.ts +22 -0
- package/dist/commands/rerere.d.ts.map +1 -1
- package/dist/commands/reset-command.d.ts +19 -2
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/rev-parse-command.d.ts +3 -7
- package/dist/commands/rev-parse-command.d.ts.map +1 -1
- package/dist/commands/revision-resolver.d.ts +24 -5
- package/dist/commands/revision-resolver.d.ts.map +1 -1
- package/dist/commands/signing.d.ts +8 -1
- package/dist/commands/signing.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts +14 -1
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/submodule-add-command.d.ts +12 -0
- package/dist/commands/submodule-add-command.d.ts.map +1 -1
- package/dist/commands/submodule-update-command.d.ts +14 -0
- package/dist/commands/submodule-update-command.d.ts.map +1 -1
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/update-index-command.d.ts +21 -0
- package/dist/commands/update-index-command.d.ts.map +1 -1
- package/dist/{commands-Mlo1dxQN.js → commands-C2E51T1z.js} +942 -293
- package/dist/{fsck-CrhVMNIH.js → fsck-BjlxStsM.js} +1 -1
- package/dist/git-command.d.ts +14 -6
- package/dist/git-command.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/{maintenance-run-command-Bw21HEkH.js → maintenance-run-command-G_eWdA8O.js} +48 -17
- package/dist/remote-config/remote-config-store.d.ts +4 -1
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/{remote-transport-Bu4PGSMD.js → remote-transport-CSgTJ1BH.js} +3 -3
- package/dist/results/index.js +1 -1
- package/dist/{results-ERo9vELd.js → results-Dg1KHG8y.js} +669 -96
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/commands/am/am-command.ts +30 -14
- package/src/commands/archive/archive-command.ts +395 -59
- package/src/commands/archive/archive-entry.ts +88 -5
- package/src/commands/archive/tar-archive.ts +40 -9
- package/src/commands/archive/zip-archive.ts +72 -21
- package/src/commands/attributes-source.ts +13 -1
- package/src/commands/cat-file/cat-file-command.ts +64 -52
- package/src/commands/checkout-command.ts +22 -1
- package/src/commands/clone-command.ts +41 -2
- package/src/commands/default-branch.ts +19 -0
- package/src/commands/diff-command.ts +19 -1
- package/src/commands/format-rev-command.ts +28 -12
- package/src/commands/fsmonitor-ipc.ts +121 -0
- package/src/commands/fsmonitor-refresh.ts +7 -2
- package/src/commands/http-config.ts +14 -2
- package/src/commands/index.ts +2 -0
- package/src/commands/log-output.ts +11 -0
- package/src/commands/ls-files-command.ts +25 -33
- package/src/commands/ls-tree-command.ts +30 -22
- package/src/commands/mv-command.ts +37 -6
- package/src/commands/pathspec.ts +2 -4
- package/src/commands/plumbing-shared.ts +197 -0
- package/src/commands/repack-command.ts +44 -11
- package/src/commands/replace-command.ts +16 -4
- package/src/commands/repo-command.ts +124 -25
- package/src/commands/rerere-command.ts +17 -0
- package/src/commands/rerere.ts +144 -3
- package/src/commands/reset-command.ts +75 -3
- package/src/commands/rev-parse-command.ts +14 -28
- package/src/commands/revision-resolver.ts +85 -34
- package/src/commands/signing.ts +54 -7
- package/src/commands/status-command.ts +31 -2
- package/src/commands/submodule-add-command.ts +18 -1
- package/src/commands/submodule-update-command.ts +18 -1
- package/src/commands/tag-command.ts +33 -11
- package/src/commands/update-index-command.ts +137 -5
- package/src/git-command.ts +60 -19
- package/src/remote-config/remote-config-store.ts +11 -3
- package/src/transport-command.ts +4 -1
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* `compute_rev_name`), over the submodule model of `submodule-model.ts`, the clone, fetch,
|
|
6
6
|
* checkout, merge and rebase commands.
|
|
7
7
|
*/
|
|
8
|
+
|
|
8
9
|
import type { ObjectId } from "@statewalker/vcs-core";
|
|
9
10
|
import {
|
|
10
11
|
type Credentials,
|
|
@@ -14,12 +15,12 @@ import {
|
|
|
14
15
|
} from "@statewalker/vcs-transport";
|
|
15
16
|
import type { PosixFilesApi } from "@statewalker/vcs-utils/files";
|
|
16
17
|
import { type WorkingCopy, wildmatch } from "@statewalker/vcs-working-tree";
|
|
17
|
-
|
|
18
18
|
import { GitApiError } from "../errors/index.js";
|
|
19
19
|
import { GitCommand } from "../git-command.js";
|
|
20
20
|
import { RemoteConfigStore } from "../remote-config/index.js";
|
|
21
21
|
import { CheckoutCommand, CheckoutStatus } from "./checkout-command.js";
|
|
22
22
|
import { createIdAbbreviator } from "./core-config.js";
|
|
23
|
+
import { unknownObjectStorageFormat } from "./default-branch.js";
|
|
23
24
|
import { DiffCommand } from "./diff-command.js";
|
|
24
25
|
import { FetchCommand } from "./fetch-command.js";
|
|
25
26
|
import { createDescriber } from "./git-describe.js";
|
|
@@ -244,6 +245,7 @@ export class SubmoduleUpdateCommand extends SubmoduleCommandBase {
|
|
|
244
245
|
private requireInit = false;
|
|
245
246
|
/** `--filter=<spec>` of the clones */
|
|
246
247
|
private filter?: string;
|
|
248
|
+
private objectStorageFormat?: string;
|
|
247
249
|
/** `--[no-]single-branch` of the clones */
|
|
248
250
|
private singleBranch?: boolean;
|
|
249
251
|
private transports?: GitTransportRegistry;
|
|
@@ -331,6 +333,17 @@ export class SubmoduleUpdateCommand extends SubmoduleCommandBase {
|
|
|
331
333
|
return this;
|
|
332
334
|
}
|
|
333
335
|
|
|
336
|
+
/**
|
|
337
|
+
* `--object-storage-format=<name>` (git master): the object storage of the submodules
|
|
338
|
+
* cloned. Only `files` is a name git knows (the repository as always); anything else,
|
|
339
|
+
* `files://<dir>` included, dies `unknown object storage format '<v>'` before any work.
|
|
340
|
+
*/
|
|
341
|
+
setObjectStorageFormat(format: string): this {
|
|
342
|
+
this.checkCallable();
|
|
343
|
+
this.objectStorageFormat = format;
|
|
344
|
+
return this;
|
|
345
|
+
}
|
|
346
|
+
|
|
334
347
|
/** `--filter=<spec>`: partial clones of the submodules (`CloneCommand.setFilter`). */
|
|
335
348
|
setFilter(spec: string | undefined): this {
|
|
336
349
|
this.checkCallable();
|
|
@@ -485,6 +498,10 @@ export class SubmoduleUpdateCommand extends SubmoduleCommandBase {
|
|
|
485
498
|
|
|
486
499
|
async call(): Promise<SubmoduleCommandResult> {
|
|
487
500
|
this.start();
|
|
501
|
+
if (this.objectStorageFormat !== undefined) {
|
|
502
|
+
const unknown = unknownObjectStorageFormat(this.objectStorageFormat, "name");
|
|
503
|
+
if (unknown) this.die(unknown);
|
|
504
|
+
}
|
|
488
505
|
if (this.requireInit) this.init = true;
|
|
489
506
|
const list = await this.moduleList(this.paths);
|
|
490
507
|
if (!list) return this.finish();
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
type RefSortKey,
|
|
36
36
|
signatureStart,
|
|
37
37
|
} from "./ref-filter/index.js";
|
|
38
|
-
import { SigningFailedError, signPayload } from "./signing.js";
|
|
38
|
+
import { SigningFailedError, signPayload, signTagCompat } from "./signing.js";
|
|
39
39
|
import {
|
|
40
40
|
amendWithTrailers,
|
|
41
41
|
type TrailerCommandRunner,
|
|
@@ -504,13 +504,18 @@ export class TagCommand extends GitCommand<Ref> {
|
|
|
504
504
|
// build_tag_object signs before writing (do_sign): the signature appended to the tag
|
|
505
505
|
// object, so to its message
|
|
506
506
|
if (sign) {
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
507
|
+
const payload = await collectTagBytes(tag);
|
|
508
|
+
const signature = await this.signTag(payload, tagger, compatibility, warnings);
|
|
509
|
+
if (signature) {
|
|
510
|
+
tag.message = `${message}${new TextDecoder().decode(signature)}`;
|
|
511
|
+
// with a compatibility object format do_sign signs the converted tag too and puts
|
|
512
|
+
// that signature in the header (so in both objects: the conversion moves each
|
|
513
|
+
// signature to where its own format keeps it)
|
|
514
|
+
const compatSignature = await this.signTag(payload, tagger, compatibility, warnings, {
|
|
515
|
+
compat: true,
|
|
516
|
+
});
|
|
517
|
+
if (compatSignature) tag.compatSignature = compatSignature;
|
|
518
|
+
}
|
|
514
519
|
}
|
|
515
520
|
tagObjectId = await this.tagsStore.storeTag(tag);
|
|
516
521
|
} else {
|
|
@@ -640,7 +645,21 @@ export class TagCommand extends GitCommand<Ref> {
|
|
|
640
645
|
tagger: PersonIdent,
|
|
641
646
|
compatibility: "2.43" | "2.56",
|
|
642
647
|
warnings: string[],
|
|
643
|
-
): Promise<Uint8Array | undefined
|
|
648
|
+
): Promise<Uint8Array | undefined>;
|
|
649
|
+
private async signTag(
|
|
650
|
+
payload: Uint8Array,
|
|
651
|
+
tagger: PersonIdent,
|
|
652
|
+
compatibility: "2.43" | "2.56",
|
|
653
|
+
warnings: string[],
|
|
654
|
+
options: { compat: true },
|
|
655
|
+
): Promise<AnnotatedTag["compatSignature"]>;
|
|
656
|
+
private async signTag(
|
|
657
|
+
payload: Uint8Array,
|
|
658
|
+
tagger: PersonIdent,
|
|
659
|
+
compatibility: "2.43" | "2.56",
|
|
660
|
+
warnings: string[],
|
|
661
|
+
options?: { compat: true },
|
|
662
|
+
): Promise<Uint8Array | AnnotatedTag["compatSignature"]> {
|
|
644
663
|
const gitDir = (await this.hooks.hostGitDir({ real: false }).catch(() => undefined))?.replace(
|
|
645
664
|
/\/+$/,
|
|
646
665
|
"",
|
|
@@ -654,11 +673,14 @@ export class TagCommand extends GitCommand<Ref> {
|
|
|
654
673
|
: `${gitDir}/TAG_EDITMSG`;
|
|
655
674
|
const cwd = await this.hooks.hostWorkingDirectory().catch(() => undefined);
|
|
656
675
|
try {
|
|
657
|
-
|
|
676
|
+
const signOptions = {
|
|
658
677
|
committer: tagger,
|
|
659
678
|
...(cwd !== undefined ? { cwd } : {}),
|
|
660
679
|
tail: ["error: unable to sign the tag", `The tag message has been left in ${path}`],
|
|
661
|
-
}
|
|
680
|
+
};
|
|
681
|
+
const key = this.signingKey ?? "";
|
|
682
|
+
if (options?.compat) return await signTagCompat(this.workingCopy, key, payload, signOptions);
|
|
683
|
+
return await signPayload(this.workingCopy, key, payload, signOptions);
|
|
662
684
|
} catch (e) {
|
|
663
685
|
if (!(e instanceof SigningFailedError)) throw e;
|
|
664
686
|
// git 2.43's do_sign fails only on a negative return, and its sign_buffer_ssh returns
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
*
|
|
13
13
|
* // git update-index --refresh
|
|
14
14
|
* const { output, exitCode } = await git.updateIndex().refresh().call();
|
|
15
|
+
*
|
|
16
|
+
* // git update-index --fsmonitor, then --fsmonitor-valid a
|
|
17
|
+
* await git.updateIndex().setFsmonitor(true).call();
|
|
18
|
+
* await git.updateIndex().setFsmonitorValid(true).addPath("a").call();
|
|
15
19
|
* ```
|
|
16
20
|
*/
|
|
17
21
|
|
|
@@ -26,6 +30,7 @@ import {
|
|
|
26
30
|
basicStatMatches,
|
|
27
31
|
compareWithWorktree,
|
|
28
32
|
entryStatOf,
|
|
33
|
+
FsmonitorState,
|
|
29
34
|
invalidateCacheTreePath,
|
|
30
35
|
modeFromWorktree,
|
|
31
36
|
type ResolveUndoRecord,
|
|
@@ -38,7 +43,11 @@ import {
|
|
|
38
43
|
} from "@statewalker/vcs-working-tree";
|
|
39
44
|
import { UpdateIndexFailedError } from "../errors/index.js";
|
|
40
45
|
import { GitCommand } from "../git-command.js";
|
|
46
|
+
import { RemoteConfigStore } from "../remote-config/index.js";
|
|
41
47
|
import { worktreeModeTrust } from "./core-config.js";
|
|
48
|
+
import { fsmonitorModeOf } from "./fsmonitor-refresh.js";
|
|
49
|
+
import { hookHostOf } from "./git-hooks.js";
|
|
50
|
+
import { hostEnvironmentOf } from "./git-ident.js";
|
|
42
51
|
import { configBool } from "./merge-config.js";
|
|
43
52
|
import { inputLines, inputPaths, unquoteLine } from "./plumbing-input.js";
|
|
44
53
|
import { worktreePathRules } from "./worktree-path-rules.js";
|
|
@@ -74,6 +83,8 @@ interface State {
|
|
|
74
83
|
markValid?: boolean;
|
|
75
84
|
/** `--[no-]skip-worktree` */
|
|
76
85
|
markSkipWorktree?: boolean;
|
|
86
|
+
/** `--[no-]fsmonitor-valid` */
|
|
87
|
+
markFsmonitor?: boolean;
|
|
77
88
|
ignoreSkipWorktreeEntries: boolean;
|
|
78
89
|
chmod?: "+x" | "-x";
|
|
79
90
|
quiet: boolean;
|
|
@@ -133,6 +144,7 @@ export class UpdateIndexCommand extends GitCommand<UpdateIndexResult> {
|
|
|
133
144
|
private indexVersion?: number;
|
|
134
145
|
private showIndexVersion = false;
|
|
135
146
|
private forceWrite = false;
|
|
147
|
+
private fsmonitor?: boolean;
|
|
136
148
|
|
|
137
149
|
private set(apply: (state: State) => void): this {
|
|
138
150
|
this.checkCallable();
|
|
@@ -203,6 +215,28 @@ export class UpdateIndexCommand extends GitCommand<UpdateIndexResult> {
|
|
|
203
215
|
});
|
|
204
216
|
}
|
|
205
217
|
|
|
218
|
+
/**
|
|
219
|
+
* `--fsmonitor-valid` (true) / `--no-fsmonitor-valid` (false) for the paths after it: the
|
|
220
|
+
* entry's fsmonitor valid bit (`CE_FSMONITOR_VALID`) set or cleared.
|
|
221
|
+
*/
|
|
222
|
+
setFsmonitorValid(mark: boolean): this {
|
|
223
|
+
return this.set((s) => {
|
|
224
|
+
s.markFsmonitor = mark;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* `--fsmonitor` (true) / `--no-fsmonitor` (false), applied after the paths, as git does:
|
|
230
|
+
* the index's `FSMN` extension added (`add_fsmonitor`; a warning when `core.fsmonitor` is
|
|
231
|
+
* unset; git's death in a bare repository with `core.fsmonitor` set) or removed (a warning
|
|
232
|
+
* when `core.fsmonitor` is set).
|
|
233
|
+
*/
|
|
234
|
+
setFsmonitor(enable: boolean): this {
|
|
235
|
+
this.checkCallable();
|
|
236
|
+
this.fsmonitor = enable;
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
|
|
206
240
|
/** `--ignore-skip-worktree-entries`: `--remove` leaves skip-worktree entries alone. */
|
|
207
241
|
setIgnoreSkipWorktreeEntries(ignore = true): this {
|
|
208
242
|
return this.set((s) => {
|
|
@@ -315,8 +349,24 @@ export class UpdateIndexCommand extends GitCommand<UpdateIndexResult> {
|
|
|
315
349
|
async call(): Promise<UpdateIndexResult> {
|
|
316
350
|
this.checkCallable();
|
|
317
351
|
this.setCallable(false);
|
|
318
|
-
|
|
319
|
-
|
|
352
|
+
// fsm_settings__get_reason: a bare repository is incompatible with a configured monitor
|
|
353
|
+
// (git dies after reading the index, which a bare working copy here does not give)
|
|
354
|
+
if (this.fsmonitor && !this.hasWorktree()) {
|
|
355
|
+
const mode = fsmonitorModeOf(
|
|
356
|
+
RemoteConfigStore.from(this.workingCopy).value("core.fsmonitor"),
|
|
357
|
+
);
|
|
358
|
+
if (mode.kind !== "disabled") {
|
|
359
|
+
throw new UpdateIndexFailedError(
|
|
360
|
+
`fatal: bare repository '${await this.currentDirectory()}' is incompatible with fsmonitor`,
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
await this.readCurrentIndex(true, false);
|
|
365
|
+
// tweak_fsmonitor on the index read: the monitor asked, the extension added or removed
|
|
366
|
+
const hadFsmonitor = !!this.staging.getFsmonitor?.();
|
|
367
|
+
const fsm = await this.fsmonitorRefresh(this.staging);
|
|
368
|
+
const run = new UpdateIndexRun(this.context(fsm?.state));
|
|
369
|
+
for (const warning of fsm?.warnings ?? []) run.stderr.push(`warning: ${warning}`);
|
|
320
370
|
try {
|
|
321
371
|
await this.inOneOperation(async () => {
|
|
322
372
|
for (const step of this.steps) await run.step(step);
|
|
@@ -330,6 +380,7 @@ export class UpdateIndexCommand extends GitCommand<UpdateIndexResult> {
|
|
|
330
380
|
await run.updateOne(path);
|
|
331
381
|
}
|
|
332
382
|
}
|
|
383
|
+
await this.applyFsmonitor(run);
|
|
333
384
|
});
|
|
334
385
|
} catch (error) {
|
|
335
386
|
if (error instanceof Death) {
|
|
@@ -340,7 +391,10 @@ export class UpdateIndexCommand extends GitCommand<UpdateIndexResult> {
|
|
|
340
391
|
}
|
|
341
392
|
throw error;
|
|
342
393
|
}
|
|
343
|
-
|
|
394
|
+
// FSMONITOR_CHANGED: the extension added or removed, bits set
|
|
395
|
+
const fsmonitorNow = this.staging.getFsmonitor?.();
|
|
396
|
+
const fsmonitorChanged = !!fsmonitorNow?.changed || (hadFsmonitor && !fsmonitorNow);
|
|
397
|
+
if (run.changed || this.forceWrite || fsmonitorChanged) {
|
|
344
398
|
try {
|
|
345
399
|
await run.write();
|
|
346
400
|
} catch (error) {
|
|
@@ -360,6 +414,50 @@ export class UpdateIndexCommand extends GitCommand<UpdateIndexResult> {
|
|
|
360
414
|
};
|
|
361
415
|
}
|
|
362
416
|
|
|
417
|
+
/** `--[no-]fsmonitor`: `add_fsmonitor` / `remove_fsmonitor` and their warnings. */
|
|
418
|
+
private async applyFsmonitor(run: UpdateIndexRun): Promise<void> {
|
|
419
|
+
if (this.fsmonitor === undefined) return;
|
|
420
|
+
const mode = fsmonitorModeOf(RemoteConfigStore.from(this.workingCopy).value("core.fsmonitor"));
|
|
421
|
+
const staging = this.staging;
|
|
422
|
+
if (this.fsmonitor) {
|
|
423
|
+
if (mode.kind === "disabled") {
|
|
424
|
+
run.stderr.push(
|
|
425
|
+
"warning: core.fsmonitor is unset; set it if you really want to enable fsmonitor",
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
if (!staging.getFsmonitor?.() && staging.setFsmonitor) {
|
|
429
|
+
// add_fsmonitor: a nanosecond token, every entry dirty; written although the
|
|
430
|
+
// monitor is off (the next read with it off removes it)
|
|
431
|
+
const state = new FsmonitorState(String(BigInt(Date.now()) * 1_000_000n));
|
|
432
|
+
state.changed = true;
|
|
433
|
+
state.writtenWhileDisabled = mode.kind === "disabled";
|
|
434
|
+
staging.setFsmonitor(state);
|
|
435
|
+
}
|
|
436
|
+
run.report("fsmonitor enabled");
|
|
437
|
+
} else {
|
|
438
|
+
if (mode.kind !== "disabled" && this.hasWorktree()) {
|
|
439
|
+
run.stderr.push(
|
|
440
|
+
"warning: core.fsmonitor is set; remove it if you really want to disable fsmonitor",
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
staging.setFsmonitor?.(undefined);
|
|
444
|
+
run.report("fsmonitor disabled");
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** git's `xgetcwd()` for a bare repository: the git directory's host path. */
|
|
449
|
+
private async currentDirectory(): Promise<string> {
|
|
450
|
+
const layout = await hookHostOf(this.workingCopy).layout();
|
|
451
|
+
if (!layout) return ".";
|
|
452
|
+
const root = (layout.files as { rootDirectory?: string }).rootDirectory;
|
|
453
|
+
if (!root) return layout.gitDir;
|
|
454
|
+
const base = root.replace(/\/+$/, "");
|
|
455
|
+
const rest = layout.gitDir.replace(/^\.?\/*|\/+$/g, "");
|
|
456
|
+
const path = rest ? `${base}/${rest}` : base || "/";
|
|
457
|
+
const environment = hostEnvironmentOf(this.workingCopy);
|
|
458
|
+
return (await environment?.realPath?.(path).catch(() => undefined)) ?? path;
|
|
459
|
+
}
|
|
460
|
+
|
|
363
461
|
private applyIndexVersion(run: UpdateIndexRun): void {
|
|
364
462
|
const staging = this.staging as unknown as {
|
|
365
463
|
_getVersion?(): number;
|
|
@@ -376,9 +474,10 @@ export class UpdateIndexCommand extends GitCommand<UpdateIndexResult> {
|
|
|
376
474
|
if (staging._setVersion) run.setVersion = (v) => staging._setVersion?.(v);
|
|
377
475
|
}
|
|
378
476
|
|
|
379
|
-
private context(): RunContext {
|
|
477
|
+
private context(fsmonitor: FsmonitorState | undefined): RunContext {
|
|
380
478
|
const worktree = this.worktreeAccess;
|
|
381
479
|
return {
|
|
480
|
+
fsmonitor,
|
|
382
481
|
staging: this.staging,
|
|
383
482
|
worktree,
|
|
384
483
|
blobs: this.blobs,
|
|
@@ -394,6 +493,8 @@ export class UpdateIndexCommand extends GitCommand<UpdateIndexResult> {
|
|
|
394
493
|
}
|
|
395
494
|
|
|
396
495
|
interface RunContext {
|
|
496
|
+
/** The index's fsmonitor state, the monitor asked (undefined while it is off) */
|
|
497
|
+
fsmonitor: FsmonitorState | undefined;
|
|
397
498
|
staging: UpdateIndexCommand["staging"];
|
|
398
499
|
worktree: Worktree | undefined;
|
|
399
500
|
blobs: UpdateIndexCommand["blobs"];
|
|
@@ -607,7 +708,10 @@ class UpdateIndexRun {
|
|
|
607
708
|
async updateOne(path: string): Promise<void> {
|
|
608
709
|
await this.load();
|
|
609
710
|
const s = this.state;
|
|
610
|
-
const markOnly =
|
|
711
|
+
const markOnly =
|
|
712
|
+
s.markValid !== undefined ||
|
|
713
|
+
s.markSkipWorktree !== undefined ||
|
|
714
|
+
s.markFsmonitor !== undefined;
|
|
611
715
|
let current: WorktreeEntry | undefined;
|
|
612
716
|
let missing = false;
|
|
613
717
|
let mode = 0;
|
|
@@ -632,6 +736,12 @@ class UpdateIndexRun {
|
|
|
632
736
|
}
|
|
633
737
|
return this.chmodAfter(path);
|
|
634
738
|
}
|
|
739
|
+
if (s.markFsmonitor !== undefined) {
|
|
740
|
+
if (!this.markFsmonitor(path, s.markFsmonitor)) {
|
|
741
|
+
throw new Death(`Unable to mark file ${path}`);
|
|
742
|
+
}
|
|
743
|
+
return this.chmodAfter(path);
|
|
744
|
+
}
|
|
635
745
|
if (s.forceRemove) {
|
|
636
746
|
this.removeFile(path);
|
|
637
747
|
this.report(`remove '${path}'`);
|
|
@@ -672,6 +782,21 @@ class UpdateIndexRun {
|
|
|
672
782
|
return true;
|
|
673
783
|
}
|
|
674
784
|
|
|
785
|
+
/** `mark_ce_flags` with `CE_FSMONITOR_VALID`: false when the path has no stage-0 entry. */
|
|
786
|
+
private markFsmonitor(path: string, mark: boolean): boolean {
|
|
787
|
+
const pos = this.namePos(path);
|
|
788
|
+
if (pos < 0) return false;
|
|
789
|
+
const ce = this.entries[pos] as Entry;
|
|
790
|
+
const state = this.ctx.fsmonitor;
|
|
791
|
+
if (state) {
|
|
792
|
+
state.markInvalid(ce);
|
|
793
|
+
if (mark) state.markValid(ce, { gitlinks: true });
|
|
794
|
+
}
|
|
795
|
+
this.invalidate(path);
|
|
796
|
+
this.changed = true;
|
|
797
|
+
return true;
|
|
798
|
+
}
|
|
799
|
+
|
|
675
800
|
/** `remove_one_path`. */
|
|
676
801
|
private removeOnePath(path: string): boolean {
|
|
677
802
|
if (!this.state.remove) {
|
|
@@ -902,6 +1027,7 @@ class UpdateIndexRun {
|
|
|
902
1027
|
const worktree = this.ctx.worktree;
|
|
903
1028
|
if (!worktree) return;
|
|
904
1029
|
const trust = this.ctx.trust;
|
|
1030
|
+
const fsmonitor = this.ctx.fsmonitor;
|
|
905
1031
|
for (let i = 0; i < this.entries.length; i++) {
|
|
906
1032
|
const ce = this.entries[i] as Entry;
|
|
907
1033
|
if (s.ignoreSubmodules && ce.mode === FileMode.GITLINK) continue;
|
|
@@ -916,6 +1042,8 @@ class UpdateIndexRun {
|
|
|
916
1042
|
// refresh_cache_ent: what the user promised not to have changed
|
|
917
1043
|
if (ce.skipWorktree) continue;
|
|
918
1044
|
if (!really && ce.assumeValid) continue;
|
|
1045
|
+
// CE_FSMONITOR_VALID: the monitor reported nothing for it, taken as up to date unseen
|
|
1046
|
+
if (fsmonitor?.isValid(ce)) continue;
|
|
919
1047
|
const current = await worktree.getEntry(ce.path).catch(() => undefined);
|
|
920
1048
|
if (!current && s.ignoreMissing) continue;
|
|
921
1049
|
let changed: boolean;
|
|
@@ -948,8 +1076,12 @@ class UpdateIndexRun {
|
|
|
948
1076
|
continue;
|
|
949
1077
|
}
|
|
950
1078
|
if (fresh && !sameStat(fresh, ce)) {
|
|
1079
|
+
// replaced (its stat stored): no longer fsmonitor-valid (replace_index_entry)
|
|
951
1080
|
this.entries[i] = fresh;
|
|
952
1081
|
this.changed = true;
|
|
1082
|
+
} else {
|
|
1083
|
+
// up to date as it is: mark_fsmonitor_valid (gitlinks never)
|
|
1084
|
+
fsmonitor?.markValid(ce);
|
|
953
1085
|
}
|
|
954
1086
|
}
|
|
955
1087
|
// has_racy_timestamp: written anyway, so the racy entries stop being racy
|
package/src/git-command.ts
CHANGED
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
createReplacedCommits,
|
|
24
24
|
createReplacedTags,
|
|
25
25
|
createReplacedTrees,
|
|
26
|
-
decodeTreeBytes,
|
|
27
26
|
type GraftFileBase,
|
|
28
27
|
graftFileBaseDir,
|
|
29
28
|
graftFileReader,
|
|
@@ -46,6 +45,7 @@ import {
|
|
|
46
45
|
clearSkipWorktreeFromPresentFiles,
|
|
47
46
|
compareWithWorktree,
|
|
48
47
|
IndexChangedError,
|
|
48
|
+
isIndexUnborn,
|
|
49
49
|
type OperationOptions,
|
|
50
50
|
type SparseCheckoutPatterns,
|
|
51
51
|
type Staging,
|
|
@@ -62,6 +62,7 @@ import {
|
|
|
62
62
|
worktreeModeTrust,
|
|
63
63
|
} from "./commands/core-config.js";
|
|
64
64
|
import type { ForkPointSource } from "./commands/fork-point.js";
|
|
65
|
+
import { FSMONITOR_DAEMON_IPC_NAME, queryFsmonitorDaemon } from "./commands/fsmonitor-ipc.js";
|
|
65
66
|
import { type FsmonitorRun, refreshFsmonitor } from "./commands/fsmonitor-refresh.js";
|
|
66
67
|
import { type HookHost, HookSession, refTransactionHookOf } from "./commands/git-hooks.js";
|
|
67
68
|
import {
|
|
@@ -77,6 +78,7 @@ import { loadLegacyRemote } from "./commands/legacy-remotes.js";
|
|
|
77
78
|
import { type Mailmap, readRepositoryMailmap } from "./commands/mailmap.js";
|
|
78
79
|
import type { MergeBaseGraph } from "./commands/merge-bases.js";
|
|
79
80
|
import type { NotesContext } from "./commands/notes-support.js";
|
|
81
|
+
import { walkTreeDesc } from "./commands/plumbing-shared.js";
|
|
80
82
|
import { postIndexChangeHookOf } from "./commands/post-index-change.js";
|
|
81
83
|
import { createPromisorFetcher, promisorOf } from "./commands/promisor-remote.js";
|
|
82
84
|
import { reflogLine } from "./commands/reflog-messages.js";
|
|
@@ -456,11 +458,26 @@ export abstract class GitCommand<T> {
|
|
|
456
458
|
return refreshFsmonitor({
|
|
457
459
|
staging,
|
|
458
460
|
owner: this,
|
|
459
|
-
|
|
461
|
+
// fsm_settings: a bare repository is incompatible, the monitor off (tweak_fsmonitor
|
|
462
|
+
// then removes the extension)
|
|
463
|
+
config: (key) =>
|
|
464
|
+
key === "core.fsmonitor" && !this.hasWorktree() ? undefined : config.value(key),
|
|
460
465
|
ignoreCase: parseGitBool(config.value("core.ignorecase")) === true,
|
|
461
466
|
query: async (query) => {
|
|
462
467
|
if (environment?.fsmonitor) return environment.fsmonitor.query(query);
|
|
463
|
-
if (query.mode
|
|
468
|
+
if (query.mode === "ipc") {
|
|
469
|
+
// the builtin daemon at <git dir>/fsmonitor--daemon.ipc, through the host's port
|
|
470
|
+
if (!environment?.openIpcPort) return undefined;
|
|
471
|
+
const gitDir = await this.hooks.hostGitDir({ real: false });
|
|
472
|
+
if (!gitDir) return undefined;
|
|
473
|
+
const port = await environment.openIpcPort({
|
|
474
|
+
service: "fsmonitor--daemon",
|
|
475
|
+
path: `${gitDir}/${FSMONITOR_DAEMON_IPC_NAME}`,
|
|
476
|
+
});
|
|
477
|
+
const stdout = await queryFsmonitorDaemon(port, query.token);
|
|
478
|
+
return stdout ? { exitCode: 0, stdout } : undefined;
|
|
479
|
+
}
|
|
480
|
+
if (query.command === undefined) return undefined;
|
|
464
481
|
return this.hooks.runShellCommandBytes("fsmonitor", query.command, [
|
|
465
482
|
String(query.version),
|
|
466
483
|
query.token,
|
|
@@ -469,6 +486,11 @@ export abstract class GitCommand<T> {
|
|
|
469
486
|
});
|
|
470
487
|
}
|
|
471
488
|
|
|
489
|
+
/** Whether the working copy has a worktree (a bare repository's refuses to give one). */
|
|
490
|
+
protected hasWorktree(): boolean {
|
|
491
|
+
return "worktree" in this._workingCopy && !!this._workingCopy.worktree;
|
|
492
|
+
}
|
|
493
|
+
|
|
472
494
|
/**
|
|
473
495
|
* The hooks this command runs (git's `run_hooks_opt`), through the host environment's
|
|
474
496
|
* `hookRunner`; with none, no hook runs.
|
|
@@ -1285,8 +1307,14 @@ export abstract class GitCommand<T> {
|
|
|
1285
1307
|
*
|
|
1286
1308
|
* @param refuseUnwritten false for a command that writes no index (`clean`): unwritten
|
|
1287
1309
|
* edits are then kept and used instead of refusing
|
|
1310
|
+
*
|
|
1311
|
+
* The file system monitor is then asked (git's `tweak_fsmonitor`, see `fsmonitorRefresh`).
|
|
1288
1312
|
*/
|
|
1289
|
-
protected async readCurrentIndex(
|
|
1313
|
+
protected async readCurrentIndex(
|
|
1314
|
+
refuseUnwritten = true,
|
|
1315
|
+
/** false: the command asks the monitor itself (it needs what the read found first) */
|
|
1316
|
+
fsmonitor = true,
|
|
1317
|
+
): Promise<void> {
|
|
1290
1318
|
const staging = this.staging;
|
|
1291
1319
|
if (await staging.isOutdated()) {
|
|
1292
1320
|
if (staging.hasUnwrittenChanges?.() !== false) {
|
|
@@ -1296,6 +1324,10 @@ export abstract class GitCommand<T> {
|
|
|
1296
1324
|
await staging.read();
|
|
1297
1325
|
}
|
|
1298
1326
|
await this.clearPresentSkipWorktree();
|
|
1327
|
+
// do_read_index's tweak_fsmonitor: the monitor asked (an extension added when missing,
|
|
1328
|
+
// the valid bits dropped on a failed answer) for every index read, not only by the
|
|
1329
|
+
// commands that use the bits; a missing index file is read without it
|
|
1330
|
+
if (fsmonitor && !(await isIndexUnborn(staging))) await this.fsmonitorRefresh(staging);
|
|
1299
1331
|
}
|
|
1300
1332
|
|
|
1301
1333
|
/**
|
|
@@ -1349,7 +1381,7 @@ export abstract class GitCommand<T> {
|
|
|
1349
1381
|
});
|
|
1350
1382
|
}
|
|
1351
1383
|
|
|
1352
|
-
|
|
1384
|
+
protected resolveStaging(): Staging {
|
|
1353
1385
|
// Try new architecture first (checkout.staging)
|
|
1354
1386
|
if (this._workingCopy.checkout?.staging) {
|
|
1355
1387
|
return this._workingCopy.checkout.staging as unknown as Staging;
|
|
@@ -1689,26 +1721,35 @@ export abstract class GitCommand<T> {
|
|
|
1689
1721
|
}
|
|
1690
1722
|
|
|
1691
1723
|
/**
|
|
1692
|
-
* A tree's entries for a listing (`ls-tree`, `cat-file -p`), as
|
|
1693
|
-
*
|
|
1694
|
-
*
|
|
1724
|
+
* A tree's entries for a listing (`ls-tree`, `cat-file -p`, `ls-files --with-tree`), as
|
|
1725
|
+
* git's readers walk them (tree-walk.c's `tree_desc`, {@link walkTreeDesc}): from the stored
|
|
1726
|
+
* bytes, names not checked (a tree holding `..` lists), each entry yielded once the next one
|
|
1727
|
+
* decoded, a corrupt entry git's death ({@link CorruptTreeError}) when the walk reaches it.
|
|
1728
|
+
* Undefined when the tree cannot be read (missing, or not a tree).
|
|
1695
1729
|
*/
|
|
1696
|
-
protected async listedTreeEntries(id: ObjectId): Promise<
|
|
1730
|
+
protected async listedTreeEntries(id: ObjectId): Promise<Iterable<TreeEntry> | undefined> {
|
|
1731
|
+
const compat = this.compatObjects;
|
|
1732
|
+
if (compat && id.length !== this.objectFormat.hexLength) {
|
|
1733
|
+
// a tree named by its compatibility id (GET_OID_HASH_ANY): read converted, its entries
|
|
1734
|
+
// the compatibility format's ids, as git's parse_tree of such an id lists them
|
|
1735
|
+
const tree = await compat.readAsCompat(id).catch(() => undefined);
|
|
1736
|
+
if (tree?.type !== "tree") return undefined;
|
|
1737
|
+
return walkTreeDesc(tree.content, compat.compat.rawLength, id);
|
|
1738
|
+
}
|
|
1739
|
+
const trees = this.trees;
|
|
1740
|
+
if (trees.raw) {
|
|
1741
|
+
const raw = await trees.raw(id).catch(() => undefined);
|
|
1742
|
+
return raw ? walkTreeDesc(raw, this.objectFormat.rawLength, id) : undefined;
|
|
1743
|
+
}
|
|
1744
|
+
// a store without stored bytes: its decoded entries
|
|
1697
1745
|
try {
|
|
1698
|
-
const loaded = await
|
|
1746
|
+
const loaded = await trees.load(id);
|
|
1699
1747
|
if (!loaded) return undefined;
|
|
1700
1748
|
const entries: TreeEntry[] = [];
|
|
1701
1749
|
for await (const e of loaded) entries.push(e);
|
|
1702
1750
|
return entries;
|
|
1703
|
-
} catch
|
|
1704
|
-
|
|
1705
|
-
const raw = await this.trees.raw?.(id).catch(() => undefined);
|
|
1706
|
-
if (!raw) return undefined;
|
|
1707
|
-
return decodeTreeBytes(raw, {
|
|
1708
|
-
canonicalModes: true,
|
|
1709
|
-
idLength: this.objectFormat.rawLength,
|
|
1710
|
-
checkNames: false,
|
|
1711
|
-
});
|
|
1751
|
+
} catch {
|
|
1752
|
+
return undefined;
|
|
1712
1753
|
}
|
|
1713
1754
|
}
|
|
1714
1755
|
|
|
@@ -735,15 +735,23 @@ export class RemoteConfigStore {
|
|
|
735
735
|
/**
|
|
736
736
|
* Every variable whose canonical key starts with `prefix` (lower case), in the
|
|
737
737
|
* configuration's order with its text (undefined for a variable without `=`), as git's
|
|
738
|
-
* config callbacks see them
|
|
738
|
+
* config callbacks see them, and where each was read (file and line; none for the command
|
|
739
|
+
* line); undefined when the config cannot list its variables.
|
|
739
740
|
*/
|
|
740
|
-
entriesWithPrefix(
|
|
741
|
+
entriesWithPrefix(
|
|
742
|
+
prefix: string,
|
|
743
|
+
): { key: string; value: string | undefined; file?: string; line?: number }[] | undefined {
|
|
741
744
|
if (!this.config.listWithOrigin) return undefined;
|
|
742
745
|
const lower = prefix.toLowerCase();
|
|
743
746
|
return this.config
|
|
744
747
|
.listWithOrigin()
|
|
745
748
|
.filter((e) => e.key.startsWith(lower))
|
|
746
|
-
.map((e) => ({
|
|
749
|
+
.map((e) => ({
|
|
750
|
+
key: e.key,
|
|
751
|
+
value: e.text,
|
|
752
|
+
...(e.file !== undefined ? { file: e.file } : {}),
|
|
753
|
+
...(e.line !== undefined ? { line: e.line } : {}),
|
|
754
|
+
}));
|
|
747
755
|
}
|
|
748
756
|
|
|
749
757
|
/**
|
package/src/transport-command.ts
CHANGED
|
@@ -251,7 +251,10 @@ export abstract class TransportCommand<T> extends GitCommand<T> {
|
|
|
251
251
|
RemoteConfigStore.from(this._workingCopy),
|
|
252
252
|
url,
|
|
253
253
|
hostEnvironmentOf(this._workingCopy),
|
|
254
|
-
{
|
|
254
|
+
{
|
|
255
|
+
compatibility: this.hooks.compatibility,
|
|
256
|
+
...(this.warningCallback ? { onWarning: this.warningCallback } : {}),
|
|
257
|
+
},
|
|
255
258
|
);
|
|
256
259
|
return this.warningCallback ? { ...settings, onWarning: this.warningCallback } : settings;
|
|
257
260
|
}
|