@statewalker/vcs-commands 0.3.2 → 0.5.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/README.md +19 -0
- package/dist/commands/add-command.d.ts +0 -6
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/blame-command.d.ts +14 -0
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/checkout-command.d.ts +7 -24
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +34 -4
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +61 -21
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts +16 -0
- package/dist/commands/core-config.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +104 -37
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +2 -2
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/merge-command.d.ts +15 -2
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +58 -25
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/remote-command.d.ts +115 -6
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/stash-apply-command.d.ts +35 -13
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +59 -25
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +8 -2
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-list-command.d.ts +2 -4
- package/dist/commands/stash-list-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +72 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +29 -22
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tree-restore.d.ts +52 -5
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/worktree-overwrite-checks.d.ts +64 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
- package/dist/{commands-COO4tJhv.js → commands-CsLNyvZ1.js} +3370 -1057
- package/dist/core-commands/add.command.impl.d.ts +0 -4
- package/dist/core-commands/add.command.impl.d.ts.map +1 -1
- package/dist/core-commands/index.d.ts +1 -3
- package/dist/core-commands/index.d.ts.map +1 -1
- package/dist/core-commands/store-worktree-file.d.ts +6 -0
- package/dist/core-commands/store-worktree-file.d.ts.map +1 -0
- package/dist/errors/checkout-errors.d.ts +13 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/index.js +18 -1
- package/dist/git-command.d.ts +10 -1
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +21 -3
- package/dist/git.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/remote-config/index.d.ts +1 -0
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +22 -0
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +37 -0
- package/dist/remote-config/remote-refs.d.ts.map +1 -0
- package/dist/results/clone-result.d.ts +6 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts +14 -7
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/fetch-result.d.ts +16 -1
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.js +28 -23
- package/dist/results/push-result.d.ts +9 -2
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +91 -20
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/{status-result-BwAyxq6R.js → status-result-BpyUK1Sg.js} +115 -5
- package/dist/transport-command.d.ts +12 -0
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +14 -12
- package/src/commands/add-command.ts +23 -30
- package/src/commands/blame-command.ts +41 -0
- package/src/commands/branch-command.ts +2 -53
- package/src/commands/checkout-command.ts +205 -127
- package/src/commands/clean-command.ts +187 -81
- package/src/commands/clone-command.ts +334 -137
- package/src/commands/core-config.ts +41 -0
- package/src/commands/fetch-command.ts +536 -211
- package/src/commands/gc-command.ts +1 -1
- package/src/commands/index.ts +1 -0
- package/src/commands/init-command.ts +108 -11
- package/src/commands/merge-command.ts +60 -27
- package/src/commands/pack-refs-command.ts +2 -2
- package/src/commands/push-command.ts +242 -308
- package/src/commands/reflog-command.ts +2 -2
- package/src/commands/remote-command.ts +429 -19
- package/src/commands/reset-command.ts +18 -5
- package/src/commands/stash-apply-command.ts +632 -97
- package/src/commands/stash-create-command.ts +142 -62
- package/src/commands/stash-drop-command.ts +53 -5
- package/src/commands/stash-list-command.ts +10 -4
- package/src/commands/stash-working-tree.ts +243 -0
- package/src/commands/status-command.ts +197 -91
- package/src/commands/tag-command.ts +2 -53
- package/src/commands/tree-restore.ts +143 -18
- package/src/commands/worktree-overwrite-checks.ts +215 -0
- package/src/core-commands/add.command.impl.ts +15 -20
- package/src/core-commands/index.ts +1 -8
- package/src/core-commands/store-worktree-file.ts +5 -0
- package/src/errors/checkout-errors.ts +20 -0
- package/src/git-command.ts +42 -1
- package/src/git.ts +30 -2
- package/src/remote-config/index.ts +1 -0
- package/src/remote-config/remote-config-store.ts +95 -8
- package/src/remote-config/remote-refs.ts +103 -0
- package/src/results/clone-result.ts +6 -0
- package/src/results/diff-formatter.ts +31 -38
- package/src/results/fetch-result.ts +16 -1
- package/src/results/push-result.ts +9 -2
- package/src/results/status-result.ts +212 -29
- package/src/transport-command.ts +18 -0
- package/dist/core-commands/checkout.command.d.ts +0 -103
- package/dist/core-commands/checkout.command.d.ts.map +0 -1
- package/dist/core-commands/checkout.command.impl.d.ts +0 -114
- package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
- package/dist/pack-import/index.d.ts +0 -8
- package/dist/pack-import/index.d.ts.map +0 -1
- package/dist/pack-import/pack-import.d.ts +0 -11
- package/dist/pack-import/pack-import.d.ts.map +0 -1
- package/src/core-commands/checkout.command.impl.ts +0 -586
- package/src/core-commands/checkout.command.ts +0 -125
- package/src/pack-import/index.ts +0 -8
- package/src/pack-import/pack-import.ts +0 -24
|
@@ -123,7 +123,7 @@ export class GarbageCollectCommand extends GitCommand<GCCommandResult> {
|
|
|
123
123
|
|
|
124
124
|
// Run garbage collection if GCController is available
|
|
125
125
|
// Note: This requires access to the Repository's gc property
|
|
126
|
-
// For now, we'll check if the
|
|
126
|
+
// For now, we'll check if the ref store supports the gc operations
|
|
127
127
|
|
|
128
128
|
// Check if refs support packRefs
|
|
129
129
|
if (this._packRefs && this.refsStore.packRefs) {
|
package/src/commands/index.ts
CHANGED
|
@@ -27,5 +27,6 @@ export * from "./stash-apply-command.js";
|
|
|
27
27
|
export * from "./stash-create-command.js";
|
|
28
28
|
export * from "./stash-drop-command.js";
|
|
29
29
|
export * from "./stash-list-command.js";
|
|
30
|
+
export * from "./stash-working-tree.js";
|
|
30
31
|
export * from "./status-command.js";
|
|
31
32
|
export * from "./tag-command.js";
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
createInMemoryFilesApi,
|
|
3
|
+
createMemoryHistory,
|
|
4
|
+
type FilesApi,
|
|
5
|
+
type History,
|
|
6
|
+
type PosixFilesApi,
|
|
7
|
+
} from "@statewalker/vcs-core";
|
|
8
|
+
import {
|
|
9
|
+
createFileWorktree,
|
|
10
|
+
createGitFilesHistoryFromFiles,
|
|
11
|
+
FileStagingStore,
|
|
12
|
+
probeCaseFolding,
|
|
13
|
+
resolveLinkedGitDir,
|
|
14
|
+
} from "@statewalker/vcs-store-files";
|
|
3
15
|
import { MemoryStagingStore } from "@statewalker/vcs-store-mem";
|
|
4
16
|
import {
|
|
5
17
|
createMemoryCheckout,
|
|
@@ -219,15 +231,68 @@ export class InitCommand {
|
|
|
219
231
|
// Determine git directory
|
|
220
232
|
const gitDir = this.resolveGitDir();
|
|
221
233
|
|
|
222
|
-
// Create the history (repository)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
234
|
+
// Create the history (repository). With a FilesApi it lives in `gitDir` on those files,
|
|
235
|
+
// in git's layout, so it survives a reload and native git can read it; like `git init`
|
|
236
|
+
// on an existing repository, a second init keeps its HEAD, config and objects. Without
|
|
237
|
+
// one it stays in memory.
|
|
238
|
+
let history: History;
|
|
239
|
+
let staging: Staging;
|
|
240
|
+
if (this.files) {
|
|
241
|
+
const dir = gitDir.replace(/\/+$/, "") || ".";
|
|
242
|
+
// a `.git` the user linked elsewhere is followed (resolved through the FilesApi)
|
|
243
|
+
const repoFiles = await resolveLinkedGitDir(files, dir);
|
|
244
|
+
const isFile = async (path: string) => (await repoFiles.stats(path))?.kind === "file";
|
|
245
|
+
const hasHead = await isFile(`${dir}/HEAD`);
|
|
246
|
+
// A repository with a config but no HEAD (damaged or half-made) is opened, not
|
|
247
|
+
// re-created: creating rewrites the config, and its remotes and settings with it.
|
|
248
|
+
const fresh = !hasHead && !(await isFile(`${dir}/config`));
|
|
249
|
+
const open = (create: boolean) =>
|
|
250
|
+
createGitFilesHistoryFromFiles({
|
|
251
|
+
files: repoFiles,
|
|
252
|
+
gitDir,
|
|
253
|
+
create,
|
|
254
|
+
defaultBranch: this.initialBranch,
|
|
255
|
+
});
|
|
256
|
+
if (fresh && this.bare && dir !== ".") {
|
|
257
|
+
// The directory layout writes `core.bare = true` only for a gitDir of "."; set it
|
|
258
|
+
// before opening, so what reads the config (reflog defaults) sees a bare repository.
|
|
259
|
+
await open(true);
|
|
260
|
+
await markBare(repoFiles, `${dir}/config`);
|
|
261
|
+
history = await open(false);
|
|
262
|
+
} else {
|
|
263
|
+
history = await open(fresh);
|
|
264
|
+
}
|
|
265
|
+
await history.initialize();
|
|
266
|
+
if (fresh) {
|
|
267
|
+
// git init's probe: a filesystem that folds case or Unicode composition
|
|
268
|
+
const folding = await probeCaseFolding(repoFiles as PosixFilesApi, dir);
|
|
269
|
+
if (folding.ignoreCase)
|
|
270
|
+
await setCoreValue(repoFiles, `${dir}/config`, "ignorecase", "true");
|
|
271
|
+
if (folding.precomposeUnicode) {
|
|
272
|
+
await setCoreValue(repoFiles, `${dir}/config`, "precomposeunicode", "true");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (!hasHead && !fresh) {
|
|
276
|
+
await history.refs.setSymbolic("HEAD", `refs/heads/${this.initialBranch}`);
|
|
277
|
+
}
|
|
278
|
+
// The index lives in the repository too: a reopened repository keeps what was staged
|
|
279
|
+
// (its last commit's files), so the next commit does not drop them.
|
|
280
|
+
if (this.stagingStore) {
|
|
281
|
+
staging = this.stagingStore;
|
|
282
|
+
} else if (this.bare) {
|
|
283
|
+
staging = new MemoryStagingStore();
|
|
284
|
+
} else {
|
|
285
|
+
const fileStaging = new FileStagingStore(repoFiles, `${dir}/index`);
|
|
286
|
+
await fileStaging.read();
|
|
287
|
+
staging = fileStaging;
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
history = createMemoryHistory();
|
|
291
|
+
await history.initialize();
|
|
292
|
+
// Set initial branch by creating symbolic ref for HEAD
|
|
293
|
+
await history.refs.setSymbolic("HEAD", `refs/heads/${this.initialBranch}`);
|
|
294
|
+
staging = this.stagingStore ?? new MemoryStagingStore();
|
|
295
|
+
}
|
|
231
296
|
|
|
232
297
|
// Create worktree if enabled and not bare
|
|
233
298
|
let worktree: Worktree | undefined;
|
|
@@ -363,3 +428,35 @@ export class InitCommand {
|
|
|
363
428
|
this.callable = value;
|
|
364
429
|
}
|
|
365
430
|
}
|
|
431
|
+
|
|
432
|
+
/** Sets `core.bare = true` in a config file written by the git directory layout. */
|
|
433
|
+
async function markBare(files: FilesApi, configPath: string): Promise<void> {
|
|
434
|
+
await setCoreValue(files, configPath, "bare", "true");
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Sets `core.<key>` in the fresh config `init` wrote (one `[core]` section). */
|
|
438
|
+
async function setCoreValue(
|
|
439
|
+
files: FilesApi,
|
|
440
|
+
configPath: string,
|
|
441
|
+
key: string,
|
|
442
|
+
value: string,
|
|
443
|
+
): Promise<void> {
|
|
444
|
+
const chunks: Uint8Array[] = [];
|
|
445
|
+
for await (const chunk of files.read(configPath)) chunks.push(chunk);
|
|
446
|
+
const text = new TextDecoder().decode(concatChunks(chunks));
|
|
447
|
+
const existing = new RegExp(`^(\\s*${key}\\s*=\\s*)\\S+`, "mi");
|
|
448
|
+
const updated = existing.test(text)
|
|
449
|
+
? text.replace(existing, `$1${value}`)
|
|
450
|
+
: text.replace(/^\[core\]\s*$/m, `[core]\n\t${key} = ${value}`);
|
|
451
|
+
await files.write(configPath, [new TextEncoder().encode(updated)]);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function concatChunks(chunks: Uint8Array[]): Uint8Array {
|
|
455
|
+
const out = new Uint8Array(chunks.reduce((n, c) => n + c.length, 0));
|
|
456
|
+
let offset = 0;
|
|
457
|
+
for (const c of chunks) {
|
|
458
|
+
out.set(c, offset);
|
|
459
|
+
offset += c.length;
|
|
460
|
+
}
|
|
461
|
+
return out;
|
|
462
|
+
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Commit, ObjectId, TreeEntry } from "@statewalker/vcs-core";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_BIG_FILE_THRESHOLD,
|
|
4
|
+
FileMode,
|
|
5
|
+
isSymbolicRef,
|
|
6
|
+
probeBlob,
|
|
7
|
+
} from "@statewalker/vcs-core";
|
|
3
8
|
import {
|
|
4
9
|
merge3Way,
|
|
5
10
|
MergeContentStrategy as UtilsMergeContentStrategy,
|
|
@@ -68,6 +73,7 @@ export class MergeCommand extends GitCommand<MergeResult> {
|
|
|
68
73
|
private squash = false;
|
|
69
74
|
private commit = true;
|
|
70
75
|
private message?: string;
|
|
76
|
+
private bigFileThreshold = DEFAULT_BIG_FILE_THRESHOLD;
|
|
71
77
|
|
|
72
78
|
/**
|
|
73
79
|
* Add a commit/branch to merge.
|
|
@@ -129,6 +135,22 @@ export class MergeCommand extends GitCommand<MergeResult> {
|
|
|
129
135
|
return this;
|
|
130
136
|
}
|
|
131
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Set the size above which files are binary to the content merge (git's
|
|
140
|
+
* `core.bigFileThreshold`, default 50 MiB).
|
|
141
|
+
*
|
|
142
|
+
* A binary file (over the threshold, or a NUL byte in its first 8000 bytes) is
|
|
143
|
+
* never content-merged and never loaded: as git does, OURS and THEIRS take that
|
|
144
|
+
* side's file whole, and UNION reports a conflict.
|
|
145
|
+
*
|
|
146
|
+
* @param threshold Size in bytes
|
|
147
|
+
*/
|
|
148
|
+
setBigFileThreshold(threshold: number): this {
|
|
149
|
+
this.checkCallable();
|
|
150
|
+
this.bigFileThreshold = threshold;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
|
|
132
154
|
/**
|
|
133
155
|
* Set squash mode.
|
|
134
156
|
*
|
|
@@ -518,10 +540,22 @@ export class MergeCommand extends GitCommand<MergeResult> {
|
|
|
518
540
|
}
|
|
519
541
|
|
|
520
542
|
try {
|
|
521
|
-
//
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
543
|
+
// Binary or big files are never content-merged (git's ll_binary_merge)
|
|
544
|
+
const contents = await this.loadTexts([base?.id, ours.id, theirs.id]);
|
|
545
|
+
if (!contents) {
|
|
546
|
+
switch (this.contentStrategy) {
|
|
547
|
+
case ContentMergeStrategy.OURS:
|
|
548
|
+
return ours;
|
|
549
|
+
case ContentMergeStrategy.THEIRS:
|
|
550
|
+
return { ...theirs, name: ours.name };
|
|
551
|
+
default:
|
|
552
|
+
return undefined;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Load content from all three versions (text under the threshold)
|
|
557
|
+
// (read once, by the probe)
|
|
558
|
+
const [baseContent, oursContent, theirsContent] = contents;
|
|
525
559
|
|
|
526
560
|
// Convert ContentMergeStrategy to utils MergeContentStrategy
|
|
527
561
|
const strategy = this.convertContentStrategy(this.contentStrategy);
|
|
@@ -531,7 +565,10 @@ export class MergeCommand extends GitCommand<MergeResult> {
|
|
|
531
565
|
|
|
532
566
|
// If using OURS/THEIRS/UNION, conflicts are auto-resolved
|
|
533
567
|
// Store the merged content
|
|
534
|
-
const mergedBlobId = await this.blobs.store(
|
|
568
|
+
const mergedBlobId = await this.blobs.store(
|
|
569
|
+
[mergeResult.content],
|
|
570
|
+
mergeResult.content.length,
|
|
571
|
+
);
|
|
535
572
|
|
|
536
573
|
return {
|
|
537
574
|
name: ours.name,
|
|
@@ -545,30 +582,26 @@ export class MergeCommand extends GitCommand<MergeResult> {
|
|
|
545
582
|
}
|
|
546
583
|
|
|
547
584
|
/**
|
|
548
|
-
*
|
|
585
|
+
* The blobs' contents, each read once; nothing when one is binary or over the
|
|
586
|
+
* threshold (then the rest are not read). A missing id is empty content.
|
|
549
587
|
*/
|
|
550
|
-
private async
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
588
|
+
private async loadTexts(
|
|
589
|
+
ids: [ObjectId | undefined, ObjectId, ObjectId],
|
|
590
|
+
): Promise<[Uint8Array, Uint8Array, Uint8Array] | undefined> {
|
|
591
|
+
const out: Uint8Array[] = [];
|
|
592
|
+
for (const id of ids) {
|
|
593
|
+
if (!id) {
|
|
594
|
+
out.push(new Uint8Array(0));
|
|
595
|
+
continue;
|
|
556
596
|
}
|
|
597
|
+
const probe = await probeBlob(this.blobs, id, {
|
|
598
|
+
bigFileThreshold: this.bigFileThreshold,
|
|
599
|
+
loadText: true,
|
|
600
|
+
});
|
|
601
|
+
if (probe.binary || !probe.content) return undefined;
|
|
602
|
+
out.push(probe.content);
|
|
557
603
|
}
|
|
558
|
-
|
|
559
|
-
return new Uint8Array(0);
|
|
560
|
-
}
|
|
561
|
-
if (chunks.length === 1) {
|
|
562
|
-
return chunks[0];
|
|
563
|
-
}
|
|
564
|
-
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
565
|
-
const result = new Uint8Array(totalLength);
|
|
566
|
-
let offset = 0;
|
|
567
|
-
for (const chunk of chunks) {
|
|
568
|
-
result.set(chunk, offset);
|
|
569
|
-
offset += chunk.length;
|
|
570
|
-
}
|
|
571
|
-
return result;
|
|
604
|
+
return out as [Uint8Array, Uint8Array, Uint8Array];
|
|
572
605
|
}
|
|
573
606
|
|
|
574
607
|
/**
|
|
@@ -69,9 +69,9 @@ export class PackRefsCommand extends GitCommand<PackRefsResult> {
|
|
|
69
69
|
this.checkCallable();
|
|
70
70
|
this.setCallable(false);
|
|
71
71
|
|
|
72
|
-
// Check if
|
|
72
|
+
// Check if the ref store supports packRefs
|
|
73
73
|
if (!this.refsStore.packRefs) {
|
|
74
|
-
throw new Error("
|
|
74
|
+
throw new Error("This ref store does not support packRefs");
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
let refsPacked = 0;
|