@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
|
@@ -438,9 +438,14 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
438
438
|
// --hard: unpack-trees' one-way merge checks the entries whose flags cheat (assume-unchanged,
|
|
439
439
|
// skip-worktree) before anything changes; a file kept outside the worktree stays so
|
|
440
440
|
let flagged: FlaggedEntries | undefined;
|
|
441
|
+
let fsmKept: Map<string, StagingEntry> | undefined;
|
|
441
442
|
if (this.mode === ResetMode.HARD) {
|
|
442
443
|
const commit = await this.commits.load(targetId);
|
|
443
444
|
if (commit) {
|
|
445
|
+
// oneway_merge: what the file system monitor holds unchanged is not even lstat'ed
|
|
446
|
+
if (this.worktreeAccess) {
|
|
447
|
+
fsmKept = await fsmonitorKeptEntries(this.trees, this.staging, commit.tree);
|
|
448
|
+
}
|
|
444
449
|
flagged = await checkFlaggedEntries(
|
|
445
450
|
{
|
|
446
451
|
trees: this.trees,
|
|
@@ -508,7 +513,7 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
508
513
|
this.staging,
|
|
509
514
|
this.mode === ResetMode.HARD ? { workdir: true } : { skipWorktree: true },
|
|
510
515
|
);
|
|
511
|
-
await this.resetStaging(targetId);
|
|
516
|
+
await this.resetStaging(targetId, fsmKept);
|
|
512
517
|
}
|
|
513
518
|
// a mixed reset refreshes the index and lists what is left unstaged
|
|
514
519
|
if (this.mode === ResetMode.MIXED && (await this.refreshAfterReset())) {
|
|
@@ -523,6 +528,7 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
523
528
|
flagged?.keptOut,
|
|
524
529
|
sparse,
|
|
525
530
|
submodules && { unpack: submodules, oldIndex },
|
|
531
|
+
fsmKept && new Set(fsmKept.keys()),
|
|
526
532
|
);
|
|
527
533
|
// check_updates: the entries written carry the stat of their new files
|
|
528
534
|
if (this.worktreeAccess && written.size > 0) {
|
|
@@ -820,6 +826,7 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
820
826
|
keptOut?: ReadonlySet<string>,
|
|
821
827
|
sparse?: SparseUnpack,
|
|
822
828
|
submodules?: HardResetSubmodules,
|
|
829
|
+
unchanged?: ReadonlySet<string>,
|
|
823
830
|
): Promise<Set<string>> {
|
|
824
831
|
const worktree = this.worktreeAccess;
|
|
825
832
|
if (!worktree) {
|
|
@@ -838,19 +845,25 @@ export class ResetCommand extends GitCommand<Ref> {
|
|
|
838
845
|
keptOut,
|
|
839
846
|
sparse,
|
|
840
847
|
submodules,
|
|
848
|
+
unchanged,
|
|
841
849
|
);
|
|
842
850
|
}
|
|
843
851
|
|
|
844
852
|
/**
|
|
845
853
|
* Reset staging area to match a tree.
|
|
846
854
|
*/
|
|
847
|
-
private async resetStaging(
|
|
855
|
+
private async resetStaging(
|
|
856
|
+
commitId: ObjectId,
|
|
857
|
+
kept?: ReadonlyMap<string, StagingEntry>,
|
|
858
|
+
): Promise<void> {
|
|
848
859
|
const commit = await this.commits.load(commitId);
|
|
849
860
|
if (commit) {
|
|
850
861
|
if (this.mode !== ResetMode.MIXED) {
|
|
851
862
|
// oneway_merge: an unchanged entry keeps its flags, a changed one its skip-worktree
|
|
852
863
|
// bit (the stat data goes: every file is written again)
|
|
853
864
|
await this.staging.readTree(this.trees, commit.tree, { keepMatching: "flags" });
|
|
865
|
+
// an entry the file system monitor holds unchanged stays whole (oneway_merge)
|
|
866
|
+
if (kept) await restoreKeptEntries(this.staging, kept);
|
|
854
867
|
await this.primeCacheTree(commit.tree);
|
|
855
868
|
await this.staging.write();
|
|
856
869
|
return;
|
|
@@ -934,6 +947,8 @@ export async function restoreWorktreeHard(
|
|
|
934
947
|
keptOut?: ReadonlySet<string>,
|
|
935
948
|
sparse?: SparseUnpack,
|
|
936
949
|
submodules?: HardResetSubmodules,
|
|
950
|
+
/** Entries oneway_merge leaves alone (fsmonitor-valid and unchanged: `fsmonitorKeptEntries`) */
|
|
951
|
+
unchanged?: ReadonlySet<string>,
|
|
937
952
|
): Promise<Set<string>> {
|
|
938
953
|
const { trees, blobs, workingCopy, worktree } = deps;
|
|
939
954
|
const subs = submodules?.unpack;
|
|
@@ -952,11 +967,15 @@ export async function restoreWorktreeHard(
|
|
|
952
967
|
// a skip-worktree entry the tree keeps is not checked out (oneway_merge skips it); in a
|
|
953
968
|
// sparse checkout, nothing outside its patterns is (apply_sparse_checkout), and an entry
|
|
954
969
|
// coming back into them is written
|
|
955
|
-
const
|
|
970
|
+
const outside = sparse
|
|
956
971
|
? (path: string) => !sparse.writes(path)
|
|
957
972
|
: keptOut && keptOut.size > 0
|
|
958
973
|
? (path: string) => keptOut.has(path)
|
|
959
974
|
: undefined;
|
|
975
|
+
const skip =
|
|
976
|
+
unchanged && unchanged.size > 0
|
|
977
|
+
? (path: string) => unchanged.has(path) || !!outside?.(path)
|
|
978
|
+
: outside;
|
|
960
979
|
const plan = skip
|
|
961
980
|
? {
|
|
962
981
|
...fullPlan,
|
|
@@ -1050,6 +1069,59 @@ export async function recordWrittenStat(
|
|
|
1050
1069
|
if (edits > 0) await editor.finish();
|
|
1051
1070
|
}
|
|
1052
1071
|
|
|
1072
|
+
/**
|
|
1073
|
+
* unpack-trees' `oneway_merge` under a reset (`reset --hard`, `checkout -f`): a stage-0 entry
|
|
1074
|
+
* the target keeps unchanged and the file system monitor holds valid (`CE_FSMONITOR_VALID`)
|
|
1075
|
+
* is neither lstat'ed nor written, and stays in the index as it is, bit and stat included.
|
|
1076
|
+
* Only an entry the monitor was asked about in this command, and reported nothing for, is
|
|
1077
|
+
* held valid (`FsmonitorState.isValid`: exactly as marked); gitlinks and skip-worktree
|
|
1078
|
+
* entries never are here. The entries by path, empty when the monitor is off.
|
|
1079
|
+
*/
|
|
1080
|
+
export async function fsmonitorKeptEntries(
|
|
1081
|
+
trees: CommandTrees,
|
|
1082
|
+
staging: Staging,
|
|
1083
|
+
treeId: ObjectId,
|
|
1084
|
+
): Promise<Map<string, StagingEntry>> {
|
|
1085
|
+
const kept = new Map<string, StagingEntry>();
|
|
1086
|
+
const state = staging.getFsmonitor?.();
|
|
1087
|
+
if (!state?.hasRun) return kept;
|
|
1088
|
+
let target: Awaited<ReturnType<typeof flatTree>> | undefined;
|
|
1089
|
+
for await (const entry of staging.entries()) {
|
|
1090
|
+
if (entry.stage !== 0 || entry.mode === FileMode.GITLINK) continue;
|
|
1091
|
+
if (entry.skipWorktree || entry.intentToAdd || !state.isValid(entry)) continue;
|
|
1092
|
+
target ??= await flatTree(trees, treeId);
|
|
1093
|
+
const t = target.get(entry.path);
|
|
1094
|
+
if (t && t.mode === entry.mode && t.objectId === entry.objectId) kept.set(entry.path, entry);
|
|
1095
|
+
}
|
|
1096
|
+
return kept;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/**
|
|
1100
|
+
* After a one-way reset read the target into the index: the entries `oneway_merge` kept
|
|
1101
|
+
* (`fsmonitorKeptEntries`) put back exactly as they were (`add_entry` of the old entry), so
|
|
1102
|
+
* their stat and fsmonitor bit survive. Not written here.
|
|
1103
|
+
*/
|
|
1104
|
+
export async function restoreKeptEntries(
|
|
1105
|
+
staging: Staging,
|
|
1106
|
+
kept: ReadonlyMap<string, StagingEntry>,
|
|
1107
|
+
): Promise<void> {
|
|
1108
|
+
if (kept.size === 0) return;
|
|
1109
|
+
const editor = staging.createEditor();
|
|
1110
|
+
for (const old of kept.values()) {
|
|
1111
|
+
editor.add({
|
|
1112
|
+
path: old.path,
|
|
1113
|
+
apply: (existing) =>
|
|
1114
|
+
existing &&
|
|
1115
|
+
existing.stage === 0 &&
|
|
1116
|
+
existing.mode === old.mode &&
|
|
1117
|
+
existing.objectId === old.objectId
|
|
1118
|
+
? old
|
|
1119
|
+
: existing,
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
await editor.finish();
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1053
1125
|
/** What {@link checkFlaggedEntries} found. */
|
|
1054
1126
|
export interface FlaggedEntries {
|
|
1055
1127
|
/** The first path whose flagged entry the tree changes or deletes over a changed file. */
|
|
@@ -194,16 +194,14 @@ export class RevParseCommand extends GitCommand<RevParseResult> {
|
|
|
194
194
|
if (await this.tryParentShorthands(resolver, arg, lines)) continue;
|
|
195
195
|
const reversed = arg.startsWith("^");
|
|
196
196
|
let id: ObjectId | undefined;
|
|
197
|
-
if (output !== undefined) {
|
|
198
|
-
const translated = await this.translatedRevision(reversed ? arg.slice(1) : arg, output);
|
|
199
|
-
if (translated !== undefined) {
|
|
200
|
-
lines.push(reversed ? `^${translated}` : translated);
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
197
|
try {
|
|
205
|
-
|
|
206
|
-
|
|
198
|
+
// under --output-object-format git adds GET_OID_HASH_ANY: ids of the compatibility
|
|
199
|
+
// format, full or abbreviated, name objects too
|
|
200
|
+
id = await resolver.resolve(
|
|
201
|
+
reversed ? arg.slice(1) : arg,
|
|
202
|
+
output !== undefined ? { hashAny: true } : {},
|
|
203
|
+
);
|
|
204
|
+
if (id !== undefined && output !== undefined) id = await this.outputId(id, output);
|
|
207
205
|
} catch (error) {
|
|
208
206
|
if (error instanceof RevisionError && resolver.warnings.length > 0) {
|
|
209
207
|
throw new RevisionError(arg, [...resolver.warnings, error.message].join("\n"));
|
|
@@ -237,27 +235,15 @@ export class RevParseCommand extends GitCommand<RevParseResult> {
|
|
|
237
235
|
}
|
|
238
236
|
|
|
239
237
|
/**
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* gives (as given when it has none, as git's ignored `repo_oid_to_algop` failure leaves it).
|
|
243
|
-
* Undefined for anything else.
|
|
238
|
+
* `repo_oid_to_algop`: `id` (of either format) printed in the format asked, through the map;
|
|
239
|
+
* as it is when the map has no translation (git ignores that failure).
|
|
244
240
|
*/
|
|
245
|
-
private async
|
|
246
|
-
name: string,
|
|
247
|
-
output: "storage" | "compat",
|
|
248
|
-
): Promise<string | undefined> {
|
|
241
|
+
private async outputId(id: ObjectId, output: "storage" | "compat"): Promise<ObjectId> {
|
|
249
242
|
const compat = this.compatObjects;
|
|
250
|
-
if (!compat
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (output === "compat") return id;
|
|
255
|
-
return (await compat.toStorage(id)) ?? id;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** `id` in the compatibility format, as the map gives it (else as it is, as git) */
|
|
259
|
-
private async outputCompat(id: ObjectId): Promise<ObjectId> {
|
|
260
|
-
return (await this.compatObjects?.toCompat(id)) ?? id;
|
|
243
|
+
if (!compat) return id;
|
|
244
|
+
const isStorage = id.length === this.objectFormat.hexLength;
|
|
245
|
+
if (output === "storage") return isStorage ? id : ((await compat.toStorage(id)) ?? id);
|
|
246
|
+
return isStorage ? ((await compat.toCompat(id)) ?? id) : id;
|
|
261
247
|
}
|
|
262
248
|
|
|
263
249
|
/**
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
|
|
34
34
|
import type { Commit, GitObjects, ObjectId, PersonIdent, Refs } from "@statewalker/vcs-core";
|
|
35
35
|
import {
|
|
36
|
-
decodeTreeBytes,
|
|
37
36
|
isSymbolicRef,
|
|
38
37
|
isValidRefName,
|
|
39
38
|
listObjectsWithPrefix,
|
|
@@ -41,6 +40,7 @@ import {
|
|
|
41
40
|
objectFormatOf,
|
|
42
41
|
} from "@statewalker/vcs-core";
|
|
43
42
|
import { compilePosixRegex, isNullObjectId, parseGitBool } from "@statewalker/vcs-utils";
|
|
43
|
+
import { encodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
44
44
|
import type { Staging, WorkingCopy } from "@statewalker/vcs-working-tree";
|
|
45
45
|
|
|
46
46
|
import { RevisionError } from "../errors/index.js";
|
|
@@ -49,6 +49,7 @@ import { applyRefspecs } from "./branch-tracking.js";
|
|
|
49
49
|
import { configLoadError } from "./core-config.js";
|
|
50
50
|
import { approxidateCareful, formatRfc2822Date } from "./git-date.js";
|
|
51
51
|
import { loadLegacyRemote } from "./legacy-remotes.js";
|
|
52
|
+
import { findTreeDescEntry } from "./plumbing-shared.js";
|
|
52
53
|
|
|
53
54
|
/** The stores a revision is read from. */
|
|
54
55
|
export interface RevisionSources {
|
|
@@ -77,7 +78,7 @@ export interface RevisionSources {
|
|
|
77
78
|
* The object store, for abbreviated ids (its `listPrefix`, else `list`); without it the
|
|
78
79
|
* typed stores' `keys()` are listed
|
|
79
80
|
*/
|
|
80
|
-
objects?: Pick<GitObjects, "list" | "listPrefix" | "objectFormat">;
|
|
81
|
+
objects?: Pick<GitObjects, "list" | "listPrefix" | "objectFormat" | "compat">;
|
|
81
82
|
/**
|
|
82
83
|
* The lengths git abbreviates ids to (`repo_find_unique_abbrev` with `core.abbrev`), for
|
|
83
84
|
* the candidates of an ambiguous short id; 7 digits without it
|
|
@@ -119,6 +120,13 @@ export interface ResolveOptions {
|
|
|
119
120
|
* searched
|
|
120
121
|
*/
|
|
121
122
|
onlyToDie?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* git's `GET_OID_HASH_ANY` (`cat-file`, `ls-tree`, `rev-parse --output-object-format`): in
|
|
125
|
+
* a repository with a compatibility object format, an abbreviated or full id of that format
|
|
126
|
+
* names the object too, and is given back as it is (an id of the compatibility format's
|
|
127
|
+
* length), the storage and mapped compatibility ids disambiguated together
|
|
128
|
+
*/
|
|
129
|
+
hashAny?: boolean;
|
|
122
130
|
}
|
|
123
131
|
|
|
124
132
|
/** git's `get_short_oid` result. */
|
|
@@ -200,6 +208,13 @@ export class RevisionResolver {
|
|
|
200
208
|
lastMode: number | undefined;
|
|
201
209
|
private config?: RemoteConfigStore;
|
|
202
210
|
private disambiguateChecked = false;
|
|
211
|
+
/**
|
|
212
|
+
* Whether an abbreviation missed: git's get_short_oid then runs `odb_reprepare`, which
|
|
213
|
+
* flushes the loose object cache the map had put the compatibility ids into, and nothing
|
|
214
|
+
* puts them back, so the rest of the process finds no compatibility id by `GET_OID_HASH_ANY`
|
|
215
|
+
* (git master: `echo <miss> <compat id> | git cat-file --batch-check` reports both missing)
|
|
216
|
+
*/
|
|
217
|
+
private compatIdsFlushed = false;
|
|
203
218
|
/** Refs read while resolving one revision (`HEAD~3` reads HEAD once) */
|
|
204
219
|
private readonly refCache = new Map<string, Promise<{ id: ObjectId; ref: string } | undefined>>();
|
|
205
220
|
|
|
@@ -834,6 +849,11 @@ export class RevisionResolver {
|
|
|
834
849
|
|
|
835
850
|
/** The type of an object, undefined when the repository does not have it. */
|
|
836
851
|
async objectType(id: ObjectId): Promise<ObjectType | undefined> {
|
|
852
|
+
const compat = this.sources.objects?.compat;
|
|
853
|
+
if (compat && id.length !== this.hexLength && id.length === compat.compat.hexLength) {
|
|
854
|
+
// an id of the compatibility format (GET_OID_HASH_ANY): its object as converted
|
|
855
|
+
return (await safe(() => compat.readAsCompat(id)))?.type;
|
|
856
|
+
}
|
|
837
857
|
const { commits, tags, trees, blobs } = this.sources;
|
|
838
858
|
if (await safe(() => commits.has(id))) return "commit";
|
|
839
859
|
if (tags && (await safe(() => tags.has(id)))) return "tag";
|
|
@@ -912,40 +932,48 @@ export class RevisionResolver {
|
|
|
912
932
|
}
|
|
913
933
|
|
|
914
934
|
/**
|
|
915
|
-
* git's `get_tree_entry
|
|
916
|
-
*
|
|
917
|
-
*
|
|
935
|
+
* git's `get_tree_entry`: the object at `path` in a tree (the tree itself for ""), found
|
|
936
|
+
* as `find_tree_entry` walks the tree's stored bytes (names unchecked, so an entry named
|
|
937
|
+
* `..` is found; a corrupt tree git's death, {@link CorruptTreeError}). A store without
|
|
938
|
+
* stored bytes answers from its decoded entries, component by component.
|
|
918
939
|
*/
|
|
919
|
-
private async
|
|
920
|
-
tree
|
|
921
|
-
name: string,
|
|
922
|
-
): Promise<{ id: ObjectId; mode: number } | undefined> {
|
|
940
|
+
private async treeEntry(tree: ObjectId, path: string): Promise<ObjectId | undefined> {
|
|
941
|
+
if (path === "") return tree;
|
|
923
942
|
const trees = this.sources.trees;
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
943
|
+
if (!trees.raw) return this.treeEntryDecoded(tree, path);
|
|
944
|
+
const rawLength = objectFormatOf(this.sources.objects).rawLength;
|
|
945
|
+
let current = tree;
|
|
946
|
+
let rest = encodeGitPath(path);
|
|
947
|
+
for (;;) {
|
|
948
|
+
const id = current;
|
|
949
|
+
const raw = await safe(() => trees.raw?.(id) ?? Promise.resolve(undefined));
|
|
950
|
+
// an empty tree holds nothing (get_tree_entry's `!size`)
|
|
929
951
|
if (!raw) return undefined;
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
952
|
+
const found = findTreeDescEntry(raw, rawLength, rest, current);
|
|
953
|
+
if (!found) return undefined;
|
|
954
|
+
if (!found.rest) {
|
|
955
|
+
this.lastMode = found.mode;
|
|
956
|
+
return found.id;
|
|
957
|
+
}
|
|
958
|
+
current = found.id;
|
|
959
|
+
rest = found.rest;
|
|
937
960
|
}
|
|
938
961
|
}
|
|
939
962
|
|
|
940
|
-
|
|
941
|
-
|
|
963
|
+
/**
|
|
964
|
+
* {@link treeEntry} over a store's decoded entries: components matched exactly, an empty
|
|
965
|
+
* one (`/a`, `d//b`) names nothing, a trailing `/` only follows a directory.
|
|
966
|
+
*/
|
|
967
|
+
private async treeEntryDecoded(tree: ObjectId, path: string): Promise<ObjectId | undefined> {
|
|
968
|
+
const trees = this.sources.trees;
|
|
942
969
|
let current = tree;
|
|
943
970
|
let rest = path;
|
|
944
971
|
for (;;) {
|
|
945
972
|
const slash = rest.indexOf("/");
|
|
946
973
|
const name = slash < 0 ? rest : rest.slice(0, slash);
|
|
947
974
|
if (name === "") return undefined;
|
|
948
|
-
const
|
|
975
|
+
const at = current;
|
|
976
|
+
const entry = await safe(() => trees.getEntry(at, name));
|
|
949
977
|
if (!entry) return undefined;
|
|
950
978
|
if (slash < 0) {
|
|
951
979
|
this.lastMode = entry.mode;
|
|
@@ -1076,16 +1104,26 @@ export class RevisionResolver {
|
|
|
1076
1104
|
* when it accepts several.
|
|
1077
1105
|
*/
|
|
1078
1106
|
private async shortOid(name: string, flags: ResolveOptions = {}): Promise<ShortOid> {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
!
|
|
1083
|
-
)
|
|
1107
|
+
// GET_OID_HASH_ANY: the prefix may be of either format (init_object_disambiguation takes
|
|
1108
|
+
// up to GIT_MAX_HEXSZ digits), the map's compatibility ids searched beside the objects
|
|
1109
|
+
const compat =
|
|
1110
|
+
flags.hashAny && !this.compatIdsFlushed ? this.sources.objects?.compat : undefined;
|
|
1111
|
+
const maxLength = Math.max(this.hexLength, compat?.compat.hexLength ?? 0);
|
|
1112
|
+
if (name.length < MINIMUM_ABBREV_LENGTH || name.length > maxLength || !HEX_DIGITS.test(name)) {
|
|
1084
1113
|
return { status: "invalid" };
|
|
1085
1114
|
}
|
|
1086
1115
|
const prefix = name.toLowerCase();
|
|
1087
|
-
const candidates = await this.objectsWithPrefix(prefix);
|
|
1088
|
-
if (
|
|
1116
|
+
const candidates = name.length <= this.hexLength ? await this.objectsWithPrefix(prefix) : [];
|
|
1117
|
+
if (compat && name.length <= compat.compat.hexLength) {
|
|
1118
|
+
const ids = await compat.compatIdsWithPrefix(prefix);
|
|
1119
|
+
// the reserved mappings (empty tree and blob, null id) are in git's cache too
|
|
1120
|
+
for (const id of ids) if (!candidates.includes(id)) candidates.push(id);
|
|
1121
|
+
candidates.sort();
|
|
1122
|
+
}
|
|
1123
|
+
if (candidates.length === 0) {
|
|
1124
|
+
if (this.sources.objects?.compat) this.compatIdsFlushed = true;
|
|
1125
|
+
return { status: "missing" };
|
|
1126
|
+
}
|
|
1089
1127
|
const hint = flags.hint ?? this.defaultHint();
|
|
1090
1128
|
let status: ShortOid;
|
|
1091
1129
|
let listedHint = hint;
|
|
@@ -1117,17 +1155,30 @@ export class RevisionResolver {
|
|
|
1117
1155
|
): Promise<void> {
|
|
1118
1156
|
const typed: { id: ObjectId; type: ObjectType | undefined }[] = [];
|
|
1119
1157
|
for (const id of candidates) typed.push({ id, type: await this.objectType(id) });
|
|
1120
|
-
// tags, commits, trees, blobs (git's type % 4);
|
|
1158
|
+
// tags, commits, trees, blobs (git's type % 4); within a type by hash algorithm (SHA-1
|
|
1159
|
+
// ids, the shorter, before SHA-256 ones: oidcmp's algo order), then by id
|
|
1121
1160
|
const rank = (t: ObjectType | undefined) =>
|
|
1122
1161
|
t === "tag" ? 0 : t === "commit" ? 1 : t === "tree" ? 2 : t === "blob" ? 3 : -1;
|
|
1123
1162
|
typed.sort((a, b) =>
|
|
1124
|
-
rank(a.type) !== rank(b.type)
|
|
1163
|
+
rank(a.type) !== rank(b.type)
|
|
1164
|
+
? rank(a.type) - rank(b.type)
|
|
1165
|
+
: a.id.length !== b.id.length
|
|
1166
|
+
? a.id.length - b.id.length
|
|
1167
|
+
: a.id < b.id
|
|
1168
|
+
? -1
|
|
1169
|
+
: 1,
|
|
1125
1170
|
);
|
|
1126
1171
|
const shown: typeof typed = [];
|
|
1127
1172
|
for (const c of typed)
|
|
1128
1173
|
if (hint === undefined || (await this.satisfies(c.id, hint))) shown.push(c);
|
|
1174
|
+
// compatibility ids are abbreviated to the default 7 digits (only storage ids are
|
|
1175
|
+
// measured against the repository)
|
|
1129
1176
|
const lengths =
|
|
1130
|
-
(await safe(async () =>
|
|
1177
|
+
(await safe(async () =>
|
|
1178
|
+
this.sources.abbreviate?.(
|
|
1179
|
+
shown.filter((c) => c.id.length === this.hexLength).map((c) => c.id),
|
|
1180
|
+
),
|
|
1181
|
+
)) ?? undefined;
|
|
1131
1182
|
const lines = [`error: short object ID ${prefix} is ambiguous`, "hint: The candidates are:"];
|
|
1132
1183
|
for (const { id, type } of shown) {
|
|
1133
1184
|
const hash = id.slice(0, lengths?.get(id) ?? 7);
|
package/src/commands/signing.ts
CHANGED
|
@@ -27,7 +27,12 @@
|
|
|
27
27
|
* alternative, warning and going on unsigned (friendlier to hosts that set `gpgSign`
|
|
28
28
|
* globally), was not taken; switch only on the human's word.
|
|
29
29
|
*/
|
|
30
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
type AnnotatedTag,
|
|
32
|
+
type Commit,
|
|
33
|
+
collectCommitBytes,
|
|
34
|
+
type PersonIdent,
|
|
35
|
+
} from "@statewalker/vcs-core";
|
|
31
36
|
import { createSha256, parseGitBool } from "@statewalker/vcs-utils";
|
|
32
37
|
import {
|
|
33
38
|
expandUserPath,
|
|
@@ -386,18 +391,60 @@ export async function signCommit(
|
|
|
386
391
|
options: Omit<SignPayloadOptions, "committer"> = {},
|
|
387
392
|
): Promise<Commit> {
|
|
388
393
|
if (sign === undefined) return commit;
|
|
389
|
-
const { gpgSignature: _dropped, ...unsigned } = commit;
|
|
394
|
+
const { gpgSignature: _dropped, compatSignature: _droppedCompat, ...unsigned } = commit;
|
|
390
395
|
const payload = await collectCommitBytes(unsigned);
|
|
396
|
+
const signOptions = { ...options, committer: commit.committer };
|
|
391
397
|
const signature = new TextDecoder().decode(
|
|
392
|
-
await signPayload(workingCopy, sign, payload,
|
|
398
|
+
await signPayload(workingCopy, sign, payload, signOptions),
|
|
393
399
|
);
|
|
394
400
|
// add_header_signature: every line of the signature with its newline, the first after the
|
|
395
401
|
// header's name and a space, the others after a space; the header ends with the
|
|
396
402
|
// signature's last newline (the commit model holds the lines without it)
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
403
|
+
const signed: Commit = { ...unsigned, gpgSignature: headerSignature(signature) };
|
|
404
|
+
// commit_tree_extended in a repository with a compatibility object format: the commit as
|
|
405
|
+
// that format sees it (its ids mapped) signed too, and both signatures in both objects, so
|
|
406
|
+
// the compatibility id the store computes covers a signature in its own format
|
|
407
|
+
const compat = workingCopy.history.objects?.compat;
|
|
408
|
+
if (compat) {
|
|
409
|
+
const compatPayload = await compat.convertToCompat("commit", payload);
|
|
410
|
+
const compatSignature = new TextDecoder().decode(
|
|
411
|
+
await signPayload(workingCopy, sign, compatPayload, signOptions),
|
|
412
|
+
);
|
|
413
|
+
signed.compatSignature = {
|
|
414
|
+
header: compat.compat.signatureHeader,
|
|
415
|
+
value: headerSignature(compatSignature),
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
return signed;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* A signature as a header holds it: its lines without the last newline (add_header_signature
|
|
423
|
+
* writes each line with its newline).
|
|
424
|
+
*/
|
|
425
|
+
function headerSignature(signature: string): string {
|
|
426
|
+
return signature.endsWith("\n") ? signature.slice(0, -1) : signature;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* builtin/tag.c `do_sign` in a repository with a compatibility object format: the tag as
|
|
431
|
+
* that format sees it signed too, its signature to go in the tag's header (the storage
|
|
432
|
+
* signature ends the message), so the tag's compatibility id covers a signature in its own
|
|
433
|
+
* format. Undefined without a compatibility format.
|
|
434
|
+
*/
|
|
435
|
+
export async function signTagCompat(
|
|
436
|
+
workingCopy: WorkingCopy,
|
|
437
|
+
sign: string,
|
|
438
|
+
payload: Uint8Array,
|
|
439
|
+
options: SignPayloadOptions,
|
|
440
|
+
): Promise<AnnotatedTag["compatSignature"]> {
|
|
441
|
+
const compat = workingCopy.history.objects?.compat;
|
|
442
|
+
if (!compat) return undefined;
|
|
443
|
+
const compatPayload = await compat.convertToCompat("tag", payload);
|
|
444
|
+
const signature = new TextDecoder().decode(
|
|
445
|
+
await signPayload(workingCopy, sign, compatPayload, options),
|
|
446
|
+
);
|
|
447
|
+
return { header: compat.compat.signatureHeader, value: headerSignature(signature) };
|
|
401
448
|
}
|
|
402
449
|
|
|
403
450
|
/** A uint32 length-prefixed string of an ssh wire buffer at `at`. */
|
|
@@ -218,6 +218,22 @@ async function concat(chunks: AsyncIterable<Uint8Array> | Iterable<Uint8Array>)
|
|
|
218
218
|
export interface SubmoduleDirt {
|
|
219
219
|
modified?: boolean;
|
|
220
220
|
untracked?: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* The repository could not be looked into because git opens it and we do not (an
|
|
223
|
+
* `extensions.objectStorage` payload): its warning lines. Its own changes are then unknown
|
|
224
|
+
* (no `modified`/`untracked`); a commit other than the index's still shows, read from refs.
|
|
225
|
+
*/
|
|
226
|
+
unreadable?: string[];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The warning lines for a submodule we cannot look into (git opens it, we do not), or
|
|
231
|
+
* undefined for any other failure, which stays fatal as git's child status dies on it.
|
|
232
|
+
*/
|
|
233
|
+
export function submoduleNotSupportedWarning(path: string, error: unknown): string[] | undefined {
|
|
234
|
+
if (!(error instanceof Error) || error.name !== "UnsupportedRepositoryFormatError") return;
|
|
235
|
+
if (!(error as { notSupportedHere?: boolean }).notSupportedHere) return;
|
|
236
|
+
return [`warning: cannot look into submodule '${path}': ${error.message}`];
|
|
221
237
|
}
|
|
222
238
|
|
|
223
239
|
/**
|
|
@@ -227,14 +243,23 @@ export interface SubmoduleDirt {
|
|
|
227
243
|
* untracked content; any other change, a nested submodule's included, is modified content.
|
|
228
244
|
* Nothing for a submodule that is not populated (or that the worktree cannot open). A
|
|
229
245
|
* configuration the inner status cannot read fails with its messages and git's
|
|
230
|
-
* `'git status --porcelain=2' failed in submodule <path>`.
|
|
246
|
+
* `'git status --porcelain=2' failed in submodule <path>`. A repository git opens and we do
|
|
247
|
+
* not (an `extensions.objectStorage` payload, statewalker/webrun-vcs#441) is no failure of
|
|
248
|
+
* the superproject: its state is `unreadable`, with a warning.
|
|
231
249
|
*/
|
|
232
250
|
export async function readSubmoduleDirt(
|
|
233
251
|
worktree: Worktree,
|
|
234
252
|
path: string,
|
|
235
253
|
ignoreUntracked: boolean,
|
|
236
254
|
): Promise<SubmoduleDirt> {
|
|
237
|
-
|
|
255
|
+
let inner: WorkingCopy | undefined;
|
|
256
|
+
try {
|
|
257
|
+
inner = await worktree.openGitlink?.(path);
|
|
258
|
+
} catch (error) {
|
|
259
|
+
const unreadable = submoduleNotSupportedWarning(path, error);
|
|
260
|
+
if (unreadable) return { unreadable };
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
238
263
|
if (!inner) return {};
|
|
239
264
|
// `git status --porcelain=2` there, with `-uno` when untracked content is ignored
|
|
240
265
|
const command = new StatusCommand(inner).setRenames(false);
|
|
@@ -878,6 +903,8 @@ export class StatusCommand extends GitCommand<Status> {
|
|
|
878
903
|
const indexTime = this.staging.getUpdateTime();
|
|
879
904
|
const gitlinks = new Set<string>();
|
|
880
905
|
const refresh: IndexStatUpdate[] = [];
|
|
906
|
+
// submodules we cannot look into (a repository git opens and we do not)
|
|
907
|
+
const submoduleWarnings: string[] = [];
|
|
881
908
|
const unmerged = new Map<string, [StatusSide?, StatusSide?, StatusSide?]>();
|
|
882
909
|
// the `.gitignore` files whose entry is up to date (git's ce_uptodate after its refresh):
|
|
883
910
|
// the untracked cache takes their ids from the index
|
|
@@ -1005,6 +1032,7 @@ export class StatusCommand extends GitCommand<Status> {
|
|
|
1005
1032
|
// a populated submodule's own index and worktree (git's is_submodule_modified)
|
|
1006
1033
|
if (flags && !flags.dirty && result.worktreeEntry?.isDirectory) {
|
|
1007
1034
|
dirt = await readSubmoduleDirt(worktree, entry.path, flags.untracked);
|
|
1035
|
+
if (dirt.unreadable) submoduleWarnings.push(...dirt.unreadable);
|
|
1008
1036
|
}
|
|
1009
1037
|
if (result.kind === "deleted") {
|
|
1010
1038
|
y = "D";
|
|
@@ -1065,6 +1093,7 @@ export class StatusCommand extends GitCommand<Status> {
|
|
|
1065
1093
|
|
|
1066
1094
|
const renamed = new Map<string, string>();
|
|
1067
1095
|
const warnings: string[] = (fsm?.warnings ?? []).map((w) => `warning: ${w}`);
|
|
1096
|
+
warnings.push(...submoduleWarnings);
|
|
1068
1097
|
const renameMode = this.renameMode();
|
|
1069
1098
|
if (renameMode) await this.pairRenames(files, renamed, worktree, warnings, renameMode);
|
|
1070
1099
|
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
* `clone_submodule`, `configure_added_submodule`), over the submodule model of
|
|
4
4
|
* `submodule-model.ts` and the clone, checkout and add commands.
|
|
5
5
|
*/
|
|
6
|
+
|
|
6
7
|
import { FileMode } from "@statewalker/vcs-core";
|
|
7
8
|
import type { GitTransportRegistry, HttpCredentialHelper } from "@statewalker/vcs-transport";
|
|
8
9
|
import { wildmatch } from "@statewalker/vcs-working-tree";
|
|
9
|
-
|
|
10
10
|
import { GitApiError } from "../errors/index.js";
|
|
11
11
|
import { RemoteConfigStore } from "../remote-config/index.js";
|
|
12
12
|
import { AddCommand } from "./add-command.js";
|
|
13
13
|
import { CheckoutCommand } from "./checkout-command.js";
|
|
14
|
+
import { unknownObjectStorageFormat } from "./default-branch.js";
|
|
14
15
|
import { checkSubmoduleName } from "./fsck/fsck-object-checks.js";
|
|
15
16
|
import { gitFileOf } from "./git-hooks.js";
|
|
16
17
|
import { DO_MATCH_DIRECTORY, matchPathspec, parsePathspec } from "./pathspec.js";
|
|
@@ -153,6 +154,7 @@ export class SubmoduleAddCommand extends SubmoduleCommandBase {
|
|
|
153
154
|
private force = false;
|
|
154
155
|
private reference?: string;
|
|
155
156
|
private depth?: number;
|
|
157
|
+
private objectStorageFormat?: string;
|
|
156
158
|
private transports?: GitTransportRegistry;
|
|
157
159
|
private credentialHelper?: HttpCredentialHelper;
|
|
158
160
|
private warningCallback?: (line: string) => void;
|
|
@@ -199,6 +201,17 @@ export class SubmoduleAddCommand extends SubmoduleCommandBase {
|
|
|
199
201
|
return this;
|
|
200
202
|
}
|
|
201
203
|
|
|
204
|
+
/**
|
|
205
|
+
* `--object-storage-format=<name>` (git master): the object storage of the submodules
|
|
206
|
+
* cloned. Only `files` is a name git knows (the repository as always); anything else,
|
|
207
|
+
* `files://<dir>` included, dies `unknown object storage format '<v>'` before any work.
|
|
208
|
+
*/
|
|
209
|
+
setObjectStorageFormat(format: string): this {
|
|
210
|
+
this.checkCallable();
|
|
211
|
+
this.objectStorageFormat = format;
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
|
|
202
215
|
/** `--depth <n>`: a shallow clone (ignored, with git's warning, for a local path). */
|
|
203
216
|
setDepth(depth: number): this {
|
|
204
217
|
this.checkCallable();
|
|
@@ -232,6 +245,10 @@ export class SubmoduleAddCommand extends SubmoduleCommandBase {
|
|
|
232
245
|
|
|
233
246
|
async call(): Promise<SubmoduleCommandResult> {
|
|
234
247
|
this.start();
|
|
248
|
+
if (this.objectStorageFormat !== undefined) {
|
|
249
|
+
const unknown = unknownObjectStorageFormat(this.objectStorageFormat, "name");
|
|
250
|
+
if (unknown) this.die(unknown);
|
|
251
|
+
}
|
|
235
252
|
if (!(await this.writingGitmodulesOk())) {
|
|
236
253
|
this.die("fatal: please make sure that the .gitmodules file is in the working tree");
|
|
237
254
|
}
|