@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
|
@@ -38,6 +38,7 @@ import { coreBool, worktreeModeTrust } from "./core-config.js";
|
|
|
38
38
|
import type { OrtConflict } from "./ort-merge.js";
|
|
39
39
|
import { markIndexUpdate } from "./post-index-change.js";
|
|
40
40
|
import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
|
|
41
|
+
import type { SubmoduleUnpack } from "./submodule-unpack.js";
|
|
41
42
|
import {
|
|
42
43
|
planFlatRestore,
|
|
43
44
|
planTreeRestore,
|
|
@@ -853,7 +854,7 @@ export async function switchTrees(
|
|
|
853
854
|
sparse?.conflict(conflicts.map((c) => c.stagePath));
|
|
854
855
|
const switched = await switchTreesWith(ctx, head, target, { ...options, conflicts }, sparse);
|
|
855
856
|
if (switched.refused) return switched.refused;
|
|
856
|
-
if (sparse) {
|
|
857
|
+
if (sparse && !options.checkOnly) {
|
|
857
858
|
const outcome = await sparse.finish(ctx, { written: switched.written });
|
|
858
859
|
pushSparseWarnings(ctx.sparseWarnings, sparse, outcome, true);
|
|
859
860
|
}
|
|
@@ -893,6 +894,15 @@ export interface SwitchTreesOptions {
|
|
|
893
894
|
* (written, untracked files in the way refused), never as a staged deletion
|
|
894
895
|
*/
|
|
895
896
|
initialCheckout?: boolean;
|
|
897
|
+
/** `--recurse-submodules`: the active submodules checked and moved with the worktree */
|
|
898
|
+
submodules?: SubmoduleUnpack;
|
|
899
|
+
/** False (`read-tree -n`): the index is not written */
|
|
900
|
+
writeIndex?: boolean;
|
|
901
|
+
/**
|
|
902
|
+
* `read-tree -n` with `-u`: the checks an update makes (untracked files in the way, the
|
|
903
|
+
* submodules' dry runs) run, then nothing is written, neither worktree nor index
|
|
904
|
+
*/
|
|
905
|
+
checkOnly?: boolean;
|
|
896
906
|
}
|
|
897
907
|
|
|
898
908
|
/** git's default unpack-trees messages (`unpack_plumbing_errors`) for one refused path. */
|
|
@@ -947,6 +957,9 @@ async function switchTreesWith(
|
|
|
947
957
|
const untrackedRemoved: string[] = [];
|
|
948
958
|
const updates: string[] = [];
|
|
949
959
|
const removes: string[] = [];
|
|
960
|
+
const subs = options.submodules;
|
|
961
|
+
/** Paths whose submodule checks replace the untracked-file checks (verify_absent_1) */
|
|
962
|
+
const submodulePaths = new Set<string>();
|
|
950
963
|
const paths = [...new Set([...head.keys(), ...target.keys()])].sort();
|
|
951
964
|
for (const path of paths) {
|
|
952
965
|
const h = head.get(path);
|
|
@@ -960,17 +973,44 @@ async function switchTreesWith(
|
|
|
960
973
|
staged.push(path);
|
|
961
974
|
continue;
|
|
962
975
|
}
|
|
976
|
+
if (subs && checked && !quiet(path) && i.mode === FileMode.GITLINK) {
|
|
977
|
+
// deleted_entry's verify_absent_if_directory of the submodule going away
|
|
978
|
+
if (!t && update && (await subs.isSubmodule(path, i)) && (await subs.exists(path))) {
|
|
979
|
+
await subs.refuses(path, (h ?? i).objectId, null);
|
|
980
|
+
}
|
|
981
|
+
const refused = await subs.notUptodate(path, i);
|
|
982
|
+
if (refused) {
|
|
983
|
+
local.push(path);
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
if (refused === false) {
|
|
987
|
+
if (t && t.mode !== FileMode.GITLINK) await subs.fileReplacesRefuses(path, i);
|
|
988
|
+
if (t) await subs.mergedRefuses(path, i, t);
|
|
989
|
+
(t ? updates : removes).push(path);
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
963
993
|
if (checked && !quiet(path) && (await entryNotUptodate(checked, path, i, trust, indexTime))) {
|
|
964
994
|
local.push(path);
|
|
965
995
|
continue;
|
|
966
996
|
}
|
|
997
|
+
if (subs && t && !quiet(path)) await subs.mergedRefuses(path, i, t);
|
|
967
998
|
(t ? updates : removes).push(path);
|
|
968
999
|
continue;
|
|
969
1000
|
}
|
|
970
1001
|
if (t) {
|
|
971
1002
|
// a staged deletion of a path the target changes (none in an initial checkout)
|
|
972
|
-
if (h && !options.initialCheckout)
|
|
973
|
-
|
|
1003
|
+
if (h && !options.initialCheckout) {
|
|
1004
|
+
staged.push(path);
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
if (subs && !quiet(path)) {
|
|
1008
|
+
// merged_entry of a new submodule: verify_absent_1's submodule check, then its own
|
|
1009
|
+
const absent = update ? await subs.absentRefuses(path, t) : undefined;
|
|
1010
|
+
if (absent !== undefined) submodulePaths.add(path);
|
|
1011
|
+
if (!absent) await subs.mergedRefuses(path, undefined, t);
|
|
1012
|
+
}
|
|
1013
|
+
updates.push(path);
|
|
974
1014
|
continue;
|
|
975
1015
|
}
|
|
976
1016
|
// a deletion already staged: an untracked file there would be removed
|
|
@@ -983,7 +1023,7 @@ async function switchTreesWith(
|
|
|
983
1023
|
const writing = new Set(updates.filter((p) => !sparse || sparse.writes(p)));
|
|
984
1024
|
const found = worktree
|
|
985
1025
|
? await findInTheWay(worktree, {
|
|
986
|
-
writes: [...writing],
|
|
1026
|
+
writes: [...writing].filter((p) => !submodulePaths.has(p)),
|
|
987
1027
|
removes: new Set(deleting),
|
|
988
1028
|
index,
|
|
989
1029
|
...(await restoreCaseOptions(worktree, ignoreCase)),
|
|
@@ -991,30 +1031,49 @@ async function switchTreesWith(
|
|
|
991
1031
|
caseVariantsExpendable: true,
|
|
992
1032
|
})
|
|
993
1033
|
: { untracked: [], lostDirs: [], caseVariants: [] };
|
|
1034
|
+
const submoduleRejected = subs?.rejected ?? [];
|
|
1035
|
+
const plainMessage = () => {
|
|
1036
|
+
// unpack-trees without show_all_errors stops at the first refusal; the submodule lines
|
|
1037
|
+
// come with it, printed as the checks ran
|
|
1038
|
+
if (subs && submoduleRejected.length > 0) {
|
|
1039
|
+
const first = submoduleRejected[0] as string;
|
|
1040
|
+
return subs.plainRefusal(first, local.includes(first));
|
|
1041
|
+
}
|
|
1042
|
+
return firstPlainError({
|
|
1043
|
+
wouldOverwrite: staged,
|
|
1044
|
+
notUptodate: local,
|
|
1045
|
+
lostDir: found.lostDirs,
|
|
1046
|
+
untracked: found.untracked,
|
|
1047
|
+
untrackedRemoved,
|
|
1048
|
+
});
|
|
1049
|
+
};
|
|
1050
|
+
const porcelain = overwriteMessage(options.action, {
|
|
1051
|
+
staged,
|
|
1052
|
+
local,
|
|
1053
|
+
lostDirs: found.lostDirs,
|
|
1054
|
+
untracked: found.untracked,
|
|
1055
|
+
untrackedRemoved,
|
|
1056
|
+
submodules: submoduleRejected,
|
|
1057
|
+
});
|
|
994
1058
|
const message = options.plainErrors
|
|
995
|
-
?
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
untracked: found.untracked,
|
|
1000
|
-
untrackedRemoved,
|
|
1001
|
-
})
|
|
1002
|
-
: overwriteMessage(options.action, {
|
|
1003
|
-
staged,
|
|
1004
|
-
local,
|
|
1005
|
-
lostDirs: found.lostDirs,
|
|
1006
|
-
untracked: found.untracked,
|
|
1007
|
-
untrackedRemoved,
|
|
1008
|
-
});
|
|
1059
|
+
? plainMessage()
|
|
1060
|
+
: porcelain && subs
|
|
1061
|
+
? `${subs.printed()}${porcelain}`
|
|
1062
|
+
: porcelain;
|
|
1009
1063
|
if (message) {
|
|
1010
1064
|
return {
|
|
1011
1065
|
refused: {
|
|
1012
1066
|
message,
|
|
1013
|
-
paths:
|
|
1067
|
+
paths:
|
|
1068
|
+
subs && submoduleRejected.length > 0 && options.plainErrors
|
|
1069
|
+
? []
|
|
1070
|
+
: [...staged, ...local, ...found.lostDirs, ...found.untracked, ...untrackedRemoved],
|
|
1014
1071
|
},
|
|
1015
1072
|
written: new Set(),
|
|
1016
1073
|
};
|
|
1017
1074
|
}
|
|
1075
|
+
// `read-tree -n -u`: every check made (o->update stays on), nothing written
|
|
1076
|
+
if (options.checkOnly) return { written: new Set() };
|
|
1018
1077
|
|
|
1019
1078
|
// record_conflicted_index_entries checks out a conflict's stage-0 entry left skip-worktree
|
|
1020
1079
|
// (the switch kept it: the trees agree on it, or the index holds the target's already):
|
|
@@ -1048,12 +1107,22 @@ async function switchTreesWith(
|
|
|
1048
1107
|
}
|
|
1049
1108
|
for (const path of removes) {
|
|
1050
1109
|
if (quiet(path)) continue;
|
|
1051
|
-
|
|
1110
|
+
const old = index.get(path);
|
|
1111
|
+
if (subs && old?.mode === FileMode.GITLINK) await subs.unlink(worktree, path, old);
|
|
1112
|
+
else await worktree.remove(path);
|
|
1052
1113
|
await pruneEmptyParents(worktree, path);
|
|
1053
1114
|
}
|
|
1054
1115
|
// core.ignorecase: what verify_clean_subdirectory took as tracked in a directory a file
|
|
1055
1116
|
// replaces goes with the directory (checkout_entry removes the subtree)
|
|
1056
1117
|
await removeCaseVariants(worktree, found.caseVariants ?? []);
|
|
1118
|
+
if (subs) {
|
|
1119
|
+
for (const path of writing) {
|
|
1120
|
+
const old = index.get(path);
|
|
1121
|
+
if (old?.mode === FileMode.GITLINK && target.get(path)?.mode !== FileMode.GITLINK) {
|
|
1122
|
+
await subs.removeForFile(worktree, path, old);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1057
1126
|
if (writing.size > 0) {
|
|
1058
1127
|
// only the written paths are planned (each validated, its blob checked)
|
|
1059
1128
|
const plan = await planPathsRestore(
|
|
@@ -1088,6 +1157,14 @@ async function switchTreesWith(
|
|
|
1088
1157
|
},
|
|
1089
1158
|
);
|
|
1090
1159
|
}
|
|
1160
|
+
if (subs) {
|
|
1161
|
+
// check_updates: `.gitmodules` read again, then the submodules checked out
|
|
1162
|
+
subs.reload();
|
|
1163
|
+
for (const path of [...writing].sort()) {
|
|
1164
|
+
const t = planTarget.get(path);
|
|
1165
|
+
if (t?.mode === FileMode.GITLINK) await subs.checkout(worktree, path, t);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1091
1168
|
}
|
|
1092
1169
|
|
|
1093
1170
|
// the index: the switched paths take the target's entries (with the stat of the files
|
|
@@ -1189,7 +1266,10 @@ async function switchTreesWith(
|
|
|
1189
1266
|
switchedCacheTree = cacheTree;
|
|
1190
1267
|
}
|
|
1191
1268
|
// set once the changes are in: it describes the index they leave
|
|
1192
|
-
await rewriteIndex(ctx.staging, changes, {
|
|
1269
|
+
await rewriteIndex(ctx.staging, changes, {
|
|
1270
|
+
cacheTree: switchedCacheTree,
|
|
1271
|
+
...(options.writeIndex === false ? { write: false } : {}),
|
|
1272
|
+
});
|
|
1193
1273
|
return { written: worktree ? writing : new Set() };
|
|
1194
1274
|
}
|
|
1195
1275
|
|
|
@@ -145,7 +145,7 @@ function autoCommentChar(text: string): string {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/** A cleanup mode given by name (`--cleanup=<name>`, `commit.cleanup`), as git parses it. */
|
|
148
|
-
function parseCleanupMode(name: string): CleanupMode {
|
|
148
|
+
export function parseCleanupMode(name: string): CleanupMode {
|
|
149
149
|
const mode = Object.values(CleanupMode).find((m) => m === name);
|
|
150
150
|
if (!mode) {
|
|
151
151
|
throw new InvalidArgumentError("cleanup", name, `fatal: Invalid cleanup mode ${name}`);
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type { ObjectId } from "@statewalker/vcs-core";
|
|
2
|
+
import { wildmatch } from "@statewalker/vcs-working-tree";
|
|
3
|
+
|
|
4
|
+
import { DescribeError } from "../errors/command-errors.js";
|
|
5
|
+
import { GitCommand } from "../git-command.js";
|
|
6
|
+
import { commitLoaderOf, type NameRevInput, runNameRev } from "./name-rev.js";
|
|
7
|
+
|
|
8
|
+
/** `git name-rev`'s output. */
|
|
9
|
+
export interface NameRevResult {
|
|
10
|
+
/** git's stdout */
|
|
11
|
+
stdout: string;
|
|
12
|
+
/** git's stderr lines (`Could not get sha1 for <rev>. Skipping.`) */
|
|
13
|
+
stderr: string[];
|
|
14
|
+
/** Each revision given and its name (undefined where git prints `undefined`) */
|
|
15
|
+
names: { revision: string; name: string | undefined }[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Find symbolic names for commits: git name-rev (builtin/name-rev.c). Every ref (or the
|
|
20
|
+
* ones `--tags`/`--refs`/`--exclude` keep) names the commits it reaches, the nearest first:
|
|
21
|
+
* `main~2`, `tags/v1.0^0`, `main^2~3`; generations of the commit-graph (else commit dates
|
|
22
|
+
* less a day) stop the walk below the oldest commit asked about.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const { stdout } = await git.nameRev().addRevisions("HEAD~2").call();
|
|
27
|
+
* // "HEAD~2 main~2\n"
|
|
28
|
+
* const { stdout } = await git.nameRev().setTags(true).setNameOnly(true).addRevisions(id).call();
|
|
29
|
+
* const { stdout } = await git.nameRev().setAnnotateStdin(text).call(); // ids annotated
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class NameRevCommand extends GitCommand<NameRevResult> {
|
|
33
|
+
private revisions: string[] = [];
|
|
34
|
+
private nameOnly = false;
|
|
35
|
+
private tags = false;
|
|
36
|
+
private refs: string[] = [];
|
|
37
|
+
private exclude: string[] = [];
|
|
38
|
+
private allowUndefined = true;
|
|
39
|
+
private always = false;
|
|
40
|
+
private all = false;
|
|
41
|
+
private annotate?: string;
|
|
42
|
+
private peelTag = false;
|
|
43
|
+
|
|
44
|
+
/** The revisions to name (`<commit>...`). */
|
|
45
|
+
addRevisions(...revisions: string[]): this {
|
|
46
|
+
this.checkCallable();
|
|
47
|
+
this.revisions.push(...revisions);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** `--name-only`: the names alone, without the revisions. */
|
|
52
|
+
setNameOnly(nameOnly: boolean): this {
|
|
53
|
+
this.checkCallable();
|
|
54
|
+
this.nameOnly = nameOnly;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** `--tags`: only tags name commits. */
|
|
59
|
+
setTags(tags: boolean): this {
|
|
60
|
+
this.checkCallable();
|
|
61
|
+
this.tags = tags;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** `--refs=<pattern>` (repeatable): only refs a pattern matches, whole or a subpath. */
|
|
66
|
+
addRefs(...patterns: string[]): this {
|
|
67
|
+
this.checkCallable();
|
|
68
|
+
this.refs.push(...patterns);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** `--exclude=<pattern>` (repeatable): no refs a pattern matches. */
|
|
73
|
+
addExclude(...patterns: string[]): this {
|
|
74
|
+
this.checkCallable();
|
|
75
|
+
this.exclude.push(...patterns);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** `--[no-]undefined`: false dies on a commit no ref names (default true). */
|
|
80
|
+
setUndefined(allow: boolean): this {
|
|
81
|
+
this.checkCallable();
|
|
82
|
+
this.allowUndefined = allow;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** `--always`: an unnamed object's abbreviated id (with `--no-undefined`). */
|
|
87
|
+
setAlways(always: boolean): this {
|
|
88
|
+
this.checkCallable();
|
|
89
|
+
this.always = always;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** `--all`: every commit the refs reach. */
|
|
94
|
+
setAll(all: boolean): this {
|
|
95
|
+
this.checkCallable();
|
|
96
|
+
this.all = all;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** `--annotate-stdin`: `text` with each full object id followed by its name. */
|
|
101
|
+
setAnnotateStdin(text: string | undefined): this {
|
|
102
|
+
this.checkCallable();
|
|
103
|
+
this.annotate = text;
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** `--peel-tag` (git's internal option): a tag given is named by its commit. */
|
|
108
|
+
setPeelTag(peel: boolean): this {
|
|
109
|
+
this.checkCallable();
|
|
110
|
+
this.peelTag = peel;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @throws DescribeError where git dies (`cannot describe '<id>'`, exit 128; a list with
|
|
116
|
+
* `--all` or `--annotate-stdin`, exit 129)
|
|
117
|
+
*/
|
|
118
|
+
async call(): Promise<NameRevResult> {
|
|
119
|
+
this.checkCallable();
|
|
120
|
+
this.setCallable(false);
|
|
121
|
+
const modes =
|
|
122
|
+
(this.all ? 1 : 0) + (this.annotate !== undefined ? 1 : 0) + (this.revisions.length ? 1 : 0);
|
|
123
|
+
if (modes > 1) {
|
|
124
|
+
throw new DescribeError(
|
|
125
|
+
"error: Specify either a list, or --all, not both!\nusage: git name-rev [<options>] <commit>...",
|
|
126
|
+
"",
|
|
127
|
+
129,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
let input: NameRevInput;
|
|
131
|
+
if (this.all) input = { all: true };
|
|
132
|
+
else if (this.annotate !== undefined) input = { annotate: this.annotate };
|
|
133
|
+
else {
|
|
134
|
+
input = {
|
|
135
|
+
revs: await Promise.all(
|
|
136
|
+
this.revisions.map(async (name) => ({
|
|
137
|
+
name,
|
|
138
|
+
id: await this.resolveRevision(name).catch(() => undefined as ObjectId | undefined),
|
|
139
|
+
})),
|
|
140
|
+
),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const resolver = this.revisionResolver();
|
|
144
|
+
const tags = this.tagsStore;
|
|
145
|
+
const run = await runNameRev(
|
|
146
|
+
{
|
|
147
|
+
refs: this.refsStore,
|
|
148
|
+
objectType: (id) => resolver.objectType(id),
|
|
149
|
+
loadTag: async (id) => tags?.load(id),
|
|
150
|
+
loadCommit: commitLoaderOf(this.walkCommits, () => this.shallowCommits()),
|
|
151
|
+
refExists: (name) => this.refsStore.has(name).catch(() => false),
|
|
152
|
+
abbreviate: (id) => this.abbreviateObjectId(id),
|
|
153
|
+
wildmatch: (pattern, text) => wildmatch(pattern, text),
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
nameOnly: this.nameOnly,
|
|
157
|
+
tags: this.tags,
|
|
158
|
+
refs: this.refs,
|
|
159
|
+
exclude: this.exclude,
|
|
160
|
+
allowUndefined: this.allowUndefined,
|
|
161
|
+
always: this.always,
|
|
162
|
+
peelTag: this.peelTag,
|
|
163
|
+
hexLength: this.objectFormat.hexLength,
|
|
164
|
+
},
|
|
165
|
+
input,
|
|
166
|
+
);
|
|
167
|
+
if (run.fatal) {
|
|
168
|
+
throw new DescribeError([...run.stderr, run.fatal].join("\n"), run.stdout, 128);
|
|
169
|
+
}
|
|
170
|
+
const names: NameRevResult["names"] = [];
|
|
171
|
+
if (!this.all && this.annotate === undefined && !this.nameOnly) {
|
|
172
|
+
for (const line of run.stdout.split("\n")) {
|
|
173
|
+
if (line === "") continue;
|
|
174
|
+
const space = line.lastIndexOf(" ");
|
|
175
|
+
const name = line.slice(space + 1);
|
|
176
|
+
names.push({
|
|
177
|
+
revision: line.slice(0, space),
|
|
178
|
+
name: name === "undefined" ? undefined : name,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return { stdout: run.stdout, stderr: run.stderr, names };
|
|
183
|
+
}
|
|
184
|
+
}
|