@statewalker/vcs-commands 0.8.0 → 0.9.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/add-command.d.ts +32 -0
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-patch.d.ts +7 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
- package/dist/commands/am/am-command.d.ts +47 -0
- package/dist/commands/am/am-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-command.d.ts +2 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-parse.d.ts +7 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -1
- package/dist/commands/apply/index.d.ts +1 -1
- package/dist/commands/apply/index.d.ts.map +1 -1
- package/dist/commands/blame-command.d.ts +303 -8
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/blame-ignore.d.ts +48 -0
- package/dist/commands/blame-ignore.d.ts.map +1 -0
- package/dist/commands/check-mailmap-command.d.ts +49 -0
- package/dist/commands/check-mailmap-command.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +7 -0
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +4 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -1
- package/dist/commands/cherry-command.d.ts +61 -0
- package/dist/commands/cherry-command.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +23 -1
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +32 -0
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clean-interactive.d.ts +56 -0
- package/dist/commands/clean-interactive.d.ts.map +1 -0
- package/dist/commands/clone-command.d.ts +116 -2
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +50 -2
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/describe-command.d.ts +71 -64
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +118 -6
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/fetch-command.d.ts +60 -0
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/fetch-multiple-command.d.ts +193 -0
- package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
- package/dist/commands/format-patch-command.d.ts +28 -2
- package/dist/commands/format-patch-command.d.ts.map +1 -1
- package/dist/commands/git-describe.d.ts +77 -4
- package/dist/commands/git-describe.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +15 -1
- package/dist/commands/git-hooks.d.ts.map +1 -1
- package/dist/commands/index.d.ts +12 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +5 -3
- package/dist/commands/init-command.d.ts +89 -0
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/line-log.d.ts +161 -0
- package/dist/commands/line-log.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +235 -6
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +4 -2
- package/dist/commands/log-graph.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +66 -1
- package/dist/commands/log-output.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +24 -1
- package/dist/commands/mailmap.d.ts.map +1 -1
- package/dist/commands/merge-command.d.ts +51 -1
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-drivers.d.ts +2 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -1
- package/dist/commands/merge-strategy-options.d.ts +69 -0
- package/dist/commands/merge-strategy-options.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +10 -0
- package/dist/commands/merge-support.d.ts.map +1 -1
- package/dist/commands/message-cleanup.d.ts +2 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -1
- package/dist/commands/name-rev-command.d.ts +65 -0
- package/dist/commands/name-rev-command.d.ts.map +1 -0
- package/dist/commands/name-rev.d.ts +110 -22
- package/dist/commands/name-rev.d.ts.map +1 -1
- package/dist/commands/octopus-merge.d.ts +26 -1
- package/dist/commands/octopus-merge.d.ts.map +1 -1
- package/dist/commands/ort-merge.d.ts +16 -0
- package/dist/commands/ort-merge.d.ts.map +1 -1
- package/dist/commands/ort-recursive.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +58 -0
- package/dist/commands/patch-id.d.ts.map +1 -1
- package/dist/commands/pull-command.d.ts +182 -38
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +65 -0
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/range-diff/index.d.ts +4 -0
- package/dist/commands/range-diff/index.d.ts.map +1 -0
- package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
- package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
- package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff.d.ts +106 -0
- package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
- package/dist/commands/read-tree-command.d.ts +14 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +21 -2
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/remerge-diff.d.ts +59 -0
- package/dist/commands/remerge-diff.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +41 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-show-command.d.ts +204 -0
- package/dist/commands/remote-show-command.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +19 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +7 -0
- package/dist/commands/restore-command.d.ts.map +1 -1
- package/dist/commands/rev-list-command.d.ts +75 -3
- package/dist/commands/rev-list-command.d.ts.map +1 -1
- package/dist/commands/revert-command.d.ts +22 -1
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +2 -0
- package/dist/commands/revision-range.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +102 -1
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/sequencer-support.d.ts +10 -1
- package/dist/commands/sequencer-support.d.ts.map +1 -1
- package/dist/commands/shortlog-command.d.ts +109 -0
- package/dist/commands/shortlog-command.d.ts.map +1 -0
- package/dist/commands/shortlog.d.ts +151 -0
- package/dist/commands/shortlog.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +31 -2
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/submodule-commands.d.ts +90 -2
- package/dist/commands/submodule-commands.d.ts.map +1 -1
- package/dist/commands/submodule-fetch.d.ts +149 -0
- package/dist/commands/submodule-fetch.d.ts.map +1 -0
- package/dist/commands/submodule-model.d.ts +8 -0
- package/dist/commands/submodule-model.d.ts.map +1 -1
- package/dist/commands/submodule-unpack.d.ts +120 -0
- package/dist/commands/submodule-unpack.d.ts.map +1 -0
- package/dist/commands/submodule-update-command.d.ts +8 -0
- package/dist/commands/submodule-update-command.d.ts.map +1 -1
- package/dist/commands/subtree-shift.d.ts +27 -0
- package/dist/commands/subtree-shift.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +3 -0
- package/dist/commands/switch-command.d.ts.map +1 -1
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/{commands-ISM52N0n.js → commands-CNvli5bl.js} +39426 -61169
- package/dist/errors/command-errors.d.ts +25 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/index.js +29 -1
- package/dist/fsck-CPeDh9fh.js +5138 -0
- package/dist/git-command.d.ts +31 -1
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +97 -1
- package/dist/git.d.ts.map +1 -1
- package/dist/guarded-transport-command.d.ts +82 -0
- package/dist/guarded-transport-command.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/remote-transport-CCmBadm-.js +1606 -0
- package/dist/rename/detect-renames.d.ts +20 -0
- package/dist/rename/detect-renames.d.ts.map +1 -1
- package/dist/rename/diffcore-break.d.ts +51 -0
- package/dist/rename/diffcore-break.d.ts.map +1 -0
- package/dist/rename/index.d.ts +1 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/blame-format.d.ts +62 -1
- package/dist/results/blame-format.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +9 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/diff-dirstat.d.ts +36 -0
- package/dist/results/diff-dirstat.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +10 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-output.d.ts +18 -0
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/fetch-result.d.ts +12 -1
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +2 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -2
- package/dist/results/init-result.d.ts +8 -1
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/line-range-hunks.d.ts +27 -0
- package/dist/results/line-range-hunks.d.ts.map +1 -0
- package/dist/results/merge-result.d.ts +8 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +11 -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 +1 -1
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BDuEgdLU.js +46847 -0
- package/dist/transport-command.d.ts +14 -0
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/commands/add-command.ts +115 -0
- package/src/commands/add-patch/add-patch.ts +8 -0
- package/src/commands/add-patch/patch-backend.ts +20 -2
- package/src/commands/am/am-command.ts +138 -4
- package/src/commands/apply/apply-command.ts +52 -9
- package/src/commands/apply/apply-parse.ts +10 -0
- package/src/commands/apply/index.ts +8 -1
- package/src/commands/blame-command.ts +1450 -51
- package/src/commands/blame-ignore.ts +307 -0
- package/src/commands/check-mailmap-command.ts +129 -0
- package/src/commands/checkout-command.ts +97 -12
- package/src/commands/checkout-paths.ts +28 -0
- package/src/commands/cherry-command.ts +187 -0
- package/src/commands/cherry-pick-command.ts +42 -1
- package/src/commands/clean-command.ts +92 -12
- package/src/commands/clean-interactive.ts +522 -0
- package/src/commands/clone-command.ts +596 -44
- package/src/commands/commit-command.ts +180 -47
- package/src/commands/describe-command.ts +341 -254
- package/src/commands/diff-command.ts +616 -56
- package/src/commands/fetch-command.ts +353 -6
- package/src/commands/fetch-multiple-command.ts +665 -0
- package/src/commands/format-patch-command.ts +189 -77
- package/src/commands/git-describe.ts +456 -217
- package/src/commands/git-hooks.ts +42 -3
- package/src/commands/index.ts +17 -0
- package/src/commands/init-command.ts +603 -49
- package/src/commands/line-log.ts +931 -0
- package/src/commands/log-command.ts +1414 -177
- package/src/commands/log-graph.ts +6 -3
- package/src/commands/log-output.ts +173 -10
- package/src/commands/mailmap.ts +41 -5
- package/src/commands/merge-command.ts +274 -16
- package/src/commands/merge-drivers.ts +3 -0
- package/src/commands/merge-strategy-options.ts +224 -0
- package/src/commands/merge-support.ts +101 -21
- package/src/commands/message-cleanup.ts +1 -1
- package/src/commands/name-rev-command.ts +184 -0
- package/src/commands/name-rev.ts +700 -109
- package/src/commands/octopus-merge.ts +35 -11
- package/src/commands/ort-merge.ts +41 -7
- package/src/commands/ort-recursive.ts +40 -2
- package/src/commands/patch-id.ts +109 -0
- package/src/commands/pull-command.ts +718 -224
- package/src/commands/push-command.ts +353 -3
- package/src/commands/range-diff/index.ts +3 -0
- package/src/commands/range-diff/linear-assignment.ts +203 -0
- package/src/commands/range-diff/range-diff-command.ts +433 -0
- package/src/commands/range-diff/range-diff.ts +617 -0
- package/src/commands/read-tree-command.ts +74 -3
- package/src/commands/rebase-command.ts +141 -65
- package/src/commands/remerge-diff.ts +241 -0
- package/src/commands/remote-command.ts +98 -10
- package/src/commands/remote-show-command.ts +836 -0
- package/src/commands/reset-command.ts +78 -3
- package/src/commands/restore-command.ts +15 -0
- package/src/commands/rev-list-command.ts +187 -11
- package/src/commands/revert-command.ts +41 -1
- package/src/commands/revision-range.ts +3 -1
- package/src/commands/sequencer-pick.ts +323 -29
- package/src/commands/sequencer-support.ts +164 -2
- package/src/commands/shortlog-command.ts +354 -0
- package/src/commands/shortlog.ts +361 -0
- package/src/commands/show-command.ts +2 -1
- package/src/commands/status-command.ts +115 -25
- package/src/commands/status-format.ts +1 -1
- package/src/commands/submodule-commands.ts +321 -3
- package/src/commands/submodule-fetch.ts +789 -0
- package/src/commands/submodule-model.ts +9 -1
- package/src/commands/submodule-unpack.ts +265 -0
- package/src/commands/submodule-update-command.ts +39 -5
- package/src/commands/subtree-shift.ts +215 -0
- package/src/commands/switch-command.ts +9 -0
- package/src/commands/tree-restore.ts +6 -1
- package/src/commands/worktree-overwrite-checks.ts +5 -0
- package/src/errors/command-errors.ts +35 -0
- package/src/git-command.ts +87 -1
- package/src/git.ts +146 -0
- package/src/guarded-transport-command.ts +171 -0
- package/src/index.ts +1 -0
- package/src/rename/detect-renames.ts +42 -8
- package/src/rename/diffcore-break.ts +166 -0
- package/src/rename/index.ts +1 -0
- package/src/results/blame-format.ts +268 -43
- package/src/results/clone-result.ts +6 -0
- package/src/results/diff-dirstat.ts +117 -0
- package/src/results/diff-entry.ts +12 -0
- package/src/results/diff-formatter.ts +1 -0
- package/src/results/diff-output.ts +127 -2
- package/src/results/fetch-result.ts +12 -1
- package/src/results/index.ts +2 -0
- package/src/results/init-result.ts +10 -1
- package/src/results/line-range-hunks.ts +126 -0
- package/src/results/merge-result.ts +9 -0
- package/src/results/pull-result.ts +7 -0
- package/src/results/push-result.ts +5 -0
- package/src/results/status-result.ts +2 -2
- package/src/transport-command.ts +34 -3
- package/dist/fsck-DLRpbwTj.js +0 -13405
- package/dist/results-TB2IJ64h.js +0 -4700
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* (`fatal:`, exit 128; a usage error, 129) the command throws {@link SubmoduleCommandError},
|
|
7
7
|
* whose `result` holds what was printed before.
|
|
8
8
|
*/
|
|
9
|
-
import { FileMode, type ObjectId } from "@statewalker/vcs-core";
|
|
9
|
+
import { FileMode, type ObjectId, objectFormatOf } from "@statewalker/vcs-core";
|
|
10
10
|
import { isGitDirectory } from "@statewalker/vcs-store-files";
|
|
11
11
|
import type { GitTransportRegistry } from "@statewalker/vcs-transport";
|
|
12
12
|
import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
parsePathspec,
|
|
28
28
|
pathspecErrors,
|
|
29
29
|
} from "./pathspec.js";
|
|
30
|
+
import { ReadTreeCommand } from "./read-tree-command.js";
|
|
30
31
|
import { RmCommand } from "./rm-command.js";
|
|
31
32
|
import {
|
|
32
33
|
defaultRemoteOf,
|
|
@@ -61,6 +62,10 @@ export interface SubmoduleCloneOptions {
|
|
|
61
62
|
references?: string[];
|
|
62
63
|
/** `--require-init`: a non-empty directory at the path is refused */
|
|
63
64
|
requireInit?: boolean;
|
|
65
|
+
/** `--filter=<spec>` */
|
|
66
|
+
filter?: string;
|
|
67
|
+
/** `--single-branch` (true) / `--no-single-branch` (false) */
|
|
68
|
+
singleBranch?: boolean;
|
|
64
69
|
/**
|
|
65
70
|
* The transports and timeout the clone reaches its remote with. No credentials or headers
|
|
66
71
|
* are taken: a submodule's URL comes from the repository's content, so they are attached
|
|
@@ -537,6 +542,8 @@ export abstract class SubmoduleCommandBase extends GitCommand<SubmoduleCommandRe
|
|
|
537
542
|
.setDirectory(hostPath);
|
|
538
543
|
if (options.depth !== undefined && options.depth > 0) clone.setDepth(options.depth);
|
|
539
544
|
for (const reference of options.references ?? []) clone.addReference(reference);
|
|
545
|
+
if (options.filter !== undefined) clone.setFilter(options.filter);
|
|
546
|
+
if (options.singleBranch !== undefined) clone.setSingleBranch(options.singleBranch);
|
|
540
547
|
if (options.transports) clone.setTransports(options.transports);
|
|
541
548
|
if (options.timeout !== undefined) clone.setTimeout(options.timeout);
|
|
542
549
|
clone.shareHooksOf(this);
|
|
@@ -626,7 +633,7 @@ export abstract class SubmoduleCommandBase extends GitCommand<SubmoduleCommandRe
|
|
|
626
633
|
await this.absorbNested(path, innerGitDir ?? undefined);
|
|
627
634
|
}
|
|
628
635
|
|
|
629
|
-
|
|
636
|
+
protected filesOrFail(): FilesApi {
|
|
630
637
|
const files = this.worktreeAccess?.getFiles?.();
|
|
631
638
|
if (!files) throw new GitApiError("fatal: no worktree");
|
|
632
639
|
return files;
|
|
@@ -793,7 +800,7 @@ export abstract class SubmoduleCommandBase extends GitCommand<SubmoduleCommandRe
|
|
|
793
800
|
* repository, else what `read_gitfile_gently` makes of it (the repository a gitfile names,
|
|
794
801
|
* `gitDir` null when it lies beyond this FilesApi, or git's error code).
|
|
795
802
|
*/
|
|
796
|
-
|
|
803
|
+
protected async resolveGitdirGently(
|
|
797
804
|
path: string,
|
|
798
805
|
): Promise<ResolvedGitdir | { error: GitfileError }> {
|
|
799
806
|
const files = this.worktreeAccess?.getFiles?.();
|
|
@@ -905,6 +912,317 @@ export abstract class SubmoduleCommandBase extends GitCommand<SubmoduleCommandRe
|
|
|
905
912
|
}
|
|
906
913
|
}
|
|
907
914
|
|
|
915
|
+
/** Flags of {@link SubmoduleHeadMover.moveHead} (submodule.c's `SUBMODULE_MOVE_HEAD_*`). */
|
|
916
|
+
export interface SubmoduleMoveHeadFlags {
|
|
917
|
+
/** `SUBMODULE_MOVE_HEAD_DRY_RUN`: only check (`read-tree -n`), change nothing */
|
|
918
|
+
dryRun?: boolean;
|
|
919
|
+
/** `SUBMODULE_MOVE_HEAD_FORCE`: local changes are thrown away (`read-tree --reset`) */
|
|
920
|
+
force?: boolean;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* submodule.c's `submodule_move_head` for the unpack-trees runs of a superproject
|
|
925
|
+
* (`checkout`, `switch`, `reset`, `restore`, `read-tree` with `--recurse-submodules`): the
|
|
926
|
+
* submodule at a path moved from one commit to another (`null` for none: a submodule coming
|
|
927
|
+
* into existence or going away) by its own `read-tree --recurse-submodules` (in-process, the
|
|
928
|
+
* nested submodules moved the same way), its HEAD then detached at the new commit, or, for
|
|
929
|
+
* one going away, its gitfile removed, its directory if empty and its `core.worktree` unset.
|
|
930
|
+
* Its `error:` lines collect in the output ({@link takeStderr}); git's deaths throw
|
|
931
|
+
* `SubmoduleCommandError`. Not a command of its own.
|
|
932
|
+
*
|
|
933
|
+
* @internal
|
|
934
|
+
*/
|
|
935
|
+
export class SubmoduleHeadMover extends SubmoduleCommandBase {
|
|
936
|
+
constructor(workingCopy: WorkingCopy, superPrefix: string) {
|
|
937
|
+
super(workingCopy);
|
|
938
|
+
this.superPrefix = superPrefix;
|
|
939
|
+
// `.gitmodules` warnings are printed by the commands that read it for themselves
|
|
940
|
+
this.modelWarningsShown = true;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
async call(): Promise<SubmoduleCommandResult> {
|
|
944
|
+
throw new GitApiError("SubmoduleHeadMover is not a command");
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
/** What was printed since the last call (git's immediate `error:` lines). */
|
|
948
|
+
takeStderr(): string {
|
|
949
|
+
const text = this.out.stderr;
|
|
950
|
+
this.out.stderr = "";
|
|
951
|
+
return text;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/** `repo_read_gitmodules` again (after `.gitmodules` was checked out). */
|
|
955
|
+
reload(): void {
|
|
956
|
+
this.forgetModel();
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/** `submodule_from_ce` of a gitlink at `path`: `.gitmodules` names a submodule there. */
|
|
960
|
+
async isSubmodule(path: string): Promise<boolean> {
|
|
961
|
+
return (await this.model()).fromPath(path) !== undefined;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/** git's `file_exists` (`lstat`) of a worktree path. */
|
|
965
|
+
async exists(path: string): Promise<boolean> {
|
|
966
|
+
return (await this.kindOf(path)) !== undefined;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/** The kind of what `lstat` finds at a worktree path (`symlink` for a link). */
|
|
970
|
+
async kind(path: string): Promise<string | undefined> {
|
|
971
|
+
const files = this.worktreeAccess?.getFiles?.();
|
|
972
|
+
if (!files) return undefined;
|
|
973
|
+
return lstatKind(files, this.filesPath(path));
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* A submodule path that is a symbolic link to a repository: git's stat follows it, finds the
|
|
978
|
+
* submodule populated and dies in `validate_submodule_path` before any change.
|
|
979
|
+
*/
|
|
980
|
+
async validateLinked(path: string): Promise<void> {
|
|
981
|
+
if ((await this.kind(path)) !== "symlink") return;
|
|
982
|
+
if ((await this.kindThroughLinks(`${path}/.git`)) === undefined) return;
|
|
983
|
+
await this.validatePath(path);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
/** `is_submodule_populated_gently` (with an error pointer: never dies). */
|
|
987
|
+
async populated(path: string): Promise<boolean> {
|
|
988
|
+
return !("error" in (await this.resolveGitdirGently(path)));
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/** Whether `<path>/.git` is a repository directory (not absorbed into the superproject). */
|
|
992
|
+
async hasGitDirectory(path: string): Promise<boolean> {
|
|
993
|
+
const state = await this.resolveGitdirGently(path);
|
|
994
|
+
return !("error" in state) && state.kind === "directory";
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/** `submodule_move_head`; false where git's returns an error (its lines in the output). */
|
|
998
|
+
async moveHead(
|
|
999
|
+
path: string,
|
|
1000
|
+
oldHead: string | null,
|
|
1001
|
+
newHead: string | null,
|
|
1002
|
+
flags: SubmoduleMoveHeadFlags = {},
|
|
1003
|
+
): Promise<boolean> {
|
|
1004
|
+
const model = await this.model();
|
|
1005
|
+
if (!model.isActive(path)) return true;
|
|
1006
|
+
if (oldHead !== null) await this.validateLinked(path);
|
|
1007
|
+
if (oldHead !== null && !(await this.populatedGently(path, flags.force === true))) return true;
|
|
1008
|
+
const sub = model.fromPath(path);
|
|
1009
|
+
if (!sub) return true;
|
|
1010
|
+
await this.validatePath(path);
|
|
1011
|
+
if (oldHead !== null && !flags.force && (await this.hasDirtyIndex(path))) {
|
|
1012
|
+
this.out.stderr += `error: submodule '${path}' has dirty index\n`;
|
|
1013
|
+
return false;
|
|
1014
|
+
}
|
|
1015
|
+
const gitDir = await model.gitDirOf(sub.name);
|
|
1016
|
+
if (!flags.dryRun) {
|
|
1017
|
+
if (oldHead !== null) {
|
|
1018
|
+
if (!(await this.usesGitfile(path))) await this.absorbGitDirIntoSuperproject(path);
|
|
1019
|
+
} else if (gitDir !== undefined) {
|
|
1020
|
+
await this.connectWorkTreeAndGitDir(path, gitDir);
|
|
1021
|
+
// make sure the index is clean as well (submodule_reset_index)
|
|
1022
|
+
if (
|
|
1023
|
+
!(await this.readTreeIn(path, (c) => c.setReset(true).setUpdate(true), [null], false))
|
|
1024
|
+
) {
|
|
1025
|
+
this.die("fatal: could not reset submodule index");
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
if (oldHead !== null && flags.force && gitDir !== undefined) {
|
|
1029
|
+
await this.connectRecursively(path, gitDir, 0);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
const merged = await this.readTreeIn(
|
|
1033
|
+
path,
|
|
1034
|
+
(c) => {
|
|
1035
|
+
c.setRecurseSubmodules(true);
|
|
1036
|
+
if (flags.dryRun) c.setDryRun(true);
|
|
1037
|
+
else c.setUpdate(true);
|
|
1038
|
+
return flags.force ? c.setReset(true) : c.setMerge(true);
|
|
1039
|
+
},
|
|
1040
|
+
flags.force ? [newHead] : [oldHead, newHead],
|
|
1041
|
+
true,
|
|
1042
|
+
);
|
|
1043
|
+
if (!merged) {
|
|
1044
|
+
this.out.stderr += `error: Submodule '${path}' could not be updated.\n`;
|
|
1045
|
+
return false;
|
|
1046
|
+
}
|
|
1047
|
+
if (flags.dryRun) return true;
|
|
1048
|
+
if (newHead !== null) {
|
|
1049
|
+
const inner = await this.openSubmodule(path);
|
|
1050
|
+
if (!inner || !(await this.detachHead(inner, newHead))) return false;
|
|
1051
|
+
} else {
|
|
1052
|
+
const files = this.filesOrFail();
|
|
1053
|
+
await files.remove(this.filesPath(`${path}/.git`)).catch(() => false);
|
|
1054
|
+
const dir = this.filesPath(path);
|
|
1055
|
+
if ((await files.stats(dir).catch(() => undefined))?.kind === "directory") {
|
|
1056
|
+
let empty = true;
|
|
1057
|
+
for await (const _ of files.list(dir)) {
|
|
1058
|
+
empty = false;
|
|
1059
|
+
break;
|
|
1060
|
+
}
|
|
1061
|
+
if (empty) await files.remove(dir).catch(() => false);
|
|
1062
|
+
}
|
|
1063
|
+
// submodule_unset_core_worktree
|
|
1064
|
+
const unset =
|
|
1065
|
+
gitDir !== undefined &&
|
|
1066
|
+
(await setInConfigFile(this.workingCopy, `${gitDir}/config`, "core.worktree", undefined)
|
|
1067
|
+
.then(() => true)
|
|
1068
|
+
.catch(() => false));
|
|
1069
|
+
if (!unset) {
|
|
1070
|
+
this.out.stderr += `warning: Could not unset core.worktree setting in submodule '${path}'\n`;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
return true;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
/**
|
|
1077
|
+
* `is_submodule_populated_gently`: `<path>/.git` names a repository. Without `gentle`
|
|
1078
|
+
* (no error code pointer) the gitfile errors `read_gitfile_error_die` dies on are deaths.
|
|
1079
|
+
*/
|
|
1080
|
+
private async populatedGently(path: string, gentle: boolean): Promise<boolean> {
|
|
1081
|
+
const state = await this.resolveGitdirGently(path);
|
|
1082
|
+
if (!("error" in state)) return true;
|
|
1083
|
+
if (!gentle) {
|
|
1084
|
+
if (state.error === "not-a-repo") {
|
|
1085
|
+
const files = this.filesOrFail();
|
|
1086
|
+
const text = decodeGitPath(
|
|
1087
|
+
await readFile(files, this.filesPath(`${path}/.git`)).catch(() => new Uint8Array()),
|
|
1088
|
+
);
|
|
1089
|
+
this.die(`fatal: not a git repository: ${text.replace(/^gitdir: /, "").trim()}`);
|
|
1090
|
+
}
|
|
1091
|
+
const fatal = GITFILE_ERRORS[state.error];
|
|
1092
|
+
if (fatal) this.die(`fatal: ${fatal}${path}/.git`);
|
|
1093
|
+
}
|
|
1094
|
+
return false;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/** `submodule_has_dirty_index`: `git diff-index --quiet --cached HEAD` there fails. */
|
|
1098
|
+
private async hasDirtyIndex(path: string): Promise<boolean> {
|
|
1099
|
+
const inner = await this.openSubmodule(path);
|
|
1100
|
+
if (!inner) return true;
|
|
1101
|
+
return new SubmoduleIndexProbe(inner).call();
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
/**
|
|
1105
|
+
* `submodule_uses_gitfile`: `<path>/.git` is a gitfile, and so is every populated nested
|
|
1106
|
+
* submodule's (`submodule foreach --recursive test -f .git`).
|
|
1107
|
+
*/
|
|
1108
|
+
private async usesGitfile(path: string): Promise<boolean> {
|
|
1109
|
+
const state = await this.resolveGitdirGently(path);
|
|
1110
|
+
if ("error" in state || state.kind !== "gitfile") return false;
|
|
1111
|
+
const files = this.filesOrFail();
|
|
1112
|
+
const inner = await this.openSubmodule(path);
|
|
1113
|
+
if (!inner) return true;
|
|
1114
|
+
const nested = async (wc: WorkingCopy, prefix: string, depth: number): Promise<boolean> => {
|
|
1115
|
+
if (depth > MAX_ABSORB_DEPTH) return false;
|
|
1116
|
+
for await (const entry of wc.checkout.staging.entries()) {
|
|
1117
|
+
if (entry.mode !== FileMode.GITLINK || entry.stage !== 0) continue;
|
|
1118
|
+
const at = `${prefix}/${entry.path}`;
|
|
1119
|
+
const kind = (await files.stats(this.filesPath(`${at}/.git`)).catch(() => undefined))?.kind;
|
|
1120
|
+
if (kind === undefined) continue;
|
|
1121
|
+
if (kind !== "file") return false;
|
|
1122
|
+
const deeper = await wc.worktree.openGitlink?.(entry.path).catch(() => undefined);
|
|
1123
|
+
if (deeper && !(await nested(deeper, at, depth + 1))) return false;
|
|
1124
|
+
}
|
|
1125
|
+
return true;
|
|
1126
|
+
};
|
|
1127
|
+
return nested(inner, path, 0);
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* dir.c's `connect_work_tree_and_git_dir(path, gitDir, 1)`: the gitfile and `core.worktree`,
|
|
1132
|
+
* then the same for every nested submodule `.gitmodules` names and that is active
|
|
1133
|
+
* (`connect_wt_gitdir_in_nested`), populated or not.
|
|
1134
|
+
*/
|
|
1135
|
+
private async connectRecursively(path: string, gitDir: string, depth: number): Promise<void> {
|
|
1136
|
+
await this.connectWorkTreeAndGitDir(path, gitDir);
|
|
1137
|
+
if (depth > MAX_ABSORB_DEPTH) return;
|
|
1138
|
+
const inner = await this.worktreeAccess?.openGitlink?.(path, { gitDir }).catch(() => undefined);
|
|
1139
|
+
if (!inner) return;
|
|
1140
|
+
const model = await SubmoduleModel.load(inner).catch(() => undefined);
|
|
1141
|
+
if (!model) return;
|
|
1142
|
+
for await (const entry of inner.checkout.staging.entries()) {
|
|
1143
|
+
if (entry.mode !== FileMode.GITLINK || entry.stage !== 0) continue;
|
|
1144
|
+
const sub = model.fromPath(entry.path);
|
|
1145
|
+
if (!sub || !model.isActive(entry.path)) continue;
|
|
1146
|
+
const nestedGitDir = await model.gitDirOf(sub.name).catch(() => undefined);
|
|
1147
|
+
if (nestedGitDir === undefined) continue;
|
|
1148
|
+
await this.connectRecursively(`${path}/${sub.path}`, nestedGitDir, depth + 1);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* git's child `read-tree --super-prefix=<prefix><path>/ ...` in the submodule
|
|
1154
|
+
* (`prepare_submodule_repo_env`: its own `.git`), `null` trees being the empty tree; its
|
|
1155
|
+
* error lines go to the output. False when it failed.
|
|
1156
|
+
*/
|
|
1157
|
+
private async readTreeIn(
|
|
1158
|
+
path: string,
|
|
1159
|
+
configure: (command: ReadTreeCommand) => ReadTreeCommand,
|
|
1160
|
+
trees: (string | null)[],
|
|
1161
|
+
recursing: boolean,
|
|
1162
|
+
): Promise<boolean> {
|
|
1163
|
+
const inner = await this.openSubmodule(path);
|
|
1164
|
+
if (!inner) {
|
|
1165
|
+
this.out.stderr += "fatal: not a git repository: '.git'\n";
|
|
1166
|
+
return false;
|
|
1167
|
+
}
|
|
1168
|
+
const command = configure(new ReadTreeCommand(inner)).setSuperPrefix(
|
|
1169
|
+
`${this.superPrefix}${path}/`,
|
|
1170
|
+
);
|
|
1171
|
+
if (!recursing) command.setRecurseSubmodules(false);
|
|
1172
|
+
const empty = objectFormatOf(inner.history).emptyTreeId;
|
|
1173
|
+
for (const tree of trees) command.addTree(tree ?? empty);
|
|
1174
|
+
try {
|
|
1175
|
+
const result = await command.call();
|
|
1176
|
+
for (const w of result.warnings) this.out.stderr += `${w}\n`;
|
|
1177
|
+
return true;
|
|
1178
|
+
} catch (error) {
|
|
1179
|
+
if (error instanceof SubmoduleCommandError) {
|
|
1180
|
+
this.out.stderr += error.result.stderr;
|
|
1181
|
+
this.out.stderr += `${error.message}\n`;
|
|
1182
|
+
return false;
|
|
1183
|
+
}
|
|
1184
|
+
if (!(error instanceof GitApiError)) throw error;
|
|
1185
|
+
this.out.stderr += `${error.message.replace(/\n$/, "")}\n`;
|
|
1186
|
+
return false;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/** `git update-ref HEAD --no-deref <id>` in the submodule. */
|
|
1191
|
+
private async detachHead(inner: WorkingCopy, id: string): Promise<boolean> {
|
|
1192
|
+
const refs = inner.history.refs;
|
|
1193
|
+
const result = await refs.batch([{ name: "HEAD", new: id, noDeref: true }]);
|
|
1194
|
+
if (!result.ok) await refs.set("HEAD", id);
|
|
1195
|
+
return true;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
/** `git diff-index --quiet --cached HEAD` of a working copy (true: it differs or fails). */
|
|
1200
|
+
class SubmoduleIndexProbe extends GitCommand<boolean> {
|
|
1201
|
+
async call(): Promise<boolean> {
|
|
1202
|
+
const headId = (await this.refsStore.resolve("HEAD").catch(() => undefined))?.objectId;
|
|
1203
|
+
if (!headId) return true;
|
|
1204
|
+
const treeId = await this.commits.getTree(headId).catch(() => undefined);
|
|
1205
|
+
if (!treeId) return true;
|
|
1206
|
+
const head = new Map<string, { objectId: string; mode: number }>();
|
|
1207
|
+
const walk = async (id: string, prefix: string): Promise<void> => {
|
|
1208
|
+
for await (const entry of this.trees.loadTree(id)) {
|
|
1209
|
+
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
1210
|
+
if (entry.mode === FileMode.TREE) await walk(entry.id, path);
|
|
1211
|
+
else head.set(path, { objectId: entry.id, mode: entry.mode });
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
await walk(treeId, "");
|
|
1215
|
+
for await (const entry of this.staging.entries()) {
|
|
1216
|
+
const h = head.get(entry.path);
|
|
1217
|
+
if (entry.stage !== 0 || !h || h.objectId !== entry.objectId || h.mode !== entry.mode) {
|
|
1218
|
+
return true;
|
|
1219
|
+
}
|
|
1220
|
+
head.delete(entry.path);
|
|
1221
|
+
}
|
|
1222
|
+
return head.size > 0;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
908
1226
|
/**
|
|
909
1227
|
* `git submodule init [-q] [<path>...]`: each submodule of the index (matching the paths)
|
|
910
1228
|
* registered in `.git/config` from `.gitmodules`: `submodule.<name>.active` unless already
|