@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
@@ -1,5 +1,6 @@
1
1
  import { GitCommand } from "../git-command.js";
2
2
  import { type RemoteConfig } from "../remote-config/index.js";
3
+ import { TransportCommand } from "../transport-command.js";
3
4
  export type { RemoteConfig };
4
5
  /**
5
6
  * Add a remote to the repository.
@@ -70,6 +71,14 @@ export declare class RemoteAddCommand extends GitCommand<RemoteConfig> {
70
71
  *
71
72
  * Based on JGit's RemoteRemoveCommand.
72
73
  *
74
+ * As git's builtin/remote.c `rm`: the branches whose upstream is the remote lose
75
+ * `branch.<b>.remote` and `branch.<b>.merge`, those pushing to it `branch.<b>.pushRemote`;
76
+ * the remote-tracking refs its fetch refspecs map to (under `refs/remotes/`, and not mapped
77
+ * by another remote too) are deleted with their reflogs, `refs/remotes/<name>/HEAD`
78
+ * included; `remote.pushDefault` naming it is unset; the `[remote "<name>"]` section goes.
79
+ * Local branches a refspec maps to are kept, and git's note naming them is in
80
+ * {@link getMessages}. A remote without a config section is refused, as git refuses it.
81
+ *
73
82
  * @example
74
83
  * ```typescript
75
84
  * await git.remoteRemove()
@@ -77,8 +86,9 @@ export declare class RemoteAddCommand extends GitCommand<RemoteConfig> {
77
86
  * .call();
78
87
  * ```
79
88
  */
80
- export declare class RemoteRemoveCommand extends GitCommand<RemoteConfig | undefined> {
89
+ export declare class RemoteRemoveCommand extends GitCommand<RemoteConfig> {
81
90
  private remoteName?;
91
+ private messages;
82
92
  /**
83
93
  * Set the remote name to remove.
84
94
  *
@@ -89,15 +99,61 @@ export declare class RemoteRemoveCommand extends GitCommand<RemoteConfig | undef
89
99
  * Get the remote name.
90
100
  */
91
101
  getRemoteName(): string | undefined;
102
+ /**
103
+ * What git prints after the removal (on stderr): the note on local branches a refspec
104
+ * maps to, which are not removed. Empty until {@link call} has run.
105
+ */
106
+ getMessages(): string[];
92
107
  /**
93
108
  * Execute the remote remove operation.
94
109
  *
95
- * Drops both halves of a remote: its config section and its tracking refs.
96
- * A remote that has only one of the two is still removable.
97
- *
98
- * @returns Removed remote config, or undefined if not found
110
+ * @returns Removed remote config
111
+ * @throws RemoteNotFoundError when the remote has no config section (git: "No such
112
+ * remote: '<name>'"); nothing is changed then
99
113
  */
100
- call(): Promise<RemoteConfig | undefined>;
114
+ call(): Promise<RemoteConfig>;
115
+ }
116
+ /** What {@link RemoteRenameCommand} did. */
117
+ export interface RemoteRenameResult {
118
+ /** The remote under its new name */
119
+ remote: RemoteConfig;
120
+ /**
121
+ * git's warnings: each fetch refspec that does not write under `refs/remotes/<old>/`
122
+ * is kept as it is ("Not updating non-default fetch refspec ...")
123
+ */
124
+ warnings: string[];
125
+ }
126
+ /**
127
+ * Rename a remote.
128
+ *
129
+ * Equivalent to `git remote rename <old> <new>`.
130
+ *
131
+ * As git's builtin/remote.c `mv`: the `[remote "<old>"]` section is renamed in place; each
132
+ * fetch refspec writing under `refs/remotes/<old>/` is rewritten to `refs/remotes/<new>/`,
133
+ * the others kept with git's warning; `branch.<b>.remote` and `branch.<b>.pushRemote`
134
+ * naming the remote are updated. When a refspec was rewritten, the refs under
135
+ * `refs/remotes/<old>/` move to `refs/remotes/<new>/` in one batch, each with its reflog
136
+ * and a `remote: renamed <old ref> to <new ref>` line, symbolic refs (`HEAD`) re-pointed
137
+ * at the moved refs, and `remote.pushDefault` follows the new name.
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const { remote, warnings } = await git.remoteRename().setOldName("origin").setNewName("upstream").call();
142
+ * ```
143
+ */
144
+ export declare class RemoteRenameCommand extends GitCommand<RemoteRenameResult> {
145
+ private oldName?;
146
+ private newName?;
147
+ /** Set the remote to rename. */
148
+ setOldName(name: string): this;
149
+ /** Set the remote's new name. */
150
+ setNewName(name: string): this;
151
+ /**
152
+ * @throws RemoteNotFoundError if the remote has no config section (git: "No such remote: '<old>'")
153
+ * @throws RemoteAlreadyExistsError if the new name is taken (git: "remote <new> already exists.")
154
+ * @throws InvalidArgumentError for an invalid new name (git: "'<new>' is not a valid remote name")
155
+ */
156
+ call(): Promise<RemoteRenameResult>;
101
157
  }
102
158
  /**
103
159
  * List remotes in the repository.
@@ -202,4 +258,57 @@ export declare class RemoteSetUrlCommand extends GitCommand<RemoteConfig> {
202
258
  /** Whether any `refs/remotes/<name>/*` ref exists. */
203
259
  private hasTrackingRefs;
204
260
  }
261
+ /**
262
+ * Point `refs/remotes/<name>/HEAD` at one of the remote's tracking branches, or delete it.
263
+ *
264
+ * Equivalent to `git remote set-head <name> <branch>`, `git remote set-head <name> -a`
265
+ * and `git remote set-head <name> -d`. The symbolic ref names the remote's default branch,
266
+ * so the remote name alone resolves to that branch (`git log origin`); `git clone` creates
267
+ * it. With {@link setAuto} the remote is asked which branch its HEAD is (its HEAD symref,
268
+ * or else the one branch at HEAD's commit). As git 2.48+, setting it on a remote whose
269
+ * `remote.<name>.followRemoteHEAD` is `always` turns that into `warn`, so the next fetch
270
+ * does not undo the choice.
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * await git.remoteSetHead().setRemoteName("origin").setBranch("develop").call();
275
+ * await git.remoteSetHead().setRemoteName("origin").setAuto(true).call();
276
+ * await git.remoteSetHead().setRemoteName("origin").setDelete(true).call();
277
+ * ```
278
+ */
279
+ export declare class RemoteSetHeadCommand extends TransportCommand<string | undefined> {
280
+ private remoteName?;
281
+ private branch?;
282
+ private deleteHead;
283
+ private auto;
284
+ private messages;
285
+ /** Set the remote whose HEAD is set. */
286
+ setRemoteName(name: string): this;
287
+ /** Set the branch (`develop`, or `refs/remotes/origin/develop`) HEAD names. */
288
+ setBranch(branch: string): this;
289
+ /** Delete `refs/remotes/<name>/HEAD` instead (`-d`). */
290
+ setDelete(deleteHead: boolean): this;
291
+ /**
292
+ * What `git remote set-head -a` prints (git 2.48+): `'origin/HEAD' is now created and
293
+ * points to 'main'`, `… is unchanged and points to …`, `… has changed from 'a' and now
294
+ * points to 'b'`, and so on. Empty without {@link setAuto}, or before {@link call}.
295
+ */
296
+ getMessages(): string[];
297
+ /** Ask the remote which branch its HEAD is, and point at that one (`-a`). */
298
+ setAuto(auto: boolean): this;
299
+ /**
300
+ * @returns The tracking ref HEAD now names, or undefined after a delete
301
+ * @throws RefNotFoundError if the tracking branch does not exist (git: "Not a valid ref: <ref>")
302
+ * @throws RefNotFoundError with `-a` when the remote HEAD names no branch (git: "Cannot
303
+ * determine remote HEAD"), or several ("Multiple remote HEAD branches. Please choose
304
+ * one explicitly with:" and a `git remote set-head` line for each)
305
+ */
306
+ call(): Promise<string | undefined>;
307
+ /**
308
+ * The remote's HEAD branches, as git's get_remote_ref_states (GET_HEAD_NAMES) finds them:
309
+ * every ref listed, then the branch HEAD's symref names, or else every branch at HEAD's
310
+ * commit (git's guess_remote_head with all matches).
311
+ */
312
+ private remoteHeads;
313
+ }
205
314
  //# sourceMappingURL=remote-command.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"remote-command.d.ts","sourceRoot":"","sources":["../../src/commands/remote-command.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAGL,KAAK,YAAY,EAElB,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,gBAAiB,SAAQ,UAAU,CAAC,YAAY,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAS;IACtB,OAAO,CAAC,GAAG,CAAC,CAAS;IACrB,OAAO,CAAC,YAAY,CAAC,CAAS;IAE9B;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAI1B;IAED;;OAEG;IACH,OAAO,IAAI,MAAM,GAAG,SAAS,CAE5B;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAIxB;IAED;;OAEG;IACH,MAAM,IAAI,MAAM,GAAG,SAAS,CAE3B;IAED;;;;;;OAMG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAIrC;IAED;;;;;OAKG;IACG,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC,CA8BlC;IAED,sDAAsD;YACxC,eAAe;CAM9B;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,mBAAoB,SAAQ,UAAU,CAAC,YAAY,GAAG,SAAS,CAAC;IAC3E,OAAO,CAAC,UAAU,CAAC,CAAS;IAE5B;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAIhC;IAED;;OAEG;IACH,aAAa,IAAI,MAAM,GAAG,SAAS,CAElC;IAED;;;;;;;OAOG;IACG,IAAI,IAAI,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAiC9C;CACF;AAED;;;;;;;;;;;;;;GAcG;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@@ -8,18 +8,16 @@ import type { StashApplyResult } from "../results/stash-result.js";
8
8
  *
9
9
  * Based on JGit's StashApplyCommand.
10
10
  *
11
- * The stashed changes are three-way merged against the current HEAD and the
12
- * result is written back: the merged working tree always, the merged index
13
- * when `restoreIndex` is set, and the stashed untracked files when
14
- * `restoreUntracked` is set. A conflict aborts before anything is written.
11
+ * As git's `stash apply`: the stash's change is merged into the current index (staged
12
+ * content and newly staged files take part), line by line where both sides changed a
13
+ * file; the result goes to the worktree, refused up front where it would overwrite local
14
+ * changes or untracked files. A content conflict is written with conflict markers and
15
+ * staged at stages 1-3 (status CONFLICTS). Without `setRestoreIndex(true)` (`--index`)
16
+ * the index keeps its entries plus the files the stash adds; the stashed untracked files
17
+ * are restored first, refused (nothing written) where a file stands in their way.
15
18
  *
16
- * Known limits, shared with `reset --hard`:
17
- * - a symlink in the merged tree is refused, because the `Worktree` interface
18
- * has no primitive to create one - writing the target as a regular file
19
- * would silently produce a working tree that does not match;
20
- * - a gitlink's contents are not restored, as in git;
21
- * - directories left empty by a deletion are not pruned;
22
- * - the restore is not atomic across the working tree and the index.
19
+ * Known limits: a gitlink's contents are not restored, as in git; the restore is not
20
+ * atomic across the working tree and the index.
23
21
  *
24
22
  * @example
25
23
  * ```typescript
@@ -56,9 +54,12 @@ export declare class StashApplyCommand extends GitCommand<StashApplyResult> {
56
54
  */
57
55
  getStashRef(): string | undefined;
58
56
  /**
59
- * Set whether to restore the index state.
57
+ * Set whether to restore the index state (`git stash apply --index`): the stash's index
58
+ * change is merged into the current index, and a conflict there refuses the apply
59
+ * ("conflicts in index. Try without --index."). Off by default, as in git: the index then
60
+ * keeps its entries, plus the files the stash adds.
60
61
  *
61
- * @param restoreIndex true to restore index (default)
62
+ * @param restoreIndex true to restore the index (default false)
62
63
  */
63
64
  setRestoreIndex(restoreIndex: boolean): this;
64
65
  /**
@@ -109,6 +110,27 @@ export declare class StashApplyCommand extends GitCommand<StashApplyResult> {
109
110
  * @returns Result of the apply operation
110
111
  */
111
112
  call(): Promise<StashApplyResult>;
113
+ private apply;
114
+ /** Writes a blob to the worktree (a link as a link where the worktree has them). */
115
+ private writeBlob;
116
+ /**
117
+ * git's ort merge of a stash: `base` (the stash's parent) to `ours` (the current index)
118
+ * and to `theirs` (the stash). Renames on one side (exact, then by similarity of at least
119
+ * {@link DEFAULT_RENAME_SCORE}%) carry the other side's change to the new path; files both
120
+ * sides changed are merged line by line (`Updated upstream` / `Stashed changes` markers);
121
+ * binary files, modify/delete and file/directory collisions are conflicts as in git.
122
+ */
123
+ private mergeFlat;
124
+ /**
125
+ * The paths `side` renamed from `base`: a deleted path paired with an added one holding
126
+ * the same blob, else (text files) the most similar added one scoring at least
127
+ * {@link DEFAULT_RENAME_SCORE}, as git's rename detection.
128
+ */
129
+ private detectRenames;
130
+ /** Stores a flat path map as a tree. */
131
+ private storeFlat;
132
+ /** The blobs, links and gitlinks of a tree, by path. */
133
+ private flatTree;
112
134
  /**
113
135
  * Plan the restore of the stash's untracked files, if there are any to restore.
114
136
  *
@@ -1 +1 @@
1
- {"version":3,"file":"stash-apply-command.d.ts","sourceRoot":"","sources":["../../src/commands/stash-apply-command.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AASnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,iBAAkB,SAAQ,UAAU,CAAC,gBAAgB,CAAC;IACjE,OAAO,CAAC,QAAQ,CAAC,CAAS;IAC1B,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,eAAe,CAAC,CAAuB;IAE/C;;;;;;OAMG;IACH,WAAW,C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B,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,eAAe,CAAC,CAAuB;IAE/C;;;;;;OAMG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAIlC;IAED;;OAEG;IACH,WAAW,IAAI,MAAM,GAAG,SAAS,CAEhC;IAED;;;;;;;OAOG;IACH,eAAe,CAAC,YAAY,EAAE,OAAO,GAAG,IAAI,CAI3C;IAED;;OAEG;IACH,eAAe,IAAI,OAAO,CAEzB;IAED;;;;OAIG;IACH,mBAAmB,CAAC,gBAAgB,EAAE,OAAO,GAAG,IAAI,CAInD;IAED;;OAEG;IACH,mBAAmB,IAAI,OAAO,CAE7B;IAED;;;;;;OAMG;IACH,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAI/C;IAED;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAIzC;IAED;;OAEG;IACH,WAAW,IAAI,aAAa,CAE3B;IAED;;;;OAIG;IACH,uBAAuB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAI5D;IAED;;OAEG;IACH,uBAAuB,IAAI,oBAAoB,GAAG,SAAS,CAE1D;IAED;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAatC;YAEa,KAAK;IAyQnB,oFAAoF;YACtE,SAAS;IAgBvB;;;;;;OAMG;YACW,SAAS;IAiMvB;;;;OAIG;YACW,aAAa;IAmD3B,wCAAwC;YAC1B,SAAS;IA2BvB,wDAAwD;YAC1C,QAAQ;IAatB;;;;;;;;;;;;;OAaG;YACW,oBAAoB;IAuDlC;;OAEG;YACW,eAAe;CA8C9B"}
@@ -1,10 +1,23 @@
1
- import type { ObjectId, PersonIdent } from "@statewalker/vcs-core";
1
+ import { type ObjectId, type PersonIdent } from "@statewalker/vcs-core";
2
2
  import { GitCommand } from "../git-command.js";
3
+ /**
4
+ * What the reset after a stash covers, as `git stash push` options.
5
+ */
6
+ export interface StashResetOptions {
7
+ /** `-u`: the untracked files were stashed and are removed (`git clean -fd`) */
8
+ includeUntracked?: boolean;
9
+ /** `-a`: the ignored files too (`git clean -fdx`) */
10
+ includeIgnored?: boolean;
11
+ /** `--keep-index`: the index tree is checked out again after the reset */
12
+ keepIndex?: boolean;
13
+ /** The stashed index tree (for `keepIndex`) */
14
+ indexTree?: ObjectId;
15
+ }
3
16
  /**
4
17
  * Interface for providing working tree and index state.
5
18
  *
6
- * The stash create operation requires access to the working directory
7
- * and index, which requires a WorkingCopy with worktree access.
19
+ * A working copy with an index and a worktree has a built-in provider
20
+ * ({@link WorkingCopyStashProvider}); set one only to stash something else.
8
21
  */
9
22
  export interface StashWorkingTreeProvider {
10
23
  /**
@@ -16,17 +29,23 @@ export interface StashWorkingTreeProvider {
16
29
  */
17
30
  getWorkingTree(): Promise<ObjectId>;
18
31
  /**
19
- * Get tree of untracked files (optional).
32
+ * Get tree of untracked files (optional); the ignored ones too with `includeIgnored`.
20
33
  */
21
- getUntrackedTree?(): Promise<ObjectId | undefined>;
34
+ getUntrackedTree?(options?: {
35
+ includeIgnored?: boolean;
36
+ }): Promise<ObjectId | undefined>;
22
37
  /**
23
- * Check if there are local changes to stash.
38
+ * Check if there are local changes to stash (untracked files count with
39
+ * `includeUntracked`, as `git stash -u`).
24
40
  */
25
- hasLocalChanges(): Promise<boolean>;
41
+ hasLocalChanges(options?: {
42
+ includeUntracked?: boolean;
43
+ includeIgnored?: boolean;
44
+ }): Promise<boolean>;
26
45
  /**
27
- * Reset working directory to HEAD after stash.
46
+ * Reset the working directory and index to HEAD after the stash, as `git stash push`.
28
47
  */
29
- resetHard(): Promise<void>;
48
+ resetHard(options?: StashResetOptions): Promise<void>;
30
49
  }
31
50
  /**
32
51
  * Command to create a stash commit.
@@ -35,22 +54,21 @@ export interface StashWorkingTreeProvider {
35
54
  *
36
55
  * Based on JGit's StashCreateCommand.
37
56
  *
38
- * Note: This command requires a working tree provider to access
39
- * uncommitted changes. Without a provider, it creates a stash
40
- * from the current HEAD state (no actual changes stashed).
57
+ * On a working copy with an index and a worktree it stashes as `git stash push` does:
58
+ * the index tree, the worktree tree (tracked files as they are on disk), with `-u` the
59
+ * untracked files, then resets the index and the worktree to HEAD (keeping untracked files
60
+ * unless they were stashed). A working copy without a worktree has nothing to stash:
61
+ * `call()` throws `StoreNotAvailableError` unless a provider is set.
41
62
  *
42
63
  * @example
43
64
  * ```typescript
44
- * // Create a stash with working tree provider
45
- * const stashCommit = await git.stashCreate()
46
- * .setWorkingTreeProvider(provider)
47
- * .setMessage("WIP: feature work")
48
- * .call();
65
+ * // git stash push -m "WIP: feature work"
66
+ * const stashCommit = await git.stashCreate().setMessage("WIP: feature work").call();
49
67
  *
50
- * // Create stash including untracked files
68
+ * // git stash push -u --keep-index
51
69
  * const stashCommit = await git.stashCreate()
52
- * .setWorkingTreeProvider(provider)
53
70
  * .setIncludeUntracked(true)
71
+ * .setKeepIndex(true)
54
72
  * .call();
55
73
  * ```
56
74
  */
@@ -59,6 +77,8 @@ export declare class StashCreateCommand extends GitCommand<ObjectId | undefined>
59
77
  private workingDirectoryMessage;
60
78
  private ref;
61
79
  private includeUntracked;
80
+ private includeIgnored;
81
+ private keepIndex;
62
82
  private workingTreeProvider?;
63
83
  private customMessage?;
64
84
  private author?;
@@ -78,14 +98,15 @@ export declare class StashCreateCommand extends GitCommand<ObjectId | undefined>
78
98
  */
79
99
  setWorkingDirectoryMessage(message: string): this;
80
100
  /**
81
- * Set a custom stash message.
101
+ * Set a custom stash message; the stash is then "On <branch>: <message>", as `git stash push -m`.
82
102
  *
83
103
  * @param message The custom message
84
104
  */
85
105
  setMessage(message: string): this;
86
106
  /**
87
107
  * Set the reference to update with the stashed commit ID.
88
- * If null, no reference is updated.
108
+ * If null, no reference is updated and the index and worktree are left as they are
109
+ * (`git stash create`).
89
110
  *
90
111
  * @param ref The ref name (default: refs/stash)
91
112
  */
@@ -100,6 +121,16 @@ export declare class StashCreateCommand extends GitCommand<ObjectId | undefined>
100
121
  * Get whether untracked files will be included.
101
122
  */
102
123
  getIncludeUntracked(): boolean;
124
+ /**
125
+ * Set whether to stash (and remove) the ignored files too, as `git stash --all`; implies
126
+ * untracked files.
127
+ */
128
+ setIncludeIgnored(includeIgnored: boolean): this;
129
+ /**
130
+ * Set whether the staged changes stay in the index and the worktree after the stash, as
131
+ * `git stash push --keep-index`.
132
+ */
133
+ setKeepIndex(keepIndex: boolean): this;
103
134
  /**
104
135
  * Set the working tree provider for accessing uncommitted changes.
105
136
  *
@@ -118,6 +149,9 @@ export declare class StashCreateCommand extends GitCommand<ObjectId | undefined>
118
149
  * @returns The stash commit ID, or undefined if nothing to stash
119
150
  */
120
151
  call(): Promise<ObjectId | undefined>;
152
+ private stash;
153
+ /** The built-in provider, for a working copy with an index and a worktree. */
154
+ private defaultProvider;
121
155
  /**
122
156
  * Format a message template.
123
157
  */
@@ -127,10 +161,10 @@ export declare class StashCreateCommand extends GitCommand<ObjectId | undefined>
127
161
  */
128
162
  private getCurrentBranchName;
129
163
  /**
130
- * Update the stash ref.
131
- *
132
- * Note: Reflog support is not part of the core Refs interface.
133
- * Stash history is tracked via parent commit chain instead.
164
+ * Update the stash ref as `git stash` does (update_ref with REF_FORCE_CREATE_REFLOG):
165
+ * a one-ref batch, under `<ref>.lock` on git files, that creates the ref's reflog and
166
+ * appends a line with the stash commit's message, so the stash is `stash@{0}` and the
167
+ * earlier ones move down the reflog.
134
168
  */
135
169
  private updateStashRef;
136
170
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stash-create-command.d.ts","sourceRoot":"","sources":["../../src/commands/stash-create-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGnE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAgC/C;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IAC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,OAAO,CAAC,aAAa;IASrB;;OAEG;YACW,oBAAoB;IASlC;;;;;OAKG;YACW,cAAc;CAgB7B"}
@@ -7,8 +7,9 @@ import { GitCommand } from "../git-command.js";
7
7
  *
8
8
  * Based on JGit's StashDropCommand.
9
9
  *
10
- * Note: Without reflog support in Refs, only the most recent stash (index 0)
11
- * can be dropped. Dropping by index > 0 requires reflog support.
10
+ * With a ref store that keeps reflogs (`getReflog`, `deleteReflogEntry`), any
11
+ * `stash@{n}` can be dropped, as git drops it; otherwise only the most recent
12
+ * stash (index 0).
12
13
  *
13
14
  * @example
14
15
  * ```typescript
@@ -59,5 +60,10 @@ export declare class StashDropCommand extends GitCommand<ObjectId | undefined> {
59
60
  * @returns The new stash ref after drop, or undefined if no stashes remain
60
61
  */
61
62
  call(): Promise<ObjectId | undefined>;
63
+ /**
64
+ * Delete `refs/stash` and its reflog if it still holds `expected` (git's clear_stash).
65
+ * With `ignoreMismatch`, a ref another writer moved meanwhile is left alone.
66
+ */
67
+ private deleteStashRef;
62
68
  }
63
69
  //# sourceMappingURL=stash-drop-command.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stash-drop-command.d.ts","sourceRoot":"","sources":["../../src/commands/stash-drop-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,gBAAiB,SAAQ,UAAU,CAAC,QAAQ,GAAG,SAAS,CAAC;IACpE,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,OAAO,CAAS;IAExB;;;;;;;;OAQG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAOlC;IAED;;OAEG;IACH,WAAW,IAAI,MAAM,CAEpB;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAIzB;IAED;;OAEG;IACH,MAAM,IAAI,OAAO,CAEhB;IAED;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CA6B1C;CACF"}
1
+ {"version":3,"file":"stash-drop-command.d.ts","sourceRoot":"","sources":["../../src/commands/stash-drop-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,gBAAiB,SAAQ,UAAU,CAAC,QAAQ,GAAG,SAAS,CAAC;IACpE,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,OAAO,CAAS;IAExB;;;;;;;;OAQG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAOlC;IAED;;OAEG;IACH,WAAW,IAAI,MAAM,CAEpB;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAIzB;IAED;;OAEG;IACH,MAAM,IAAI,OAAO,CAEhB;IAED;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CA0D1C;IAED;;;OAGG;YACW,cAAc;CAa7B"}
@@ -28,10 +28,8 @@ export declare class StashListCommand extends GitCommand<StashEntry[]> {
28
28
  */
29
29
  call(): Promise<StashEntry[]>;
30
30
  /**
31
- * Get stash entries.
32
- *
33
- * Note: Without reflog support in the core Refs interface,
34
- * this returns only the most recent stash (if any).
31
+ * Get stash entries: the reflog of `refs/stash`, newest first, as `git stash list`
32
+ * reads it. A store without reflogs gives only the current `refs/stash`.
35
33
  */
36
34
  private getStashReflog;
37
35
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"stash-list-command.d.ts","sourceRoot":"","sources":["../../src/commands/stash-list-command.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,SAAS,eAAe,CAAC;AAEtC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAiB,SAAQ,UAAU,CAAC,UAAU,EAAE,CAAC;IAC5D;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAwBlC;IAED;;;;;OAKG;YACW,cAAc;IAmB5B;;OAEG;YACW,eAAe;CA6B9B"}
1
+ {"version":3,"file":"stash-list-command.d.ts","sourceRoot":"","sources":["../../src/commands/stash-list-command.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,SAAS,eAAe,CAAC;AAEtC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAiB,SAAQ,UAAU,CAAC,UAAU,EAAE,CAAC;IAC5D;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAyBlC;IAED;;;OAGG;YACW,cAAc;IA0B5B;;OAEG;YACW,eAAe;CA6B9B"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * The built-in working-tree side of `git stash push`, for a working copy with an index and
3
+ * a worktree: the stash trees (index, worktree, untracked) as git builds them, and the
4
+ * reset that follows (`git clean -fd` with `-u`, `git reset --hard`, and with
5
+ * `--keep-index` the index tree checked out again).
6
+ *
7
+ * The index is compared with the worktree once per stash ({@link scanIndex}); the check for
8
+ * changes, the worktree tree and the reset all use that one comparison, and the entries it
9
+ * could only prove clean by hashing get their fresh stat in the index the reset writes.
10
+ */
11
+ import { type Blobs, type ObjectId } from "@statewalker/vcs-core";
12
+ import { type Staging, type WorkingCopy, type Worktree } from "@statewalker/vcs-working-tree";
13
+ import type { CommandTrees } from "../git-command.js";
14
+ import type { StashResetOptions, StashWorkingTreeProvider } from "./stash-create-command.js";
15
+ /** What {@link WorkingCopyStashProvider} works on. */
16
+ export interface WorkingCopyStashContext {
17
+ workingCopy: WorkingCopy;
18
+ trees: CommandTrees;
19
+ blobs: Blobs;
20
+ staging: Staging;
21
+ worktree: Worktree;
22
+ /** HEAD's tree (undefined before the first commit) */
23
+ headTree: () => Promise<ObjectId | undefined>;
24
+ }
25
+ /**
26
+ * The stash working-tree provider `git.stashCreate()` uses when none is set and the working
27
+ * copy has an index and a worktree. One instance serves one stash: it compares the index
28
+ * with the worktree once and reuses that comparison.
29
+ */
30
+ export declare class WorkingCopyStashProvider implements StashWorkingTreeProvider {
31
+ private readonly context;
32
+ private scanned?;
33
+ constructor(context: WorkingCopyStashContext);
34
+ private get source();
35
+ /** The index compared with the worktree, once. */
36
+ private scan;
37
+ getIndexTree(): Promise<ObjectId>;
38
+ getWorkingTree(): Promise<ObjectId>;
39
+ getUntrackedTree(options?: {
40
+ includeIgnored?: boolean;
41
+ }): Promise<ObjectId | undefined>;
42
+ hasLocalChanges(options?: {
43
+ includeUntracked?: boolean;
44
+ includeIgnored?: boolean;
45
+ }): Promise<boolean>;
46
+ /**
47
+ * As `git stash push` after saving: with `includeUntracked` the untracked files go
48
+ * (`git clean -fd`, `-x` too with `includeIgnored`), then the index and the worktree's
49
+ * tracked files are reset to HEAD (`git reset --hard`); with `keepIndex` the index tree is
50
+ * then checked out again (`git checkout --no-overlay <index tree> -- :/`). Only paths
51
+ * that differ are written; untracked files are kept unless removed by the clean.
52
+ */
53
+ resetHard(options?: StashResetOptions): Promise<void>;
54
+ /**
55
+ * `git clean -fd` (`-x` with `ignored`): the untracked files, then the untracked
56
+ * directories left empty, deepest first. A directory is removed only when nothing at all
57
+ * is in it, so a nested repository (and, without `-x`, an ignored file) keeps its own.
58
+ */
59
+ private clean;
60
+ /**
61
+ * The index and the worktree's tracked files made to match HEAD, as `git reset --hard`:
62
+ * every path whose index entry or worktree file differs is written (or removed) and staged
63
+ * with its fresh stat; paths that already match are not touched, and those the scan only
64
+ * proved clean by hashing get their fresh stat.
65
+ */
66
+ private resetToHead;
67
+ /** `git checkout --no-overlay <tree> -- :/` after the reset: index and worktree at `to`. */
68
+ private checkoutTree;
69
+ /** Writes (or removes) the `stale` paths of the worktree and the index to `treeId`. */
70
+ private write;
71
+ }
72
+ //# sourceMappingURL=stash-working-tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stash-working-tree.d.ts","sourceRoot":"","sources":["../../src/commands/stash-working-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,KAAK,KAAK,EAAY,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAWL,KAAK,OAAO,EAIZ,KAAK,WAAW,EAChB,KAAK,QAAQ,EACd,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAO7F,sDAAsD;AACtD,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,YAAY,CAAC;IACpB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;CAC/C;AAED;;;;GAIG;AACH,qBAAa,wBAAyB,YAAW,wBAAwB;IAG3D,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,OAAO,CAAC,CAAqB;IAErC,YAA6B,OAAO,EAAE,uBAAuB,EAAI;IAEjE,OAAO,KAAK,MAAM,GAGjB;IAED,kDAAkD;IAClD,OAAO,CAAC,IAAI;IAKZ,YAAY,IAAI,OAAO,CAAC,QAAQ,CAAC,CAEhC;IAEK,cAAc,IAAI,OAAO,CAAC,QAAQ,CAAC,CAExC;IAEK,gBAAgB,CAAC,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAE5F;IAEK,eAAe,CAAC,OAAO,CAAC,EAAE;QAC9B,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B,GAAG,OAAO,CAAC,OAAO,CAAC,CAWnB;IAED;;;;;;OAMG;IACG,SAAS,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ9D;IAED;;;;OAIG;YACW,KAAK;IAsBnB;;;;;OAKG;YACW,WAAW;IAczB,4FAA4F;YAC9E,YAAY;IAa1B,uFAAuF;YACzE,KAAK;CA+DpB"}
@@ -1,39 +1,36 @@
1
1
  import { GitCommand } from "../git-command.js";
2
2
  import { type Status } from "../results/status-result.js";
3
3
  /**
4
- * Shows the staging area status compared to HEAD.
4
+ * Shows the working tree status, as `git status`: the index against HEAD (staged changes),
5
+ * the worktree against the index (unstaged changes: modified, deleted, type changed),
6
+ * unmerged entries, untracked files and, on request, ignored ones.
5
7
  *
6
- * This is a simplified version for repositories without working trees,
7
- * focusing on staged changes and conflicts.
8
+ * Worktree files are compared with the index through the stat it recorded: a file whose
9
+ * size and modification time still match is not read, unless its entry is racily clean
10
+ * (modified at or after the index was written), which is re-hashed as git does. Links are
11
+ * compared as links (mode 120000), the executable bit only where `core.filemode` trusts it,
12
+ * and the ignore rules are read afresh for each status. Untracked files are listed one by
13
+ * one (`--untracked-files=all`). Renames are not detected.
8
14
  *
9
- * Equivalent to `git status` but only for staged changes.
15
+ * Without a worktree only the index is compared with HEAD.
10
16
  *
11
- * Based on JGit's StatusCommand (staged-only subset).
17
+ * Based on JGit's StatusCommand.
12
18
  *
13
19
  * @example
14
20
  * ```typescript
15
- * // Get repository status
16
21
  * const status = await git.status().call();
17
- *
18
- * // Check if clean
19
- * if (status.isClean()) {
20
- * console.log("Nothing to commit");
21
- * }
22
- *
23
- * // Check for changes
24
- * console.log("Added:", status.added);
25
- * console.log("Changed:", status.changed);
26
- * console.log("Removed:", status.removed);
27
- * console.log("Conflicting:", status.conflicting);
28
- *
29
- * // Filter by path
30
- * const subStatus = await git.status()
31
- * .addPath("src/")
32
- * .call();
22
+ * if (status.isClean()) console.log("nothing to commit, working tree clean");
23
+ * console.log("Staged:", status.added, status.changed, status.removed);
24
+ * console.log("Unstaged:", status.modified, status.missing);
25
+ * console.log("Untracked:", status.untracked);
26
+ * // the lines of `git status --porcelain`
27
+ * console.log(formatStatusPorcelain(status));
33
28
  * ```
34
29
  */
35
30
  export declare class StatusCommand extends GitCommand<Status> {
36
31
  private paths;
32
+ private showIgnored;
33
+ private showUntracked;
37
34
  /**
38
35
  * Add a path filter.
39
36
  *
@@ -42,7 +39,17 @@ export declare class StatusCommand extends GitCommand<Status> {
42
39
  * @param path Path prefix to filter by
43
40
  */
44
41
  addPath(path: string): this;
42
+ /**
43
+ * Whether to report the ignored files the index does not track (`--ignored`). Off by
44
+ * default.
45
+ */
46
+ setIgnored(ignored: boolean): this;
47
+ /**
48
+ * Whether to report untracked files (`--untracked-files=all`, the default, or `=no`).
49
+ */
50
+ setUntracked(untracked: boolean): this;
45
51
  call(): Promise<Status>;
52
+ private compute;
46
53
  /**
47
54
  * Check if a path matches the configured path filters.
48
55
  */
@@ -1 +1 @@
1
- {"version":3,"file":"status-command.d.ts","sourceRoot":"","sources":["../../src/commands/status-command.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,KAAK,MAAM,EAAc,MAAM,6BAA6B,CAAC;AAWtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,aAAc,SAAQ,UAAU,CAAC,MAAM,CAAC;IACnD,OAAO,CAAC,KAAK,CAAgB;IAE7B;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAI1B;IAEK,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAkE5B;IAED;;OAEG;IACH,OAAO,CAAC,WAAW;IAiBnB;;OAEG;YACW,kBAAkB;CAiBjC"}
1
+ {"version":3,"file":"status-command.d.ts","sourceRoot":"","sources":["../../src/commands/status-command.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EACL,KAAK,MAAM,EAKZ,MAAM,6BAA6B,CAAC;AAiBrC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,aAAc,SAAQ,UAAU,CAAC,MAAM,CAAC;IACnD,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,aAAa,CAAQ;IAE7B;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAI1B;IAED;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAIjC;IAED;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAIrC;IAEK,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAM5B;YAEa,OAAO;IAqIrB;;OAEG;IACH,OAAO,CAAC,WAAW;IAenB;;OAEG;YACW,kBAAkB;CAcjC"}