@statewalker/vcs-commands 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/commands/add-command.d.ts.map +1 -1
  2. package/dist/commands/checkout-command.d.ts +7 -24
  3. package/dist/commands/checkout-command.d.ts.map +1 -1
  4. package/dist/commands/clean-command.d.ts +34 -4
  5. package/dist/commands/clean-command.d.ts.map +1 -1
  6. package/dist/commands/clone-command.d.ts +62 -7
  7. package/dist/commands/clone-command.d.ts.map +1 -1
  8. package/dist/commands/core-config.d.ts +16 -0
  9. package/dist/commands/core-config.d.ts.map +1 -0
  10. package/dist/commands/fetch-command.d.ts +96 -14
  11. package/dist/commands/fetch-command.d.ts.map +1 -1
  12. package/dist/commands/index.d.ts +1 -0
  13. package/dist/commands/index.d.ts.map +1 -1
  14. package/dist/commands/index.js +2 -2
  15. package/dist/commands/init-command.d.ts.map +1 -1
  16. package/dist/commands/remote-command.d.ts +115 -6
  17. package/dist/commands/remote-command.d.ts.map +1 -1
  18. package/dist/commands/reset-command.d.ts.map +1 -1
  19. package/dist/commands/stash-apply-command.d.ts +35 -13
  20. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  21. package/dist/commands/stash-create-command.d.ts +59 -25
  22. package/dist/commands/stash-create-command.d.ts.map +1 -1
  23. package/dist/commands/stash-drop-command.d.ts +8 -2
  24. package/dist/commands/stash-drop-command.d.ts.map +1 -1
  25. package/dist/commands/stash-list-command.d.ts +2 -4
  26. package/dist/commands/stash-list-command.d.ts.map +1 -1
  27. package/dist/commands/stash-working-tree.d.ts +72 -0
  28. package/dist/commands/stash-working-tree.d.ts.map +1 -0
  29. package/dist/commands/status-command.d.ts +29 -22
  30. package/dist/commands/status-command.d.ts.map +1 -1
  31. package/dist/commands/tree-restore.d.ts +52 -5
  32. package/dist/commands/tree-restore.d.ts.map +1 -1
  33. package/dist/commands/worktree-overwrite-checks.d.ts +64 -0
  34. package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
  35. package/dist/{commands-BpeXZTC3.js → commands-CsLNyvZ1.js} +2940 -631
  36. package/dist/core-commands/add.command.impl.d.ts.map +1 -1
  37. package/dist/core-commands/index.d.ts +0 -3
  38. package/dist/core-commands/index.d.ts.map +1 -1
  39. package/dist/errors/checkout-errors.d.ts +13 -0
  40. package/dist/errors/checkout-errors.d.ts.map +1 -1
  41. package/dist/errors/index.js +18 -1
  42. package/dist/git-command.d.ts +10 -1
  43. package/dist/git-command.d.ts.map +1 -1
  44. package/dist/git.d.ts +21 -3
  45. package/dist/git.d.ts.map +1 -1
  46. package/dist/index.js +4 -4
  47. package/dist/remote-config/index.d.ts +1 -0
  48. package/dist/remote-config/index.d.ts.map +1 -1
  49. package/dist/remote-config/remote-config-store.d.ts +18 -0
  50. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  51. package/dist/remote-config/remote-refs.d.ts +37 -0
  52. package/dist/remote-config/remote-refs.d.ts.map +1 -0
  53. package/dist/results/clone-result.d.ts +6 -0
  54. package/dist/results/clone-result.d.ts.map +1 -1
  55. package/dist/results/fetch-result.d.ts +9 -1
  56. package/dist/results/fetch-result.d.ts.map +1 -1
  57. package/dist/results/index.js +2 -2
  58. package/dist/results/status-result.d.ts +91 -20
  59. package/dist/results/status-result.d.ts.map +1 -1
  60. package/dist/{status-result-BapZoQaR.js → status-result-BpyUK1Sg.js} +113 -5
  61. package/dist/transport-command.d.ts +12 -0
  62. package/dist/transport-command.d.ts.map +1 -1
  63. package/package.json +11 -10
  64. package/src/commands/add-command.ts +9 -7
  65. package/src/commands/checkout-command.ts +200 -118
  66. package/src/commands/clean-command.ts +187 -88
  67. package/src/commands/clone-command.ts +244 -40
  68. package/src/commands/core-config.ts +41 -0
  69. package/src/commands/fetch-command.ts +476 -57
  70. package/src/commands/index.ts +1 -0
  71. package/src/commands/init-command.ts +32 -7
  72. package/src/commands/remote-command.ts +429 -19
  73. package/src/commands/reset-command.ts +18 -5
  74. package/src/commands/stash-apply-command.ts +632 -97
  75. package/src/commands/stash-create-command.ts +142 -62
  76. package/src/commands/stash-drop-command.ts +53 -5
  77. package/src/commands/stash-list-command.ts +10 -4
  78. package/src/commands/stash-working-tree.ts +243 -0
  79. package/src/commands/status-command.ts +197 -91
  80. package/src/commands/tree-restore.ts +142 -13
  81. package/src/commands/worktree-overwrite-checks.ts +215 -0
  82. package/src/core-commands/add.command.impl.ts +2 -4
  83. package/src/core-commands/index.ts +0 -8
  84. package/src/errors/checkout-errors.ts +20 -0
  85. package/src/git-command.ts +42 -1
  86. package/src/git.ts +30 -2
  87. package/src/remote-config/index.ts +1 -0
  88. package/src/remote-config/remote-config-store.ts +84 -8
  89. package/src/remote-config/remote-refs.ts +103 -0
  90. package/src/results/clone-result.ts +6 -0
  91. package/src/results/fetch-result.ts +9 -1
  92. package/src/results/status-result.ts +212 -29
  93. package/src/transport-command.ts +18 -0
  94. package/dist/core-commands/checkout.command.d.ts +0 -103
  95. package/dist/core-commands/checkout.command.d.ts.map +0 -1
  96. package/dist/core-commands/checkout.command.impl.d.ts +0 -110
  97. package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
  98. package/src/core-commands/checkout.command.impl.ts +0 -564
  99. package/src/core-commands/checkout.command.ts +0 -125
@@ -2,8 +2,8 @@
2
2
  * Writing a tree back into the working tree.
3
3
  *
4
4
  * Shared by the commands that make the working tree match a tree object -
5
- * `reset --hard` and `stash apply`. Both need the same two-phase shape: plan
6
- * and validate the whole restore first, then write. A tree that cannot be
5
+ * `reset --hard`, `stash apply` and the checkout of `clone`. All need the
6
+ * same two-phase shape: plan and validate the whole restore first, then write. A tree that cannot be
7
7
  * restored faithfully therefore fails with the working tree still intact,
8
8
  * rather than half-way through rewriting it.
9
9
  */
@@ -26,19 +26,57 @@ export interface TreeRestorePlan {
26
26
  * is one the target tree deletes.
27
27
  */
28
28
  paths: Set<string>;
29
+ /** The gitlinks (submodules) of the tree, which are not written. */
30
+ gitlinks: RestoreEntry[];
31
+ /**
32
+ * With `ignoreCase`: files whose paths differ only in case (`README`, `readme`). Both are
33
+ * written, the last one wins, as git checks them out with its "the following paths have
34
+ * collided" warning.
35
+ */
36
+ collided: string[];
37
+ }
38
+ /** Options of {@link planTreeRestore}. */
39
+ export interface TreeRestoreOptions {
40
+ /**
41
+ * Plan symlinks as entries to write (their blob is the link target), for a
42
+ * worktree that writes mode `0o120000` as a link or as a file holding the
43
+ * target, as git does. Without it a symlink fails the plan.
44
+ */
45
+ symlinks?: boolean;
46
+ /**
47
+ * Compare paths case-insensitively (`core.ignorecase`), as a case-folding filesystem
48
+ * would: a path beneath a file, link or submodule of another case (`A` a link, `a/x`)
49
+ * is refused, it would be written through the link; two files differing only in case
50
+ * are both planned (the last wins) and reported in `collided`, as git does.
51
+ */
52
+ ignoreCase?: boolean;
53
+ /** The worktree is on Windows (`capabilities.windowsPaths`): git's Windows path rules. */
54
+ windows?: boolean;
55
+ /** Top-level names the worktree's storage reserves (`capabilities.reservedNames`) */
56
+ reservedNames?: string[];
57
+ /**
58
+ * Only these paths will be written: the blobs of the others are not checked (every path
59
+ * is still validated). Absent: every blob is checked.
60
+ */
61
+ writing?: Set<string>;
29
62
  }
30
63
  /**
31
64
  * Walk a tree and plan which files to restore, validating as it goes.
32
65
  *
33
66
  * Throws on anything that cannot be restored faithfully, so the caller can
34
- * abort before mutating the working tree.
67
+ * abort before mutating the working tree: a path git's `verify_path` refuses
68
+ * (`.git` under any spelling, a symlinked `.gitmodules`), and two entries that
69
+ * collide - the same path twice, a file and a directory of one name, or a path
70
+ * beneath a planned file, symlink or submodule (which would write through the
71
+ * link), compared case-insensitively with `ignoreCase`.
35
72
  *
36
73
  * @param trees Tree storage to walk
37
74
  * @param blobs Blob storage, checked for the content of every planned file
38
75
  * @param treeId Tree to restore
39
76
  * @param operation Names the operation in failure messages, e.g. `reset --hard`
77
+ * @param options What else the worktree can restore
40
78
  */
41
- export declare function planTreeRestore(trees: CommandTrees, blobs: Blobs, treeId: ObjectId, operation: string): Promise<TreeRestorePlan>;
79
+ export declare function planTreeRestore(trees: CommandTrees, blobs: Blobs, treeId: ObjectId, operation: string, options?: TreeRestoreOptions): Promise<TreeRestorePlan>;
42
80
  /**
43
81
  * Execute a plan produced by {@link planTreeRestore}, writing every file.
44
82
  *
@@ -47,5 +85,14 @@ export declare function planTreeRestore(trees: CommandTrees, blobs: Blobs, treeI
47
85
  * @param plan The validated plan
48
86
  * @param operation Names the operation in failure messages
49
87
  */
50
- export declare function writeTreeRestorePlan(worktree: Worktree, blobs: Blobs, plan: TreeRestorePlan, operation: string): Promise<void>;
88
+ export declare function writeTreeRestorePlan(worktree: Worktree, blobs: Blobs, plan: TreeRestorePlan, operation: string, options?: TreeWriteOptions): Promise<void>;
89
+ /** Options of {@link writeTreeRestorePlan}. */
90
+ export interface TreeWriteOptions {
91
+ /** Write symlinks as links (default); false writes them as files holding the target. */
92
+ symlinks?: boolean;
93
+ /** A forced checkout: unlink a file or link standing where a directory must go. */
94
+ replaceInTheWay?: boolean;
95
+ /** Create an empty directory for each gitlink (submodule). */
96
+ gitlinks?: boolean;
97
+ }
51
98
  //# sourceMappingURL=tree-restore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tree-restore.d.ts","sourceRoot":"","sources":["../../src/commands/tree-restore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,oEAAoE;AACpE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC9B,0BAA0B;IAC1B,OAA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nB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qFAAqF;IACrF,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB;;;OAGG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACvB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,QAAQ,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,eAAe,CAAC,CAI1B;AAkGD;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,eAAe,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAIf;AA+BD,+CAA+C;AAC/C,MAAM,WAAW,gBAAgB;IAC/B,wFAAwF;IACxF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mFAAmF;IACnF,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * What a checkout or a stash apply must not overwrite, as git's unpack-trees checks it
3
+ * before writing anything: local changes (`verify_uptodate`), untracked files on a path or
4
+ * a leading component (`verify_absent`, `check_leading_path`), and untracked files in a
5
+ * directory a file replaces (`verify_clean_subdirectory`).
6
+ */
7
+ import { type ObjectId } from "@statewalker/vcs-core";
8
+ import type { Worktree, WorktreeModeTrust } from "@statewalker/vcs-working-tree";
9
+ /** An index or tree entry, with the index's stat where it has one. */
10
+ export interface CheckedEntry {
11
+ objectId: ObjectId;
12
+ mode: number;
13
+ size?: number;
14
+ mtime?: number;
15
+ ctime?: number;
16
+ }
17
+ /**
18
+ * Whether the worktree file at `path` no longer holds the index entry (git's
19
+ * `verify_uptodate`): changed content, type, or executable bit where the worktree shows it.
20
+ * A missing file is no local change.
21
+ */
22
+ export declare function worktreeDiffers(worktree: Worktree, path: string, entry: CheckedEntry, trust?: WorktreeModeTrust): Promise<boolean>;
23
+ /** What stands where an operation writes: untracked files, and directories with some. */
24
+ export interface InTheWay {
25
+ /** Untracked files or links on a written path, or on a leading component of one */
26
+ untracked: string[];
27
+ /**
28
+ * Directories a written file replaces that hold untracked files, or tracked files the
29
+ * operation does not remove (never replaced behind the index's back)
30
+ */
31
+ lostDirs: string[];
32
+ }
33
+ /**
34
+ * Finds what stands where `writes` (paths not in the index) are written, `removes` being
35
+ * the tracked paths the operation deletes first. Ignored files are expendable, as in git.
36
+ * With `ignoreCase`, a file that is one of `removes` in another case is no obstacle (a
37
+ * case-only rename on a case-folding worktree).
38
+ */
39
+ export declare function findInTheWay(worktree: Worktree, options: {
40
+ writes: string[];
41
+ removes: Set<string>;
42
+ index: Map<string, unknown>;
43
+ ignoreCase?: boolean;
44
+ }): Promise<InTheWay>;
45
+ /**
46
+ * Removes the directory at `dir` if it holds nothing at all, as git's `rmdir`: never a
47
+ * directory with a file, link, subdirectory, nested repository (`.git`) or FIFO in it, and
48
+ * never recursively. Returns whether it was removed.
49
+ */
50
+ export declare function removeDirectoryIfEmpty(worktree: Worktree, dir: string): Promise<boolean>;
51
+ /**
52
+ * Removes the directories a removal left empty, bottom-up to the worktree root, as git's
53
+ * `schedule_dir_for_removal`: each only if it is truly empty, stopping at the first that is
54
+ * not (a nested repository, an ignored or untracked file, a FIFO keeps its directory).
55
+ */
56
+ export declare function pruneEmptyParents(worktree: Worktree, path: string): Promise<void>;
57
+ /** git's refusal messages (unpack-trees), for `checkout` or `merge` (stash apply). */
58
+ export declare function overwriteMessage(action: "checkout" | "merge", found: {
59
+ local?: string[];
60
+ lostDirs?: string[];
61
+ untracked?: string[];
62
+ untrackedRemoved?: string[];
63
+ }): string | undefined;
64
+ //# sourceMappingURL=worktree-overwrite-checks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worktree-overwrite-checks.d.ts","sourceRoot":"","sources":["../../src/commands/worktree-overwrite-checks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEjF,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,YAAY,EACnB,KAAK,CAAC,EAAE,iBAAiB,GACxB,OAAO,CAAC,OAAO,CAAC,CA2BlB;AAED,yFAAyF;AACzF,MAAM,WAAW,QAAQ;IACvB,mFAAmF;IACnF,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GACA,OAAO,CAAC,QAAQ,CAAC,CA2CnB;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAAC,QAAQ,E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