@statewalker/vcs-commands 0.6.0 → 0.7.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/apply/apply-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-engine.d.ts.map +1 -1
- package/dist/commands/apply/apply-parse.d.ts.map +1 -1
- package/dist/commands/bisect/bisect-engine.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +17 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/comment-char-config.d.ts +35 -0
- package/dist/commands/comment-char-config.d.ts.map +1 -0
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts.map +1 -1
- package/dist/commands/default-branch.d.ts +70 -0
- package/dist/commands/default-branch.d.ts.map +1 -0
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/format-patch-command.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-command.d.ts +2 -0
- package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-loose.d.ts +3 -0
- package/dist/commands/fsck/fsck-loose.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-object-checks.d.ts +25 -14
- package/dist/commands/fsck/fsck-object-checks.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-object-table.d.ts +15 -7
- package/dist/commands/fsck/fsck-object-table.d.ts.map +1 -1
- package/dist/commands/fsck/fsck-pack.d.ts +11 -4
- package/dist/commands/fsck/fsck-pack.d.ts.map +1 -1
- package/dist/commands/fsck/verify-pack-command.d.ts.map +1 -1
- package/dist/commands/gc-command.d.ts +72 -48
- package/dist/commands/gc-command.d.ts.map +1 -1
- package/dist/commands/git-date.d.ts +1 -65
- package/dist/commands/git-date.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +8 -0
- package/dist/commands/git-hooks.d.ts.map +1 -1
- package/dist/commands/index-adder.d.ts +2 -0
- package/dist/commands/index-adder.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 +3 -3
- package/dist/commands/init-command.d.ts +50 -3
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/legacy-remotes.d.ts +55 -0
- package/dist/commands/legacy-remotes.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/ls-remote-command.d.ts.map +1 -1
- package/dist/commands/merge-command.d.ts +12 -0
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-support.d.ts +11 -3
- package/dist/commands/merge-support.d.ts.map +1 -1
- package/dist/commands/notes-merge-command.d.ts.map +1 -1
- package/dist/commands/notes-tree.d.ts +11 -1
- package/dist/commands/notes-tree.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +3 -0
- package/dist/commands/patch-id.d.ts.map +1 -1
- package/dist/commands/pretty-format.d.ts.map +1 -1
- package/dist/commands/pull-command.d.ts +18 -0
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/read-tree-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/rev-parse-command.d.ts +9 -0
- package/dist/commands/rev-parse-command.d.ts.map +1 -1
- package/dist/commands/revision-resolver.d.ts +6 -2
- package/dist/commands/revision-resolver.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +1 -1
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/sequencer-support.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +1 -1
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/submodule-summary-command.d.ts.map +1 -1
- package/dist/commands/untracked-cache-support.d.ts +2 -1
- package/dist/commands/untracked-cache-support.d.ts.map +1 -1
- package/dist/commands/worktree-list-command.d.ts.map +1 -1
- package/dist/{commands-DnmlfwGV.js → commands-DIJ91NnD.js} +1111 -506
- package/dist/{git-command-DxvwPrPB.js → git-command-BGiOJ8Zk.js} +630 -996
- package/dist/git-command.d.ts +16 -1
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +9 -2
- package/dist/git.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/remote-config/index.d.ts +1 -1
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +62 -3
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/rename/detect-renames.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +8 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/index.js +1 -1
- package/dist/results/init-result.d.ts +7 -0
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +5 -0
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +5 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/{results-BZGa2Z3I.js → results-WVlBhVb1.js} +11 -10
- package/package.json +12 -12
- package/src/commands/add-patch/add-interactive.ts +3 -3
- package/src/commands/am/am-command.ts +1 -1
- package/src/commands/apply/apply-command.ts +12 -2
- package/src/commands/apply/apply-engine.ts +5 -6
- package/src/commands/apply/apply-parse.ts +3 -2
- package/src/commands/attributes-source.ts +1 -1
- package/src/commands/bisect/bisect-engine.ts +2 -1
- package/src/commands/checkout-command.ts +1 -1
- package/src/commands/clone-command.ts +116 -4
- package/src/commands/comment-char-config.ts +160 -0
- package/src/commands/commit-command.ts +8 -7
- package/src/commands/core-config.ts +7 -2
- package/src/commands/default-branch.ts +196 -0
- package/src/commands/diff-command.ts +45 -27
- package/src/commands/fetch-command.ts +19 -5
- package/src/commands/format-patch-command.ts +7 -2
- package/src/commands/fsck/fsck-command.ts +183 -66
- package/src/commands/fsck/fsck-loose.ts +14 -4
- package/src/commands/fsck/fsck-object-checks.ts +87 -46
- package/src/commands/fsck/fsck-object-table.ts +52 -42
- package/src/commands/fsck/fsck-pack.ts +64 -34
- package/src/commands/fsck/verify-pack-command.ts +5 -2
- package/src/commands/gc-command.ts +208 -107
- package/src/commands/git-date.ts +9 -895
- package/src/commands/git-hooks.ts +11 -0
- package/src/commands/index-adder.ts +8 -3
- package/src/commands/index.ts +2 -0
- package/src/commands/init-command.ts +167 -11
- package/src/commands/legacy-remotes.ts +224 -0
- package/src/commands/log-command.ts +37 -22
- package/src/commands/ls-remote-command.ts +4 -0
- package/src/commands/merge-command.ts +31 -1
- package/src/commands/merge-support.ts +29 -8
- package/src/commands/notes-merge-command.ts +23 -14
- package/src/commands/notes-tree.ts +28 -13
- package/src/commands/octopus-merge.ts +3 -2
- package/src/commands/patch-id.ts +16 -8
- package/src/commands/pretty-format.ts +2 -1
- package/src/commands/pull-command.ts +128 -20
- package/src/commands/push-command.ts +23 -8
- package/src/commands/read-tree-command.ts +6 -2
- package/src/commands/rebase-command.ts +24 -13
- package/src/commands/remote-command.ts +35 -5
- package/src/commands/reset-command.ts +4 -11
- package/src/commands/rev-parse-command.ts +22 -0
- package/src/commands/revision-resolver.ts +32 -14
- package/src/commands/sequencer-pick.ts +7 -2
- package/src/commands/sequencer-support.ts +10 -3
- package/src/commands/stash-apply-command.ts +1 -1
- package/src/commands/stash-create-command.ts +2 -2
- package/src/commands/status-command.ts +2 -4
- package/src/commands/status-header.ts +3 -1
- package/src/commands/submodule-summary-command.ts +6 -7
- package/src/commands/untracked-cache-support.ts +16 -12
- package/src/commands/worktree-list-command.ts +3 -5
- package/src/core-commands/add.command.impl.ts +1 -1
- package/src/git-command.ts +32 -2
- package/src/git.ts +16 -3
- package/src/remote-config/index.ts +2 -0
- package/src/remote-config/remote-config-store.ts +137 -11
- package/src/rename/detect-renames.ts +5 -1
- package/src/results/clone-result.ts +9 -0
- package/src/results/diff-output.ts +9 -7
- package/src/results/init-result.ts +9 -0
- package/src/results/pull-result.ts +5 -0
- package/src/results/push-result.ts +5 -0
- package/src/results/status-result.ts +5 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_BIG_FILE_THRESHOLD, probeBlob } from "@statewalker/vcs-core";
|
|
2
2
|
import { compareGitPaths, decodeGitPath, encodeGitPath, gitCharWidthAt, gitStrWidth, parseGitBool } from "@statewalker/vcs-utils/encoding";
|
|
3
3
|
import { wildmatch } from "@statewalker/vcs-working-tree";
|
|
4
|
-
import { ByteSink, XDF_IGNORE_WHITESPACE, XDF_IGNORE_WHITESPACE_CHANGE, XDF_WHITESPACE_FLAGS, bytesToHex, compressBlockPako, createSha1, diffLineCounts, unifiedDiffHunks, userdiffFindFunction, whitespaceFlags, writeHunks, xdlIsSpace } from "@statewalker/vcs-utils";
|
|
4
|
+
import { ByteSink, XDF_IGNORE_WHITESPACE, XDF_IGNORE_WHITESPACE_CHANGE, XDF_WHITESPACE_FLAGS, bytesToHex, compressBlockPako, createSha1, diffLineCounts, nullObjectIdLike, unifiedDiffHunks, userdiffFindFunction, whitespaceFlags, writeHunks, xdlIsSpace } from "@statewalker/vcs-utils";
|
|
5
5
|
//#region src/results/quote-path.ts
|
|
6
6
|
/**
|
|
7
7
|
* Path quoting as git prints paths (`quote.c`'s `quote_c_style`): a path with a control
|
|
@@ -1405,7 +1405,6 @@ function gitBinaryPatch(one, two) {
|
|
|
1405
1405
|
*/
|
|
1406
1406
|
const S_IFMT = 61440;
|
|
1407
1407
|
const GITLINK_MODE = 57344;
|
|
1408
|
-
const NULL_ID = "0".repeat(40);
|
|
1409
1408
|
const FIRST_FEW_BYTES = 8e3;
|
|
1410
1409
|
const GIT_DIFF_BIG_FILE_THRESHOLD = 536870912;
|
|
1411
1410
|
const encoder = new TextEncoder();
|
|
@@ -1439,11 +1438,13 @@ const boolValue = (v) => parseGitBool(v);
|
|
|
1439
1438
|
var LoadedSide = class {
|
|
1440
1439
|
spec;
|
|
1441
1440
|
driver;
|
|
1441
|
+
otherId;
|
|
1442
1442
|
content;
|
|
1443
1443
|
probed;
|
|
1444
|
-
constructor(spec, driver) {
|
|
1444
|
+
constructor(spec, driver, otherId) {
|
|
1445
1445
|
this.spec = spec;
|
|
1446
1446
|
this.driver = driver;
|
|
1447
|
+
this.otherId = otherId;
|
|
1447
1448
|
}
|
|
1448
1449
|
get valid() {
|
|
1449
1450
|
return this.spec !== void 0;
|
|
@@ -1452,7 +1453,7 @@ var LoadedSide = class {
|
|
|
1452
1453
|
return this.spec?.mode ?? 0;
|
|
1453
1454
|
}
|
|
1454
1455
|
get id() {
|
|
1455
|
-
return this.spec?.id ??
|
|
1456
|
+
return this.spec?.id ?? nullObjectIdLike(this.otherId);
|
|
1456
1457
|
}
|
|
1457
1458
|
read() {
|
|
1458
1459
|
this.content ??= this.spec ? this.spec.read() : Promise.resolve(/* @__PURE__ */ new Uint8Array(0));
|
|
@@ -1539,7 +1540,7 @@ function metainfo(pair, one, two, name, other, options, fullIndex = false) {
|
|
|
1539
1540
|
mustShow = true;
|
|
1540
1541
|
}
|
|
1541
1542
|
if (one.id !== two.id) {
|
|
1542
|
-
const abbrev = (id) => id.slice(0, options.fullIndex || fullIndex ?
|
|
1543
|
+
const abbrev = (id) => id.slice(0, options.fullIndex || fullIndex ? id.length : options.abbrevLengths?.get(id) ?? options.abbrev ?? 7);
|
|
1543
1544
|
text += `index ${abbrev(one.id)}..${abbrev(two.id)}`;
|
|
1544
1545
|
if (one.mode === two.mode) text += ` ${octal6(one.mode)}`;
|
|
1545
1546
|
text += "\n";
|
|
@@ -1563,8 +1564,8 @@ async function builtinDiff(sink, pair, options, absentPath, report) {
|
|
|
1563
1564
|
const other = pathTwo !== name ? pathTwo : void 0;
|
|
1564
1565
|
const oneDriver = await driverOf(options, pathOne);
|
|
1565
1566
|
const twoDriver = pathTwo === pathOne ? oneDriver : await driverOf(options, pathTwo);
|
|
1566
|
-
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver));
|
|
1567
|
-
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver));
|
|
1567
|
+
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver), pair.new?.id);
|
|
1568
|
+
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver), pair.old?.id);
|
|
1568
1569
|
const textconvOne = one.driver?.textconv;
|
|
1569
1570
|
const textconvTwo = two.driver?.textconv;
|
|
1570
1571
|
const isBinary = async () => !options.text && (!textconvOne && await one.isBinary(threshold) || !textconvTwo && await two.isBinary(threshold));
|
|
@@ -1670,8 +1671,8 @@ async function computeDiffstat(pairs, options = {}) {
|
|
|
1670
1671
|
files.push(file);
|
|
1671
1672
|
const oneDriver = await driverOf(options, nameA);
|
|
1672
1673
|
const twoDriver = nameB === nameA ? oneDriver : await driverOf(options, nameB);
|
|
1673
|
-
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver));
|
|
1674
|
-
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver));
|
|
1674
|
+
const one = new LoadedSide(pair.old, contentDriver(pair.old, oneDriver), pair.new?.id);
|
|
1675
|
+
const two = new LoadedSide(pair.new, contentDriver(pair.new, twoDriver), pair.old?.id);
|
|
1675
1676
|
const mayDiffer = !(one.valid && two.valid && one.spec?.idValid !== false && two.spec?.idValid !== false && one.id === two.id);
|
|
1676
1677
|
if (await one.isBinary(threshold) || await two.isBinary(threshold)) {
|
|
1677
1678
|
file.isBinary = true;
|
|
@@ -2331,7 +2332,6 @@ var StatusImpl = class {
|
|
|
2331
2332
|
function comparePaths(a, b) {
|
|
2332
2333
|
return compareGitPaths(a, b);
|
|
2333
2334
|
}
|
|
2334
|
-
const ZERO_ID = "0".repeat(40);
|
|
2335
2335
|
/**
|
|
2336
2336
|
* The submodule field of a porcelain v2 line: `N...` for a path that is no submodule, else
|
|
2337
2337
|
* `S` and whether its commit changed (`C`), it has tracked changes (`M`) and untracked files
|
|
@@ -2385,6 +2385,7 @@ function formatStatusPorcelain(status, version = 1, options = {}) {
|
|
|
2385
2385
|
}
|
|
2386
2386
|
const xy = `${e.index === " " ? "." : e.index}${e.worktree === " " ? "." : e.worktree}`;
|
|
2387
2387
|
const sub = submoduleToken(e);
|
|
2388
|
+
const ZERO_ID = nullObjectIdLike(e.head?.id ?? e.staged?.id ?? e.stages?.find((x) => x !== void 0)?.id);
|
|
2388
2389
|
if (from !== void 0) {
|
|
2389
2390
|
lines.push([
|
|
2390
2391
|
"2",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statewalker/vcs-commands",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Git-like VCS commands (commit, checkout, merge, diff, log)",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/statewalker/webrun-vcs/issues"
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"src"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@statewalker/vcs-store-
|
|
50
|
-
"@statewalker/vcs-
|
|
51
|
-
"@statewalker/vcs-
|
|
52
|
-
"@statewalker/vcs-
|
|
53
|
-
"@statewalker/vcs-
|
|
54
|
-
"@statewalker/vcs-
|
|
49
|
+
"@statewalker/vcs-store-files": "^0.7.0",
|
|
50
|
+
"@statewalker/vcs-store-mem": "^0.7.0",
|
|
51
|
+
"@statewalker/vcs-transport": "^0.7.0",
|
|
52
|
+
"@statewalker/vcs-utils": "^0.7.0",
|
|
53
|
+
"@statewalker/vcs-working-tree": "^0.7.0",
|
|
54
|
+
"@statewalker/vcs-core": "^0.7.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@statewalker/webrun-rpc": "^0.15.0",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"typescript": "^7.0.2",
|
|
62
62
|
"vitest": "^5.1.0",
|
|
63
63
|
"ws": "^8.22.0",
|
|
64
|
-
"@statewalker/vcs-store-kv": "^0.
|
|
65
|
-
"@statewalker/vcs-
|
|
66
|
-
"@statewalker/vcs-
|
|
67
|
-
"@statewalker/vcs-transport-lfs": "^0.
|
|
68
|
-
"@statewalker/vcs-utils-node": "^0.
|
|
64
|
+
"@statewalker/vcs-store-kv": "^0.7.0",
|
|
65
|
+
"@statewalker/vcs-transport-adapters": "^0.7.0",
|
|
66
|
+
"@statewalker/vcs-store-sql": "^0.7.0",
|
|
67
|
+
"@statewalker/vcs-transport-lfs": "^0.6.0",
|
|
68
|
+
"@statewalker/vcs-utils-node": "^0.7.0"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "rm -rf dist && rolldown -c && tsc --emitDeclarationOnly --declaration",
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* what git prints gathered as its standard output and standard error.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import type { ObjectId } from "@statewalker/vcs-core";
|
|
10
10
|
import type {
|
|
11
11
|
ResolveUndoRecord,
|
|
12
12
|
StagingEntry,
|
|
@@ -512,7 +512,7 @@ class AddInteractiveSession extends GitCommand<AddInteractiveResult> {
|
|
|
512
512
|
const diff = new DiffCommand(this.workingCopy).setRenames(false).setCombineMerges(false);
|
|
513
513
|
if (fromIndex) {
|
|
514
514
|
diff
|
|
515
|
-
.setOldTree(head ??
|
|
515
|
+
.setOldTree(head ?? this.objectFormat.emptyTreeId)
|
|
516
516
|
.setCached(true)
|
|
517
517
|
.setIntentToAddVisible(true);
|
|
518
518
|
} else diff.setIgnoreSubmodules("dirty");
|
|
@@ -892,7 +892,7 @@ class AddInteractiveSession extends GitCommand<AddInteractiveResult> {
|
|
|
892
892
|
const { context, interHunkContext } = this.options;
|
|
893
893
|
const diff = new DiffCommand(this.workingCopy)
|
|
894
894
|
.setCached(true)
|
|
895
|
-
.setOldTree(head ??
|
|
895
|
+
.setOldTree(head ?? this.objectFormat.emptyTreeId)
|
|
896
896
|
.setPathspec(this.chosen());
|
|
897
897
|
if (this.modern) {
|
|
898
898
|
diff.setOptions({
|
|
@@ -747,7 +747,7 @@ export class AmCommand extends GitCommand<AmResult> {
|
|
|
747
747
|
if (p.isNew > 0) continue;
|
|
748
748
|
let oid: string | undefined;
|
|
749
749
|
try {
|
|
750
|
-
oid = /^[0-9a-f]{4,
|
|
750
|
+
oid = /^[0-9a-f]{4,64}$/.test(p.oldOidPrefix)
|
|
751
751
|
? await resolver.resolve(p.oldOidPrefix)
|
|
752
752
|
: undefined;
|
|
753
753
|
if (oid && !(await this.blobs.has(oid))) oid = undefined;
|
|
@@ -559,6 +559,7 @@ export class ApplyCommand extends GitCommand<ApplyResult> {
|
|
|
559
559
|
rejectWorktree: Worktree | undefined,
|
|
560
560
|
): ApplyIO {
|
|
561
561
|
const blobs = this.blobs;
|
|
562
|
+
const format = this.objectFormat;
|
|
562
563
|
const toPath = latin1ToPath;
|
|
563
564
|
const readAll = async (content: AsyncIterable<Uint8Array> | Iterable<Uint8Array>) => {
|
|
564
565
|
const chunks: Uint8Array[] = [];
|
|
@@ -677,10 +678,19 @@ export class ApplyCommand extends GitCommand<ApplyResult> {
|
|
|
677
678
|
},
|
|
678
679
|
hasObject: (oid) => blobs.has(oid),
|
|
679
680
|
writeBlob: async (content) => blobs.store([latin1ToBytes(content)]),
|
|
681
|
+
// the repository's hash (git's the_hash_algo)
|
|
680
682
|
hashBlob: async (content) =>
|
|
681
|
-
|
|
683
|
+
format.name === "sha1"
|
|
684
|
+
? bytesToHex(sha1Of(latin1ToBytes(`blob ${content.length}\0`), latin1ToBytes(content)))
|
|
685
|
+
: bytesToHex(
|
|
686
|
+
format
|
|
687
|
+
.createHasher()
|
|
688
|
+
.update(latin1ToBytes(`blob ${content.length}\0`))
|
|
689
|
+
.update(latin1ToBytes(content))
|
|
690
|
+
.digest(),
|
|
691
|
+
),
|
|
682
692
|
resolveBlob: async (prefix) => {
|
|
683
|
-
if (!/^[0-9a-f]{4,
|
|
693
|
+
if (!/^[0-9a-f]{4,64}$/.test(prefix) || prefix.length > format.hexLength) return undefined;
|
|
684
694
|
try {
|
|
685
695
|
const id = await resolver().resolve(prefix);
|
|
686
696
|
return id && (await blobs.has(id)) ? id : undefined;
|
|
@@ -759,7 +759,8 @@ export class ApplyEngine extends ApplyParser {
|
|
|
759
759
|
|
|
760
760
|
private async applyBinary(img: Target, patch: FilePatch): Promise<number> {
|
|
761
761
|
const name = patch.oldName ?? patch.newName;
|
|
762
|
-
|
|
762
|
+
// a full id of either format (git's hexsz digits)
|
|
763
|
+
const hex = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
763
764
|
if (!hex.test(patch.oldOidPrefix) || !hex.test(patch.newOidPrefix))
|
|
764
765
|
return this.error(`cannot apply binary patch to '${name}' without full index line`);
|
|
765
766
|
if (patch.oldName !== null) {
|
|
@@ -1328,13 +1329,11 @@ export class ApplyEngine extends ApplyParser {
|
|
|
1328
1329
|
private async addIndexFile(name: string, mode: number, buf: string): Promise<number> {
|
|
1329
1330
|
if (this.itaOnly) {
|
|
1330
1331
|
// set_object_name_for_intent_to_add_entry: the empty blob it names is written
|
|
1331
|
-
await this.io.writeBlob("");
|
|
1332
|
-
return this.addIndexEntries(name, [
|
|
1333
|
-
{ mode, oid: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", intentToAdd: true },
|
|
1334
|
-
]);
|
|
1332
|
+
const emptyBlob = await this.io.writeBlob("");
|
|
1333
|
+
return this.addIndexEntries(name, [{ mode, oid: emptyBlob, intentToAdd: true }]);
|
|
1335
1334
|
}
|
|
1336
1335
|
if (isGitlink(mode)) {
|
|
1337
|
-
const m = /^Subproject commit ([0-9a-f]{40})/.exec(buf);
|
|
1336
|
+
const m = /^Subproject commit ([0-9a-f]{64}|[0-9a-f]{40})/.exec(buf);
|
|
1338
1337
|
if (!m) return this.error(`corrupt patch for submodule ${name}`);
|
|
1339
1338
|
return this.addIndexEntries(name, [{ mode, oid: m[1] as string }]);
|
|
1340
1339
|
}
|
|
@@ -618,12 +618,13 @@ export class ApplyParser {
|
|
|
618
618
|
const dot = buf.indexOf(".", line);
|
|
619
619
|
const eol0 = buf.indexOf("\n", line);
|
|
620
620
|
const eol = eol0 < 0 ? buf.length : eol0;
|
|
621
|
-
|
|
621
|
+
// at most a full id's digits (64 in SHA-256, git's hexsz)
|
|
622
|
+
if (dot < 0 || buf[dot + 1] !== "." || 64 < dot - line) return 0;
|
|
622
623
|
const oldPrefix = buf.slice(line, dot);
|
|
623
624
|
const l2 = dot + 2;
|
|
624
625
|
let ptr = buf.indexOf(" ", l2);
|
|
625
626
|
if (ptr < 0 || eol < ptr) ptr = eol;
|
|
626
|
-
if (
|
|
627
|
+
if (64 < ptr - l2) return 0;
|
|
627
628
|
patch.oldOidPrefix = oldPrefix;
|
|
628
629
|
patch.newOidPrefix = buf.slice(l2, ptr);
|
|
629
630
|
if (buf[ptr] === " ") return mode(ptr + 1 - at, (m) => (patch.oldMode = m));
|
|
@@ -20,7 +20,7 @@ import { hostEnvironmentOf } from "./git-ident.js";
|
|
|
20
20
|
import { configBool, configValue } from "./merge-config.js";
|
|
21
21
|
import type { RevisionResolver } from "./revision-resolver.js";
|
|
22
22
|
|
|
23
|
-
const FULL_ID = /^[0-9a-fA-F]{40}$/;
|
|
23
|
+
const FULL_ID = /^(?:[0-9a-fA-F]{40}|[0-9a-fA-F]{64})$/;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Resolves attribute sources through `resolver` (a fresh one per lookup). A full object id
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { ObjectId } from "@statewalker/vcs-core";
|
|
10
|
+
import { nullObjectIdLike } from "@statewalker/vcs-utils";
|
|
10
11
|
|
|
11
12
|
import type { OperationState } from "../merge-support.js";
|
|
12
13
|
import {
|
|
@@ -801,7 +802,7 @@ export class BisectEngine {
|
|
|
801
802
|
}
|
|
802
803
|
if (!id) this.error(`Bad rev input: ${head}`);
|
|
803
804
|
// git goes on with whatever it read (the null id)
|
|
804
|
-
revs.push(id ??
|
|
805
|
+
revs.push(id ?? nullObjectIdLike(revs[0]));
|
|
805
806
|
}
|
|
806
807
|
for (const arg of revArgs) {
|
|
807
808
|
const id = await this.ctx.resolve(arg);
|
|
@@ -977,7 +977,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
977
977
|
* checkout do before the write).
|
|
978
978
|
*/
|
|
979
979
|
private async writeSwitchedIndex(): Promise<void> {
|
|
980
|
-
await updateIndexCacheTree(this.staging, this.trees);
|
|
980
|
+
await updateIndexCacheTree(this.staging, this.trees, this.objectFormat);
|
|
981
981
|
markIndexUpdate(this.staging, { workdir: true });
|
|
982
982
|
await this.staging.write();
|
|
983
983
|
}
|
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
type FetchOptions as TransportFetchOptions,
|
|
16
16
|
} from "@statewalker/vcs-transport";
|
|
17
17
|
import { parseGitInt } from "@statewalker/vcs-utils/encoding";
|
|
18
|
-
import type {
|
|
18
|
+
import type { ObjectFormat } from "@statewalker/vcs-utils/hash";
|
|
19
|
+
import type { OpenedRepository, WorkingCopy, Worktree } from "@statewalker/vcs-working-tree";
|
|
19
20
|
|
|
20
21
|
import {
|
|
21
22
|
CloneCheckoutError,
|
|
@@ -30,6 +31,7 @@ import type { CloneResult } from "../results/clone-result.js";
|
|
|
30
31
|
import type { FetchResult, TrackingRefUpdate } from "../results/fetch-result.js";
|
|
31
32
|
import { TransportCommand } from "../transport-command.js";
|
|
32
33
|
import { coreBool, worktreeModeTrust } from "./core-config.js";
|
|
34
|
+
import { defaultInitialBranch } from "./default-branch.js";
|
|
33
35
|
import { TagOption, toTagMode, toTrackingRefUpdate } from "./fetch-command.js";
|
|
34
36
|
import { fetchFsckOf } from "./fsck/index.js";
|
|
35
37
|
import { runPostCheckoutHook } from "./git-hooks.js";
|
|
@@ -42,7 +44,48 @@ import { withRemoteUploadPack } from "./remote-transport.js";
|
|
|
42
44
|
import { SparseCheckoutCommand } from "./sparse-checkout-command.js";
|
|
43
45
|
import { SparseUnpack } from "./sparse-checkout-support.js";
|
|
44
46
|
import { checkoutFreshTree } from "./tree-restore.js";
|
|
45
|
-
import { repositoryPlaceOf } from "./worktree-support.js";
|
|
47
|
+
import { repositoryPlaceOf, worktreeAdminWorkingCopy } from "./worktree-support.js";
|
|
48
|
+
|
|
49
|
+
/** The settings a clone reopened with another object format runs with again. */
|
|
50
|
+
const CLONE_SETTINGS = [
|
|
51
|
+
"uri",
|
|
52
|
+
"branch",
|
|
53
|
+
"depth",
|
|
54
|
+
"filterSpec",
|
|
55
|
+
"uploadPack",
|
|
56
|
+
"bare",
|
|
57
|
+
"noCheckout",
|
|
58
|
+
"sparse",
|
|
59
|
+
"remoteName",
|
|
60
|
+
"cloneAllBranches",
|
|
61
|
+
"mirror",
|
|
62
|
+
"singleBranch",
|
|
63
|
+
"branchesToClone",
|
|
64
|
+
"tagOption",
|
|
65
|
+
"shallowSince",
|
|
66
|
+
"shallowExcludes",
|
|
67
|
+
"directory",
|
|
68
|
+
"shared",
|
|
69
|
+
"local",
|
|
70
|
+
"dissociate",
|
|
71
|
+
"references",
|
|
72
|
+
"credentials",
|
|
73
|
+
"timeout",
|
|
74
|
+
"headers",
|
|
75
|
+
"gzipRequests",
|
|
76
|
+
"progressCallback",
|
|
77
|
+
"progressMessageCallback",
|
|
78
|
+
"transportRegistry",
|
|
79
|
+
"useReplaceRefsOverride",
|
|
80
|
+
"reflogActionOverride",
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
/** The remote names objects with another hash than the destination (see `cloneReopenedAs`). */
|
|
84
|
+
class RemoteObjectFormatSwitch extends Error {
|
|
85
|
+
constructor(readonly format: ObjectFormat) {
|
|
86
|
+
super(`the remote repository's object format is ${format.name}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
46
89
|
|
|
47
90
|
/** Names the clone's checkout in failure messages. */
|
|
48
91
|
const CLONE = "clone";
|
|
@@ -544,7 +587,65 @@ export class CloneCommand extends TransportCommand<CloneResult> {
|
|
|
544
587
|
async call(): Promise<CloneResult> {
|
|
545
588
|
this.checkCallable();
|
|
546
589
|
this.setCallable(false);
|
|
590
|
+
try {
|
|
591
|
+
return await this.cloneOnce();
|
|
592
|
+
} catch (error) {
|
|
593
|
+
if (!(error instanceof RemoteObjectFormatSwitch)) throw error;
|
|
594
|
+
return this.cloneReopenedAs(error.format);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Called with the working copy a clone reopened with the remote's object format (see
|
|
600
|
+
* {@link CloneResult.workingCopy}): `Git.clone()` takes it as its own.
|
|
601
|
+
*/
|
|
602
|
+
onWorkingCopyReopened(listener: (workingCopy: WorkingCopy) => void): this {
|
|
603
|
+
this.reopenedListener = listener;
|
|
604
|
+
return this;
|
|
605
|
+
}
|
|
547
606
|
|
|
607
|
+
private reopenedListener?: (workingCopy: WorkingCopy) => void;
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* git's clone initializes the new repository with the hash the remote names
|
|
611
|
+
* (`initialize_repository_version` with `transport_get_hash_algo`): the destination, still
|
|
612
|
+
* empty, is switched to `format` and reopened (`LinkedWorktrees.reopenWithObjectFormat`),
|
|
613
|
+
* and the clone runs again into it. What the first attempt wrote before it learned the
|
|
614
|
+
* format (the alternates of `--reference` / `--shared`) is removed once the destination
|
|
615
|
+
* passed the check.
|
|
616
|
+
*/
|
|
617
|
+
private async cloneReopenedAs(format: ObjectFormat): Promise<CloneResult> {
|
|
618
|
+
const worktrees = this._workingCopy.worktrees;
|
|
619
|
+
if (!worktrees?.reopenWithObjectFormat) {
|
|
620
|
+
throw new TransportError(
|
|
621
|
+
`fatal: cannot clone a ${format.name} repository into this ${this.objectFormat.name} repository`,
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
const place = repositoryPlaceOf(this.workingCopy);
|
|
625
|
+
const files = place?.getFiles?.();
|
|
626
|
+
const gitDir = place?.getGitDir?.();
|
|
627
|
+
// checked first (no refs, no objects of its own): a refused destination keeps its
|
|
628
|
+
// alternates
|
|
629
|
+
const admin = await worktrees.reopenWithObjectFormat(format);
|
|
630
|
+
if (files && gitDir !== undefined) {
|
|
631
|
+
const file = `${gitDir}/objects/info/alternates`;
|
|
632
|
+
if ((await files.stats(file))?.kind === "file") {
|
|
633
|
+
await files.remove(file);
|
|
634
|
+
await admin.history.objects?.alternates?.refresh();
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const workingCopy = worktreeAdminWorkingCopy(admin);
|
|
638
|
+
const next = new CloneCommand(workingCopy);
|
|
639
|
+
const self = this as unknown as Record<string, unknown>;
|
|
640
|
+
const other = next as unknown as Record<string, unknown>;
|
|
641
|
+
for (const key of CLONE_SETTINGS) if (key in self) other[key] = self[key];
|
|
642
|
+
next.shareHooksOf(this);
|
|
643
|
+
const result = await next.call();
|
|
644
|
+
this.reopenedListener?.(workingCopy);
|
|
645
|
+
return { ...result, workingCopy };
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
private async cloneOnce(): Promise<CloneResult> {
|
|
548
649
|
if (!this.uri) {
|
|
549
650
|
throw new InvalidRemoteError("", "URI must be specified for clone");
|
|
550
651
|
}
|
|
@@ -758,6 +859,11 @@ export class CloneCommand extends TransportCommand<CloneResult> {
|
|
|
758
859
|
? { filter: this.filterSpec, onWarning: (line: string) => messages.push(`${line}\n`) }
|
|
759
860
|
: {}),
|
|
760
861
|
...(fsck ? { fsckObjects: fsck } : {}),
|
|
862
|
+
// git's clone takes the remote's hash: a destination of another one is reopened with it
|
|
863
|
+
// before anything is fetched (cloneReopenedAs)
|
|
864
|
+
onRemoteObjectFormat: (format) => {
|
|
865
|
+
if (format.name !== this.objectFormat.name) throw new RemoteObjectFormatSwitch(format);
|
|
866
|
+
},
|
|
761
867
|
...(copyObjects
|
|
762
868
|
? {
|
|
763
869
|
beforeFetch: async (remoteRefs) => {
|
|
@@ -812,7 +918,9 @@ export class CloneCommand extends TransportCommand<CloneResult> {
|
|
|
812
918
|
let checkoutId: ObjectId | undefined;
|
|
813
919
|
// an empty remote without unborn HEAD: git's default branch (the one init named)
|
|
814
920
|
if (!detachedTag && !this.bare && defaultBranch === undefined && result.isEmpty) {
|
|
815
|
-
defaultBranch =
|
|
921
|
+
defaultBranch =
|
|
922
|
+
(await this.localHeadBranch()) ??
|
|
923
|
+
(await defaultInitialBranch(hostEnvironmentOf(this._workingCopy))).name;
|
|
816
924
|
}
|
|
817
925
|
|
|
818
926
|
// git's update_remote_refs (before update_head): refs/remotes/<name>/HEAD names the tracking ref of the
|
|
@@ -896,7 +1004,11 @@ export class CloneCommand extends TransportCommand<CloneResult> {
|
|
|
896
1004
|
|
|
897
1005
|
const cloneResult: CloneResult = {
|
|
898
1006
|
fetchResult,
|
|
899
|
-
|
|
1007
|
+
// as the empty-remote case above: the local HEAD's branch, else git's default
|
|
1008
|
+
defaultBranch:
|
|
1009
|
+
defaultBranch ??
|
|
1010
|
+
(await this.localHeadBranch()) ??
|
|
1011
|
+
(await defaultInitialBranch(hostEnvironmentOf(this._workingCopy))).name,
|
|
900
1012
|
remoteName: this.remoteName,
|
|
901
1013
|
bare: this.bare,
|
|
902
1014
|
headCommit,
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `core.commentChar` / `core.commentString` = `auto`, deprecated in git 2.5x and removed in
|
|
3
|
+
* git 3.0 (config.c's `comment_char_callback` and `check_auto_comment_char_config`). git
|
|
4
|
+
* tracks every value of the two keys in configuration order; when the last one is exactly
|
|
5
|
+
* `auto`, a git built with `WITH_BREAKING_CHANGES` dies in every command that reads the
|
|
6
|
+
* repository's configuration, and git 2.5x warns once in commit, merge, rebase, revert and
|
|
7
|
+
* cherry-pick. Both add advice naming the files to change, as `git config` scope options.
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* autoCommentCharLines(workingCopy, "removed");
|
|
11
|
+
* // ["fatal: Support for 'core.commentChar=auto' has been removed in Git 3.0", "hint:",
|
|
12
|
+
* // "hint: To use the default comment string (#) please run", ...]
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import type { GitHostEnvironment, WorkingCopy } from "@statewalker/vcs-working-tree";
|
|
16
|
+
import { InvalidConfigError } from "../errors/index.js";
|
|
17
|
+
import { RemoteConfigStore } from "../remote-config/index.js";
|
|
18
|
+
import { hostEnvironmentOf } from "./git-ident.js";
|
|
19
|
+
|
|
20
|
+
const KEYS = ["core.commentchar", "core.commentstring"] as const;
|
|
21
|
+
const NAMES = ["core.commentChar", "core.commentString"] as const;
|
|
22
|
+
|
|
23
|
+
interface Item {
|
|
24
|
+
keyId: 0 | 1;
|
|
25
|
+
scope: string | undefined;
|
|
26
|
+
file: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** `core.commentChar=auto` in a git 3.0 build: every command but `git config` dies (exit 128). */
|
|
30
|
+
export class AutoCommentCharRemovedError extends InvalidConfigError {
|
|
31
|
+
/** git's stderr: the fatal line and its hints */
|
|
32
|
+
readonly lines: string[];
|
|
33
|
+
constructor(lines: string[]) {
|
|
34
|
+
super("core.commentChar", lines.join("\n"));
|
|
35
|
+
this.name = "AutoCommentCharRemovedError";
|
|
36
|
+
this.lines = lines;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* git's lines about an `auto` comment character, or undefined when the last value of the two
|
|
42
|
+
* keys is not exactly `auto`: `removed` gives git 3.0's death (`fatal:`), `deprecated` git
|
|
43
|
+
* 2.5x's warning (`warning:`), each followed by the advice.
|
|
44
|
+
*/
|
|
45
|
+
export function autoCommentCharLines(
|
|
46
|
+
workingCopy: WorkingCopy,
|
|
47
|
+
kind: "removed" | "deprecated",
|
|
48
|
+
): string[] | undefined {
|
|
49
|
+
const config = RemoteConfigStore.from(workingCopy);
|
|
50
|
+
const entries = config.entriesWithOriginFor([...KEYS]);
|
|
51
|
+
if (!entries) {
|
|
52
|
+
// a config that cannot list its variables: the last value alone, no advice
|
|
53
|
+
const last = config.lastValueOf([...NAMES]);
|
|
54
|
+
if (last !== "auto") return undefined;
|
|
55
|
+
return [headline(kind, "core.commentChar")];
|
|
56
|
+
}
|
|
57
|
+
let lastKey: 0 | 1 = 0;
|
|
58
|
+
let autoSet = false;
|
|
59
|
+
let autoSetInFile = false;
|
|
60
|
+
const items: Item[] = [];
|
|
61
|
+
const seenTwice = new Set<string>();
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
const keyId = KEYS.indexOf(entry.key as (typeof KEYS)[number]) as 0 | 1;
|
|
64
|
+
lastKey = keyId;
|
|
65
|
+
autoSet = entry.text === "auto";
|
|
66
|
+
// values of the command line are not files: no advice names them
|
|
67
|
+
if (entry.scope === "command" || entry.file === undefined) continue;
|
|
68
|
+
const id = `${keyId}\0${entry.file}`;
|
|
69
|
+
if (items.some((item) => `${item.keyId}\0${item.file}` === id)) seenTwice.add(id);
|
|
70
|
+
else items.push({ keyId, scope: entry.scope, file: entry.file });
|
|
71
|
+
autoSetInFile = autoSet;
|
|
72
|
+
}
|
|
73
|
+
if (!autoSet) return undefined;
|
|
74
|
+
const lines = [headline(kind, NAMES[lastKey])];
|
|
75
|
+
if (autoSetInFile && items.length > 0) {
|
|
76
|
+
const environment = hostEnvironmentOf(workingCopy);
|
|
77
|
+
const unset = items.map(
|
|
78
|
+
(item) =>
|
|
79
|
+
` git config unset ${scopeArg(item, environment)}${
|
|
80
|
+
seenTwice.has(`${item.keyId}\0${item.file}`) ? "--all " : ""
|
|
81
|
+
}${NAMES[item.keyId]}`,
|
|
82
|
+
);
|
|
83
|
+
lines.push(
|
|
84
|
+
...hint(`\nTo use the default comment string (#) please run\n\n${unset.join("\n")}\n`),
|
|
85
|
+
);
|
|
86
|
+
const last = items[items.length - 1] as Item;
|
|
87
|
+
const set = ` git config set ${scopeArg(last, environment)}${NAMES[last.keyId]} <comment string>`;
|
|
88
|
+
lines.push(
|
|
89
|
+
...hint(
|
|
90
|
+
`\nTo set a custom comment string please run\n\n${set}\n\nwhere '<comment string>' is the string you wish to use.\n`,
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return lines;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The git 3.0 check every command runs as it reads the configuration (`check_deprecated_config`
|
|
99
|
+
* in `repo_read_config`): throws with git's lines when the comment character is `auto` and the
|
|
100
|
+
* host asked for git 3.0 (`GitHostEnvironment.breakingChanges`).
|
|
101
|
+
*/
|
|
102
|
+
export function checkAutoCommentChar(workingCopy: WorkingCopy): void {
|
|
103
|
+
if (!hostEnvironmentOf(workingCopy)?.breakingChanges) return;
|
|
104
|
+
const lines = autoCommentCharLines(workingCopy, "removed");
|
|
105
|
+
if (lines) throw new AutoCommentCharRemovedError(lines);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function headline(kind: "removed" | "deprecated", key: string): string {
|
|
109
|
+
return kind === "removed"
|
|
110
|
+
? `fatal: Support for '${key}=auto' has been removed in Git 3.0`
|
|
111
|
+
: `warning: Support for '${key}=auto' is deprecated and will be removed in Git 3.0`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** advice.c's `vadvise`: each line as `hint: <line>`, an empty one as `hint:`. */
|
|
115
|
+
function hint(text: string): string[] {
|
|
116
|
+
const out: string[] = [];
|
|
117
|
+
const parts = text.split("\n");
|
|
118
|
+
// a trailing newline ends the last line; it adds no empty one
|
|
119
|
+
if (parts[parts.length - 1] === "") parts.pop();
|
|
120
|
+
for (const part of parts) out.push(part === "" ? "hint:" : `hint: ${part}`);
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* config.c's `add_config_scope_arg`: the option naming the file a value came from. The
|
|
126
|
+
* system file is taken as writable (git recommends `--global` when it is not; the FilesApi
|
|
127
|
+
* cannot tell).
|
|
128
|
+
*/
|
|
129
|
+
function scopeArg(item: Item, environment: GitHostEnvironment | undefined): string {
|
|
130
|
+
const base = item.file.split("/").pop() ?? item.file;
|
|
131
|
+
if (item.scope === "system" && item.file === environment?.systemConfig) return "--system ";
|
|
132
|
+
if (item.scope === "global" && isGlobalFile(item.file, environment)) return "--global ";
|
|
133
|
+
if (item.scope === "local" && base === "config") return "";
|
|
134
|
+
if (item.scope === "worktree" && base === "config.worktree") return "--worktree ";
|
|
135
|
+
let path = item.file;
|
|
136
|
+
let prefix = "";
|
|
137
|
+
const home = environment?.home;
|
|
138
|
+
if (home && path.startsWith(home)) {
|
|
139
|
+
path = path.slice(home.length).replace(/^\//, "");
|
|
140
|
+
prefix = "~/";
|
|
141
|
+
}
|
|
142
|
+
return `--file ${prefix}${quotePretty(path)} `;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function isGlobalFile(file: string, environment: GitHostEnvironment | undefined): boolean {
|
|
146
|
+
if (!environment) return false;
|
|
147
|
+
if (environment.globalConfig !== undefined) return file === environment.globalConfig;
|
|
148
|
+
const home = environment.home?.replace(/\/+$/, "");
|
|
149
|
+
const xdg = environment.xdgConfigHome ?? (home ? `${home}/.config` : undefined);
|
|
150
|
+
return (
|
|
151
|
+
(home !== undefined && file === `${home}/.gitconfig`) ||
|
|
152
|
+
(xdg !== undefined && file === `${xdg}/git/config`)
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** quote.c's `sq_quote_buf_pretty`: as is when every byte is safe, else single-quoted. */
|
|
157
|
+
function quotePretty(path: string): string {
|
|
158
|
+
if (path !== "" && /^[A-Za-z0-9+,\-./:=@_^]+$/.test(path)) return path;
|
|
159
|
+
return `'${path.replace(/'/g, "'\\''").replace(/!/g, "'\\!'")}'`;
|
|
160
|
+
}
|