es-git 0.4.0-next.135 → 0.4.0-next.136

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 (3) hide show
  1. package/index.d.ts +461 -0
  2. package/index.js +4 -1
  3. package/package.json +11 -11
package/index.d.ts CHANGED
@@ -1730,6 +1730,84 @@ export interface SignaturePayload {
1730
1730
  email: string
1731
1731
  timeOptions?: SignatureTimeOptions
1732
1732
  }
1733
+ /**
1734
+ * Options for saving a stash.
1735
+ *
1736
+ * All fields are optional. If not provided, sensible defaults will be used.
1737
+ *
1738
+ * @example
1739
+ * ```ts
1740
+ * import { openRepository } from 'es-git';
1741
+ *
1742
+ * const repo = await openRepository('./path/to/repo');
1743
+ *
1744
+ * // Basic usage
1745
+ * repo.stashSave({
1746
+ * stasher: { name: 'Seokju Na', email: 'seokju.me@toss.im' }
1747
+ * });
1748
+ *
1749
+ * // With options
1750
+ * repo.stashSave({
1751
+ * stasher: { name: 'Seokju Na', email: 'seokju.me@toss.im' },
1752
+ * message: 'WIP: feature implementation',
1753
+ * includeUntracked: true
1754
+ * });
1755
+ * ```
1756
+ */
1757
+ export interface StashSaveOptions {
1758
+ /**
1759
+ * The identity of the person performing the stashing.
1760
+ * If not provided, uses the repository's default signature.
1761
+ */
1762
+ stasher?: SignaturePayload
1763
+ /**
1764
+ * Description along with the stashed state.
1765
+ * If not provided, a default message will be generated.
1766
+ */
1767
+ message?: string
1768
+ /**
1769
+ * Whether to stash untracked files.
1770
+ * Default: false
1771
+ */
1772
+ includeUntracked?: boolean
1773
+ /**
1774
+ * Whether to stash ignored files.
1775
+ * Default: false
1776
+ */
1777
+ includeIgnored?: boolean
1778
+ /**
1779
+ * Whether to retain the index after stashing.
1780
+ * If true, staged changes remain in the index after stashing.
1781
+ * Default: false
1782
+ */
1783
+ keepIndex?: boolean
1784
+ }
1785
+ /**
1786
+ * Options for applying a stash.
1787
+ *
1788
+ * Controls how a stash is applied to the working directory.
1789
+ *
1790
+ * @example
1791
+ * ```ts
1792
+ * import { openRepository } from 'es-git';
1793
+ *
1794
+ * const repo = await openRepository('./path/to/repo');
1795
+ *
1796
+ * // Default apply
1797
+ * repo.stashApply(0);
1798
+ *
1799
+ * // With options
1800
+ * repo.stashApply(0, { reinstantiateIndex: true });
1801
+ * ```
1802
+ */
1803
+ export interface StashApplyOptions {
1804
+ /**
1805
+ * Whether to reinstall the index from the stash.
1806
+ * If true, the index state recorded in the stash is also restored.
1807
+ * Default: false
1808
+ */
1809
+ reinstantiateIndex?: boolean
1810
+ }
1733
1811
  export interface Status {
1734
1812
  current: boolean
1735
1813
  indexNew: boolean
@@ -5286,6 +5364,175 @@ export declare class Repository {
5286
5364
  * @returns Revwalk to traverse the commit graph in this repository.
5287
5365
  */
5288
5366
  revwalk(): Revwalk
5367
+ /**
5368
+ * Save the local modifications to a new stash.
5369
+ *
5370
+ * This method saves your current working directory and index state to a new stash entry,
5371
+ * allowing you to temporarily store changes and work on something else. The working directory
5372
+ * is reverted to match the HEAD commit after stashing.
5373
+ *
5374
+ * @category Repository/Methods
5375
+ * @signature
5376
+ * ```ts
5377
+ * class Repository {
5378
+ * stashSave(options?: StashSaveOptions): string;
5379
+ * }
5380
+ * ```
5381
+ *
5382
+ * @param {StashSaveOptions} [options] - Options for saving the stash.
5383
+ * @returns {string} The object ID (40-character SHA1) of the commit containing the stashed state.
5384
+ * @throws {Error} If there are no local changes to stash or if the stash operation fails.
5385
+ *
5386
+ * @example
5387
+ * ```ts
5388
+ * import { openRepository } from 'es-git';
5389
+ *
5390
+ * const repo = await openRepository('./path/to/repo');
5391
+ *
5392
+ * // Simple stash
5393
+ * const stashId = repo.stashSave({
5394
+ * stasher: { name: 'Seokju Na', email: 'seokju.me@toss.im' },
5395
+ * message: 'WIP: implementing new feature'
5396
+ * });
5397
+ *
5398
+ * // Stash including untracked files
5399
+ * repo.stashSave({
5400
+ * stasher: { name: 'Seokju Na', email: 'seokju.me@toss.im' },
5401
+ * includeUntracked: true
5402
+ * });
5403
+ * ```
5404
+ */
5405
+ stashSave(options?: StashSaveOptions | undefined | null): string
5406
+ /**
5407
+ * Apply a single stashed state from the stash list.
5408
+ *
5409
+ * This method applies the changes from a stash entry to your working directory.
5410
+ * Unlike `stashPop`, this does not remove the stash from the list after applying.
5411
+ * Conflicts may occur if the stashed changes conflict with the current working directory.
5412
+ *
5413
+ * @category Repository/Methods
5414
+ * @signature
5415
+ * ```ts
5416
+ * class Repository {
5417
+ * stashApply(index: number, options?: StashApplyOptions): void;
5418
+ * }
5419
+ * ```
5420
+ *
5421
+ * @param {number} index - The index of the stash to apply (0 is the most recent).
5422
+ * @param {StashApplyOptions} [options] - Options for applying the stash.
5423
+ * @throws {Error} If the stash index is invalid or if there are conflicts during application.
5424
+ *
5425
+ * @example
5426
+ * ```ts
5427
+ * import { openRepository } from 'es-git';
5428
+ *
5429
+ * const repo = await openRepository('./path/to/repo');
5430
+ *
5431
+ * // Apply the most recent stash
5432
+ * repo.stashApply(0);
5433
+ *
5434
+ * // Apply with options
5435
+ * repo.stashApply(0, { reinstantiateIndex: true });
5436
+ * ```
5437
+ */
5438
+ stashApply(index: number, options?: StashApplyOptions | undefined | null): void
5439
+ /**
5440
+ * Remove a single stashed state from the stash list.
5441
+ *
5442
+ * This permanently deletes a stash entry. The stash is removed from the list and
5443
+ * cannot be recovered. All subsequent stashes will be reindexed (e.g., stash@{2}
5444
+ * becomes stash@{1} after dropping stash@{1}).
5445
+ *
5446
+ * @category Repository/Methods
5447
+ * @signature
5448
+ * ```ts
5449
+ * class Repository {
5450
+ * stashDrop(index: number): void;
5451
+ * }
5452
+ * ```
5453
+ *
5454
+ * @param {number} index - The index of the stash to drop (0 is the most recent).
5455
+ * @throws {Error} If the stash index is invalid.
5456
+ *
5457
+ * @example
5458
+ * ```ts
5459
+ * import { openRepository } from 'es-git';
5460
+ *
5461
+ * const repo = await openRepository('./path/to/repo');
5462
+ *
5463
+ * // Drop the most recent stash
5464
+ * repo.stashDrop(0);
5465
+ *
5466
+ * // Drop the third stash
5467
+ * repo.stashDrop(2);
5468
+ * ```
5469
+ */
5470
+ stashDrop(index: number): void
5471
+ /**
5472
+ * Apply a single stashed state from the stash list and remove it from the list if successful.
5473
+ *
5474
+ * This method combines `stashApply` and `stashDrop` into a single operation. It applies
5475
+ * the stash to your working directory and, if successful, removes it from the stash list.
5476
+ * If the application fails (e.g., due to conflicts), the stash remains in the list.
5477
+ *
5478
+ * @category Repository/Methods
5479
+ * @signature
5480
+ * ```ts
5481
+ * class Repository {
5482
+ * stashPop(index: number, options?: StashApplyOptions): void;
5483
+ * }
5484
+ * ```
5485
+ *
5486
+ * @param {number} index - The index of the stash to pop (0 is the most recent).
5487
+ * @param {StashApplyOptions} [options] - Options for applying the stash.
5488
+ * @throws {Error} If the stash index is invalid or if there are conflicts during application.
5489
+ *
5490
+ * @example
5491
+ * ```ts
5492
+ * import { openRepository } from 'es-git';
5493
+ *
5494
+ * const repo = await openRepository('./path/to/repo');
5495
+ *
5496
+ * // Pop the most recent stash
5497
+ * repo.stashPop(0);
5498
+ *
5499
+ * // Pop with options
5500
+ * repo.stashPop(0, { reinstantiateIndex: true });
5501
+ * ```
5502
+ */
5503
+ stashPop(index: number, options?: StashApplyOptions | undefined | null): void
5504
+ /**
5505
+ * Get the list of stash states in the repository.
5506
+ *
5507
+ * Returns a StashList object that provides access to all stashes in the repository.
5508
+ * The list is ordered with the most recent stash at index 0.
5509
+ *
5510
+ * @category Repository/Methods
5511
+ * @signature
5512
+ * ```ts
5513
+ * class Repository {
5514
+ * stashList(): StashList;
5515
+ * }
5516
+ * ```
5517
+ *
5518
+ * @returns {StashList} A container providing access to all stash entries in the repository.
5519
+ *
5520
+ * @example
5521
+ * ```ts
5522
+ * import { openRepository } from 'es-git';
5523
+ *
5524
+ * const repo = await openRepository('./path/to/repo');
5525
+ * const stashList = repo.stashList();
5526
+ *
5527
+ * if (!stashList.isEmpty()) {
5528
+ * console.log(`Found ${stashList.len()} stashes`);
5529
+ * for (const stash of stashList.iter()) {
5530
+ * console.log(`${stash.index()}: ${stash.message()}`);
5531
+ * }
5532
+ * }
5533
+ * ```
5534
+ */
5535
+ stashList(): StashList
5289
5536
  /**
5290
5537
  * Test if the ignore rules apply to a given file.
5291
5538
  *
@@ -5833,6 +6080,220 @@ export declare class Revwalk {
5833
6080
  */
5834
6081
  hideRef(reference: string): this
5835
6082
  }
6083
+ /**
6084
+ * A class to represent a git stash entry.
6085
+ *
6086
+ * A stash entry represents a snapshot of the working directory and index that has been saved
6087
+ * temporarily. Each stash entry has an index (position in the stash stack), an ID (commit SHA),
6088
+ * and an optional message describing the changes.
6089
+ */
6090
+ export declare class StashEntry {
6091
+ /**
6092
+ * Get the index of this stash entry.
6093
+ *
6094
+ * The index represents the position of this stash in the stash stack, where 0 is the most recent stash.
6095
+ *
6096
+ * @category Stash/Methods
6097
+ * @signature
6098
+ * ```ts
6099
+ * class StashEntry {
6100
+ * index(): number;
6101
+ * }
6102
+ * ```
6103
+ *
6104
+ * @returns {number} Index of this stash entry (0-based, with 0 being the most recent).
6105
+ *
6106
+ * @example
6107
+ * ```ts
6108
+ * import { openRepository } from 'es-git';
6109
+ *
6110
+ * const repo = await openRepository('./path/to/repo');
6111
+ * const stashList = repo.stashList();
6112
+ * const stash = stashList.get(0);
6113
+ * console.log(stash?.index()); // 0
6114
+ * ```
6115
+ */
6116
+ index(): number
6117
+ /**
6118
+ * Get the id (SHA1) of this stash entry.
6119
+ *
6120
+ * Each stash is stored as a commit object, and this returns the commit SHA.
6121
+ *
6122
+ * @category Stash/Methods
6123
+ * @signature
6124
+ * ```ts
6125
+ * class StashEntry {
6126
+ * id(): string;
6127
+ * }
6128
+ * ```
6129
+ *
6130
+ * @returns {string} The 40-character hexadecimal SHA1 hash of the stash commit.
6131
+ *
6132
+ * @example
6133
+ * ```ts
6134
+ * import { openRepository } from 'es-git';
6135
+ *
6136
+ * const repo = await openRepository('./path/to/repo');
6137
+ * const stashList = repo.stashList();
6138
+ * const stash = stashList.get(0);
6139
+ * console.log(stash?.id()); // e.g., "a1b2c3d4e5f6..."
6140
+ * ```
6141
+ */
6142
+ id(): string
6143
+ /**
6144
+ * Get the message of this stash entry.
6145
+ *
6146
+ * Returns the message associated with the stash when it was created. If no custom message
6147
+ * was provided, it returns the default message generated by Git.
6148
+ *
6149
+ * @category Stash/Methods
6150
+ * @signature
6151
+ * ```ts
6152
+ * class StashEntry {
6153
+ * message(): string | null;
6154
+ * }
6155
+ * ```
6156
+ *
6157
+ * @returns {string | null} The stash message, or null if not available.
6158
+ *
6159
+ * @example
6160
+ * ```ts
6161
+ * import { openRepository } from 'es-git';
6162
+ *
6163
+ * const repo = await openRepository('./path/to/repo');
6164
+ * const stashList = repo.stashList();
6165
+ * const stash = stashList.get(0);
6166
+ * console.log(stash?.message()); // e.g., "WIP on main: abc1234 fix: typo"
6167
+ * ```
6168
+ */
6169
+ message(): string | null
6170
+ }
6171
+ /**
6172
+ * A container for a list of stash entries about a repository.
6173
+ *
6174
+ * The stash list provides access to all stashes in the repository. Stashes are indexed
6175
+ * from 0 (most recent) to n-1 (oldest). This class provides methods to access individual
6176
+ * stashes, check the count, and iterate over all stashes.
6177
+ *
6178
+ * @example
6179
+ * ```ts
6180
+ * import { openRepository } from 'es-git';
6181
+ *
6182
+ * const repo = await openRepository('./path/to/repo');
6183
+ * const stashList = repo.stashList();
6184
+ * console.log(`Total stashes: ${stashList.len()}`);
6185
+ *
6186
+ * // Iterate over all stashes
6187
+ * for (const stash of stashList.iter()) {
6188
+ * console.log(`${stash.index()}: ${stash.message()}`);
6189
+ * }
6190
+ * ```
6191
+ */
6192
+ export declare class StashList {
6193
+ /**
6194
+ * Gets a stash entry from this list at the specified index.
6195
+ *
6196
+ * @category Stash/Methods
6197
+ * @signature
6198
+ * ```ts
6199
+ * class StashList {
6200
+ * get(index: number): StashEntry | null;
6201
+ * }
6202
+ * ```
6203
+ *
6204
+ * @param {number} index - Index of the stash entry to get (0-based, where 0 is the most recent).
6205
+ * @returns {StashEntry | null} A stash entry from this list at the specified index, or `null` if the index is out of bounds.
6206
+ *
6207
+ * @example
6208
+ * ```ts
6209
+ * import { openRepository } from 'es-git';
6210
+ *
6211
+ * const repo = await openRepository('./path/to/repo');
6212
+ * const stashList = repo.stashList();
6213
+ *
6214
+ * // Get the most recent stash
6215
+ * const stash = stashList.get(0);
6216
+ * if (stash) {
6217
+ * console.log(stash.message());
6218
+ * }
6219
+ * ```
6220
+ */
6221
+ get(index: number): StashEntry | null
6222
+ /**
6223
+ * Gets the count of stash entries in this list.
6224
+ *
6225
+ * @category Stash/Methods
6226
+ * @signature
6227
+ * ```ts
6228
+ * class StashList {
6229
+ * len(): number;
6230
+ * }
6231
+ * ```
6232
+ *
6233
+ * @returns If there are no stashes in the repository, this should return 0.
6234
+ */
6235
+ len(): number
6236
+ /**
6237
+ * Check if the stash list is empty.
6238
+ *
6239
+ * @category Stash/Methods
6240
+ * @signature
6241
+ * ```ts
6242
+ * class StashList {
6243
+ * isEmpty(): boolean;
6244
+ * }
6245
+ * ```
6246
+ *
6247
+ * @returns {boolean} Returns `true` if there are no stash entries in this repository.
6248
+ *
6249
+ * @example
6250
+ * ```ts
6251
+ * import { openRepository } from 'es-git';
6252
+ *
6253
+ * const repo = await openRepository('./path/to/repo');
6254
+ * const stashList = repo.stashList();
6255
+ *
6256
+ * if (stashList.isEmpty()) {
6257
+ * console.log('No stashes found');
6258
+ * } else {
6259
+ * console.log(`Found ${stashList.len()} stashes`);
6260
+ * }
6261
+ * ```
6262
+ */
6263
+ isEmpty(): boolean
6264
+ /**
6265
+ * Returns an iterator over the stash entries in this list.
6266
+ *
6267
+ * The iterator yields stash entries in order from newest (index 0) to oldest.
6268
+ *
6269
+ * @category Stash/Methods
6270
+ * @signature
6271
+ * ```ts
6272
+ * class StashList {
6273
+ * iter(): StashListIter;
6274
+ * }
6275
+ * ```
6276
+ *
6277
+ * @returns {StashListIter} An iterator that yields StashEntry objects.
6278
+ *
6279
+ * @example
6280
+ * ```ts
6281
+ * import { openRepository } from 'es-git';
6282
+ *
6283
+ * const repo = await openRepository('./path/to/repo');
6284
+ * const stashList = repo.stashList();
6285
+ *
6286
+ * // Iterate over stashes
6287
+ * for (const stash of stashList.iter()) {
6288
+ * console.log(`${stash.index()}: ${stash.message()}`);
6289
+ * }
6290
+ * ```
6291
+ */
6292
+ iter(): StashListIter
6293
+ }
6294
+ export declare class StashListIter {
6295
+ [Symbol.iterator](): Iterator<StashEntry, void, void>
6296
+ }
5836
6297
  /**
5837
6298
  * A container for a list of status information about a repository.
5838
6299
  *
package/index.js CHANGED
@@ -310,7 +310,7 @@ if (!nativeBinding) {
310
310
  throw new Error(`Failed to load native binding`)
311
311
  }
312
312
 
313
- const { AnnotatedCommit, Blame, BlameHunks, BlameHunksByLine, Blob, isValidBranchName, Branch, Branches, BranchType, Commit, ConfigLevel, ConfigEntries, Config, openConfig, openDefaultConfig, findGlobalConfigPath, findSystemConfigPath, findXdgConfigPath, parseConfigBool, parseConfigI32, parseConfigI64, DiffFlags, diffFlagsContains, DeltaType, DiffFormat, Diff, DiffStats, Deltas, DiffDelta, FileMode, DiffFile, IndexStage, Index, IndexEntries, Mailmap, createMailmapFromBuffer, FileFavor, ObjectType, GitObject, isValidOid, isZeroOid, zeroOid, hashObjectOid, hashFileOid, ReferenceType, Reference, isValidReferenceName, ReferenceFormat, normalizeReferenceName, Direction, CredentialType, FetchPrune, AutotagOption, RemoteRedirect, Remote, RepositoryState, RepositoryInitMode, Repository, initRepository, openRepository, discoverRepository, cloneRepository, RevparseMode, revparseModeContains, RevwalkSort, Revwalk, createSignature, StatusShow, Statuses, StatusesIter, StatusEntry, isValidTagName, Tag, TreeWalkMode, Tree, TreeIter, TreeEntry } = nativeBinding
313
+ const { AnnotatedCommit, Blame, BlameHunks, BlameHunksByLine, Blob, isValidBranchName, Branch, Branches, BranchType, Commit, ConfigLevel, ConfigEntries, Config, openConfig, openDefaultConfig, findGlobalConfigPath, findSystemConfigPath, findXdgConfigPath, parseConfigBool, parseConfigI32, parseConfigI64, DiffFlags, diffFlagsContains, DeltaType, DiffFormat, Diff, DiffStats, Deltas, DiffDelta, FileMode, DiffFile, IndexStage, Index, IndexEntries, Mailmap, createMailmapFromBuffer, FileFavor, ObjectType, GitObject, isValidOid, isZeroOid, zeroOid, hashObjectOid, hashFileOid, ReferenceType, Reference, isValidReferenceName, ReferenceFormat, normalizeReferenceName, Direction, CredentialType, FetchPrune, AutotagOption, RemoteRedirect, Remote, RepositoryState, RepositoryInitMode, Repository, initRepository, openRepository, discoverRepository, cloneRepository, RevparseMode, revparseModeContains, RevwalkSort, Revwalk, createSignature, StashEntry, StashList, StashListIter, StatusShow, Statuses, StatusesIter, StatusEntry, isValidTagName, Tag, TreeWalkMode, Tree, TreeIter, TreeEntry } = nativeBinding
314
314
 
315
315
  module.exports.AnnotatedCommit = AnnotatedCommit
316
316
  module.exports.Blame = Blame
@@ -379,6 +379,9 @@ module.exports.revparseModeContains = revparseModeContains
379
379
  module.exports.RevwalkSort = RevwalkSort
380
380
  module.exports.Revwalk = Revwalk
381
381
  module.exports.createSignature = createSignature
382
+ module.exports.StashEntry = StashEntry
383
+ module.exports.StashList = StashList
384
+ module.exports.StashListIter = StashListIter
382
385
  module.exports.StatusShow = StatusShow
383
386
  module.exports.Statuses = Statuses
384
387
  module.exports.StatusesIter = StatusesIter
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-git",
3
- "version": "0.4.0-next.135+be674ce",
3
+ "version": "0.4.0-next.136+f47e288",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [
@@ -57,15 +57,15 @@
57
57
  "vitest": "^3.0.5"
58
58
  },
59
59
  "optionalDependencies": {
60
- "es-git-darwin-x64": "0.4.0-next.135+be674ce",
61
- "es-git-darwin-arm64": "0.4.0-next.135+be674ce",
62
- "es-git-win32-x64-msvc": "0.4.0-next.135+be674ce",
63
- "es-git-win32-arm64-msvc": "0.4.0-next.135+be674ce",
64
- "es-git-linux-x64-gnu": "0.4.0-next.135+be674ce",
65
- "es-git-linux-x64-musl": "0.4.0-next.135+be674ce",
66
- "es-git-android-arm64": "0.4.0-next.135+be674ce",
67
- "es-git-linux-arm64-gnu": "0.4.0-next.135+be674ce",
68
- "es-git-linux-arm64-musl": "0.4.0-next.135+be674ce",
69
- "es-git-android-arm-eabi": "0.4.0-next.135+be674ce"
60
+ "es-git-darwin-x64": "0.4.0-next.136+f47e288",
61
+ "es-git-darwin-arm64": "0.4.0-next.136+f47e288",
62
+ "es-git-win32-x64-msvc": "0.4.0-next.136+f47e288",
63
+ "es-git-win32-arm64-msvc": "0.4.0-next.136+f47e288",
64
+ "es-git-linux-x64-gnu": "0.4.0-next.136+f47e288",
65
+ "es-git-linux-x64-musl": "0.4.0-next.136+f47e288",
66
+ "es-git-android-arm64": "0.4.0-next.136+f47e288",
67
+ "es-git-linux-arm64-gnu": "0.4.0-next.136+f47e288",
68
+ "es-git-linux-arm64-musl": "0.4.0-next.136+f47e288",
69
+ "es-git-android-arm-eabi": "0.4.0-next.136+f47e288"
70
70
  }
71
71
  }