isomorphic-git 1.37.2 → 1.37.4

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/README.md CHANGED
@@ -77,7 +77,10 @@ git.clone({ fs, http, dir, url: 'https://github.com/isomorphic-git/lightning-fs'
77
77
  ```
78
78
 
79
79
  If you're using `isomorphic-git` in the browser, you'll need something that emulates the `fs` API.
80
- The easiest to setup and most performant library is [LightningFS](https://github.com/isomorphic-git/lightning-fs) which is written and maintained by the same author and is part of the `isomorphic-git` suite.
80
+ The easiest to setup and most performant library is [LightningFS](https://github.com/isomorphic-git/lightning-fs) which is written and maintained by the same author and is part of the `isomorphic-git` suite.
81
+
82
+ ⚠️ LightningFS may apply file operations out of order, which can lead to repository corruption if the process crashes. You can mitigate this by calling `fs.flush()` after Git operations.
83
+
81
84
  If LightningFS doesn't meet your requirements, isomorphic-git should also work with [ZenFS](https://github.com/zen-fs/core) and [Filer](https://github.com/filerjs/filer).
82
85
  Instead of `isomorphic-git/http/node` this time import `isomorphic-git/http/web`:
83
86
 
package/index.cjs CHANGED
@@ -3273,12 +3273,13 @@ class GitPackIndex {
3273
3273
  0b1100000: 'ofs_delta',
3274
3274
  0b1110000: 'ref_delta',
3275
3275
  };
3276
- if (!this.pack) {
3276
+ const pack = await this.pack;
3277
+ if (!pack) {
3277
3278
  throw new InternalError(
3278
- 'Tried to read from a GitPackIndex with no packfile loaded into memory'
3279
+ 'Could not read packfile data. The packfile may be missing, corrupted, or too large to read into memory.'
3279
3280
  )
3280
3281
  }
3281
- const raw = (await this.pack).slice(start);
3282
+ const raw = pack.slice(start);
3282
3283
  const reader = new BufferCursor(raw);
3283
3284
  const byte = reader.readUInt8();
3284
3285
  // Object type is encoded in bits 654
@@ -3390,12 +3391,18 @@ async function readObjectPacked({
3390
3391
  if (p.error) throw new InternalError(p.error)
3391
3392
  // If the packfile DOES have the oid we're looking for...
3392
3393
  if (p.offsets.has(oid)) {
3393
- // Get the resolved git object from the packfile
3394
+ // Derive the .pack path from the .idx path
3395
+ const packFile = indexFile.replace(/idx$/, 'pack');
3394
3396
  if (!p.pack) {
3395
- const packFile = indexFile.replace(/idx$/, 'pack');
3396
3397
  p.pack = fs.read(packFile);
3397
3398
  }
3398
3399
  const pack = await p.pack;
3400
+ if (!pack) {
3401
+ p.pack = null;
3402
+ throw new InternalError(
3403
+ `Could not read packfile at ${packFile}. The file may be missing, corrupted, or too large to read into memory.`
3404
+ )
3405
+ }
3399
3406
 
3400
3407
  // === Packfile Integrity Verification ===
3401
3408
  // Performance optimization: use _checksumVerified flag to verify only once per packfile
@@ -5201,7 +5208,7 @@ function assertParameter(name, value) {
5201
5208
  /**
5202
5209
  * discoverGitdir
5203
5210
  *
5204
- * When processing git commands on a submodule determine
5211
+ * When processing git commands on a submodule or worktree, determine
5205
5212
  * the actual git directory based on the contents of the .git file.
5206
5213
  *
5207
5214
  * Otherwise (if sent a directory) return that directory as-is.
@@ -5218,6 +5225,11 @@ function assertParameter(name, value) {
5218
5225
  *
5219
5226
  */
5220
5227
 
5228
+ // Check if a path is absolute (Unix / or Windows drive letter like C:\ or C:/)
5229
+ function isAbsolute(filepath) {
5230
+ return filepath.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(filepath)
5231
+ }
5232
+
5221
5233
  async function discoverGitdir({ fsp, dotgit }) {
5222
5234
  assertParameter('fsp', fsp);
5223
5235
  assertParameter('dotgit', dotgit);
@@ -5232,6 +5244,10 @@ async function discoverGitdir({ fsp, dotgit }) {
5232
5244
  ._readFile(dotgit, 'utf8')
5233
5245
  .then(contents => contents.trimRight().substr(8))
5234
5246
  .then(submoduleGitdir => {
5247
+ // Worktrees use absolute gitdir paths; submodules use relative ones.
5248
+ if (isAbsolute(submoduleGitdir)) {
5249
+ return submoduleGitdir
5250
+ }
5235
5251
  const gitdir = join(dirname(dotgit), submoduleGitdir);
5236
5252
  return gitdir
5237
5253
  })
@@ -9295,8 +9311,8 @@ function filterCapabilities(server, client) {
9295
9311
 
9296
9312
  const pkg = {
9297
9313
  name: 'isomorphic-git',
9298
- version: '1.37.2',
9299
- agent: 'git/isomorphic-git@1.37.2',
9314
+ version: '1.37.4',
9315
+ agent: 'git/isomorphic-git@1.37.4',
9300
9316
  };
9301
9317
 
9302
9318
  class FIFO {
package/index.js CHANGED
@@ -3267,12 +3267,13 @@ class GitPackIndex {
3267
3267
  0b1100000: 'ofs_delta',
3268
3268
  0b1110000: 'ref_delta',
3269
3269
  };
3270
- if (!this.pack) {
3270
+ const pack = await this.pack;
3271
+ if (!pack) {
3271
3272
  throw new InternalError(
3272
- 'Tried to read from a GitPackIndex with no packfile loaded into memory'
3273
+ 'Could not read packfile data. The packfile may be missing, corrupted, or too large to read into memory.'
3273
3274
  )
3274
3275
  }
3275
- const raw = (await this.pack).slice(start);
3276
+ const raw = pack.slice(start);
3276
3277
  const reader = new BufferCursor(raw);
3277
3278
  const byte = reader.readUInt8();
3278
3279
  // Object type is encoded in bits 654
@@ -3384,12 +3385,18 @@ async function readObjectPacked({
3384
3385
  if (p.error) throw new InternalError(p.error)
3385
3386
  // If the packfile DOES have the oid we're looking for...
3386
3387
  if (p.offsets.has(oid)) {
3387
- // Get the resolved git object from the packfile
3388
+ // Derive the .pack path from the .idx path
3389
+ const packFile = indexFile.replace(/idx$/, 'pack');
3388
3390
  if (!p.pack) {
3389
- const packFile = indexFile.replace(/idx$/, 'pack');
3390
3391
  p.pack = fs.read(packFile);
3391
3392
  }
3392
3393
  const pack = await p.pack;
3394
+ if (!pack) {
3395
+ p.pack = null;
3396
+ throw new InternalError(
3397
+ `Could not read packfile at ${packFile}. The file may be missing, corrupted, or too large to read into memory.`
3398
+ )
3399
+ }
3393
3400
 
3394
3401
  // === Packfile Integrity Verification ===
3395
3402
  // Performance optimization: use _checksumVerified flag to verify only once per packfile
@@ -5195,7 +5202,7 @@ function assertParameter(name, value) {
5195
5202
  /**
5196
5203
  * discoverGitdir
5197
5204
  *
5198
- * When processing git commands on a submodule determine
5205
+ * When processing git commands on a submodule or worktree, determine
5199
5206
  * the actual git directory based on the contents of the .git file.
5200
5207
  *
5201
5208
  * Otherwise (if sent a directory) return that directory as-is.
@@ -5212,6 +5219,11 @@ function assertParameter(name, value) {
5212
5219
  *
5213
5220
  */
5214
5221
 
5222
+ // Check if a path is absolute (Unix / or Windows drive letter like C:\ or C:/)
5223
+ function isAbsolute(filepath) {
5224
+ return filepath.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(filepath)
5225
+ }
5226
+
5215
5227
  async function discoverGitdir({ fsp, dotgit }) {
5216
5228
  assertParameter('fsp', fsp);
5217
5229
  assertParameter('dotgit', dotgit);
@@ -5226,6 +5238,10 @@ async function discoverGitdir({ fsp, dotgit }) {
5226
5238
  ._readFile(dotgit, 'utf8')
5227
5239
  .then(contents => contents.trimRight().substr(8))
5228
5240
  .then(submoduleGitdir => {
5241
+ // Worktrees use absolute gitdir paths; submodules use relative ones.
5242
+ if (isAbsolute(submoduleGitdir)) {
5243
+ return submoduleGitdir
5244
+ }
5229
5245
  const gitdir = join(dirname(dotgit), submoduleGitdir);
5230
5246
  return gitdir
5231
5247
  })
@@ -9289,8 +9305,8 @@ function filterCapabilities(server, client) {
9289
9305
 
9290
9306
  const pkg = {
9291
9307
  name: 'isomorphic-git',
9292
- version: '1.37.2',
9293
- agent: 'git/isomorphic-git@1.37.2',
9308
+ version: '1.37.4',
9309
+ agent: 'git/isomorphic-git@1.37.4',
9294
9310
  };
9295
9311
 
9296
9312
  class FIFO {