isomorphic-git 1.35.1 → 1.36.1

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/index.js CHANGED
@@ -4823,6 +4823,7 @@ function isPromiseFs(fs) {
4823
4823
 
4824
4824
  // List of commands all filesystems are expected to provide. `rm` is not
4825
4825
  // included since it may not exist and must be handled as a special case
4826
+ // Likewise with `cp`.
4826
4827
  const commands = [
4827
4828
  'readFile',
4828
4829
  'writeFile',
@@ -4847,12 +4848,14 @@ function bindFs(target, fs) {
4847
4848
  }
4848
4849
  }
4849
4850
 
4850
- // Handle the special case of `rm`
4851
+ // Handle the special cases of `rm` and `cp`
4851
4852
  if (isPromiseFs(fs)) {
4853
+ if (fs.cp) target._cp = fs.cp.bind(fs);
4852
4854
  if (fs.rm) target._rm = fs.rm.bind(fs);
4853
4855
  else if (fs.rmdir.length > 1) target._rm = fs.rmdir.bind(fs);
4854
4856
  else target._rm = rmRecursive.bind(null, target);
4855
4857
  } else {
4858
+ if (fs.cp) target._cp = pify(fs.cp.bind(fs));
4856
4859
  if (fs.rm) target._rm = pify(fs.rm.bind(fs));
4857
4860
  else if (fs.rmdir.length > 2) target._rm = pify(fs.rmdir.bind(fs));
4858
4861
  else target._rm = rmRecursive.bind(null, target);
@@ -5116,6 +5119,51 @@ function assertParameter(name, value) {
5116
5119
  }
5117
5120
  }
5118
5121
 
5122
+ /**
5123
+ * discoverGitdir
5124
+ *
5125
+ * When processing git commands on a submodule determine
5126
+ * the actual git directory based on the contents of the .git file.
5127
+ *
5128
+ * Otherwise (if sent a directory) return that directory as-is.
5129
+ *
5130
+ * A decision has to be made "in what layer will submodules be interpreted,
5131
+ * and then after that, where can the code can just stay exactly the same as before."
5132
+ * This implementation processes submodules in the front-end location of src/api/.
5133
+ * The backend of src/commands/ isn't modified. This keeps a clear division
5134
+ * of responsibilities and should be maintained.
5135
+ *
5136
+ * A consequence is that __tests__ must occasionally be informed
5137
+ * about submodules also, since those call src/commands/ directly.
5138
+ *
5139
+ *
5140
+ */
5141
+
5142
+ async function discoverGitdir({ fsp, dotgit }) {
5143
+ assertParameter('fsp', fsp);
5144
+ assertParameter('dotgit', dotgit);
5145
+
5146
+ const dotgitStat = await fsp
5147
+ ._stat(dotgit)
5148
+ .catch(() => ({ isFile: () => false, isDirectory: () => false }));
5149
+ if (dotgitStat.isDirectory()) {
5150
+ return dotgit
5151
+ } else if (dotgitStat.isFile()) {
5152
+ return fsp
5153
+ ._readFile(dotgit, 'utf8')
5154
+ .then(contents => contents.trimRight().substr(8))
5155
+ .then(submoduleGitdir => {
5156
+ const gitdir = join(dirname(dotgit), submoduleGitdir);
5157
+ return gitdir
5158
+ })
5159
+ } else {
5160
+ // Neither a file nor a directory. This correlates to a "git init" scenario where it's empty.
5161
+ // This is the expected result for normal repos, and indeterminate for submodules, but
5162
+ // would be unusual with submodules.
5163
+ return dotgit
5164
+ }
5165
+ }
5166
+
5119
5167
  // @ts-check
5120
5168
  /**
5121
5169
  *
@@ -5182,8 +5230,9 @@ async function abortMerge({
5182
5230
  const trees = [TREE({ ref: commit }), WORKDIR(), STAGE()];
5183
5231
  let unmergedPaths = [];
5184
5232
 
5233
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
5185
5234
  await GitIndexManager.acquire(
5186
- { fs, gitdir, cache },
5235
+ { fs, gitdir: updatedGitdir, cache },
5187
5236
  async function (index) {
5188
5237
  unmergedPaths = index.unmergedPaths;
5189
5238
  }
@@ -5193,7 +5242,7 @@ async function abortMerge({
5193
5242
  fs,
5194
5243
  cache,
5195
5244
  dir,
5196
- gitdir,
5245
+ gitdir: updatedGitdir,
5197
5246
  trees,
5198
5247
  map: async function (path, [head, workdir, index]) {
5199
5248
  const staged = !(await modified(workdir, index));
@@ -5218,7 +5267,7 @@ async function abortMerge({
5218
5267
  });
5219
5268
 
5220
5269
  await GitIndexManager.acquire(
5221
- { fs, gitdir, cache },
5270
+ { fs, gitdir: updatedGitdir, cache },
5222
5271
  async function (index) {
5223
5272
  // Reset paths in index and worktree, this can't be done in _walk because the
5224
5273
  // STAGE walker acquires its own index lock.
@@ -5431,20 +5480,24 @@ async function add({
5431
5480
  assertParameter('filepath', filepath);
5432
5481
 
5433
5482
  const fs = new FileSystem(_fs);
5434
- await GitIndexManager.acquire({ fs, gitdir, cache }, async index => {
5435
- const config = await GitConfigManager.get({ fs, gitdir });
5436
- const autocrlf = await config.get('core.autocrlf');
5437
- return addToIndex({
5438
- dir,
5439
- gitdir,
5440
- fs,
5441
- filepath,
5442
- index,
5443
- force,
5444
- parallel,
5445
- autocrlf,
5446
- })
5447
- });
5483
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
5484
+ await GitIndexManager.acquire(
5485
+ { fs, gitdir: updatedGitdir, cache },
5486
+ async index => {
5487
+ const config = await GitConfigManager.get({ fs, gitdir: updatedGitdir });
5488
+ const autocrlf = await config.get('core.autocrlf');
5489
+ return addToIndex({
5490
+ dir,
5491
+ gitdir: updatedGitdir,
5492
+ fs,
5493
+ filepath,
5494
+ index,
5495
+ force,
5496
+ parallel,
5497
+ autocrlf,
5498
+ })
5499
+ }
5500
+ );
5448
5501
  } catch (err) {
5449
5502
  err.caller = 'git.add';
5450
5503
  throw err
@@ -6203,11 +6256,12 @@ async function addNote({
6203
6256
  });
6204
6257
  if (!committer) throw new MissingNameError('committer')
6205
6258
 
6259
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
6206
6260
  return await _addNote({
6207
- fs: new FileSystem(fs),
6261
+ fs,
6208
6262
  cache,
6209
6263
  onSign,
6210
- gitdir,
6264
+ gitdir: updatedGitdir,
6211
6265
  ref,
6212
6266
  oid,
6213
6267
  note,
@@ -6313,9 +6367,11 @@ async function addRemote({
6313
6367
  assertParameter('gitdir', gitdir);
6314
6368
  assertParameter('remote', remote);
6315
6369
  assertParameter('url', url);
6370
+ const fsp = new FileSystem(fs);
6371
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
6316
6372
  return await _addRemote({
6317
- fs: new FileSystem(fs),
6318
- gitdir,
6373
+ fs: fsp,
6374
+ gitdir: updatedGitdir,
6319
6375
  remote,
6320
6376
  url,
6321
6377
  force,
@@ -6472,16 +6528,21 @@ async function annotatedTag({
6472
6528
  assertParameter('onSign', onSign);
6473
6529
  }
6474
6530
  const fs = new FileSystem(_fs);
6531
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
6475
6532
 
6476
6533
  // Fill in missing arguments with default values
6477
- const tagger = await normalizeAuthorObject({ fs, gitdir, author: _tagger });
6534
+ const tagger = await normalizeAuthorObject({
6535
+ fs,
6536
+ gitdir: updatedGitdir,
6537
+ author: _tagger,
6538
+ });
6478
6539
  if (!tagger) throw new MissingNameError('tagger')
6479
6540
 
6480
6541
  return await _annotatedTag({
6481
6542
  fs,
6482
6543
  cache,
6483
6544
  onSign,
6484
- gitdir,
6545
+ gitdir: updatedGitdir,
6485
6546
  ref,
6486
6547
  tagger,
6487
6548
  message,
@@ -6595,9 +6656,11 @@ async function branch({
6595
6656
  assertParameter('fs', fs);
6596
6657
  assertParameter('gitdir', gitdir);
6597
6658
  assertParameter('ref', ref);
6659
+ const fsp = new FileSystem(fs);
6660
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
6598
6661
  return await _branch({
6599
- fs: new FileSystem(fs),
6600
- gitdir,
6662
+ fs: fsp,
6663
+ gitdir: updatedGitdir,
6601
6664
  ref,
6602
6665
  object,
6603
6666
  checkout,
@@ -7430,13 +7493,15 @@ async function checkout({
7430
7493
  assertParameter('gitdir', gitdir);
7431
7494
 
7432
7495
  const ref = _ref || 'HEAD';
7496
+ const fsp = new FileSystem(fs);
7497
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
7433
7498
  return await _checkout({
7434
- fs: new FileSystem(fs),
7499
+ fs: fsp,
7435
7500
  cache,
7436
7501
  onProgress,
7437
7502
  onPostCheckout,
7438
7503
  dir,
7439
- gitdir,
7504
+ gitdir: updatedGitdir,
7440
7505
  remote,
7441
7506
  ref,
7442
7507
  filepaths,
@@ -8185,8 +8250,8 @@ function filterCapabilities(server, client) {
8185
8250
 
8186
8251
  const pkg = {
8187
8252
  name: 'isomorphic-git',
8188
- version: '1.35.1',
8189
- agent: 'git/isomorphic-git@1.35.1',
8253
+ version: '1.36.1',
8254
+ agent: 'git/isomorphic-git@1.36.1',
8190
8255
  };
8191
8256
 
8192
8257
  class FIFO {
@@ -9114,8 +9179,10 @@ async function clone({
9114
9179
  }
9115
9180
  assertParameter('url', url);
9116
9181
 
9182
+ const fsp = new FileSystem(fs);
9183
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
9117
9184
  return await _clone({
9118
- fs: new FileSystem(fs),
9185
+ fs: fsp,
9119
9186
  cache,
9120
9187
  http,
9121
9188
  onProgress,
@@ -9125,7 +9192,7 @@ async function clone({
9125
9192
  onAuthFailure,
9126
9193
  onPostCheckout,
9127
9194
  dir,
9128
- gitdir,
9195
+ gitdir: updatedGitdir,
9129
9196
  url,
9130
9197
  corsProxy,
9131
9198
  ref,
@@ -9217,12 +9284,13 @@ async function commit({
9217
9284
  assertParameter('onSign', onSign);
9218
9285
  }
9219
9286
  const fs = new FileSystem(_fs);
9287
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
9220
9288
 
9221
9289
  return await _commit({
9222
9290
  fs,
9223
9291
  cache,
9224
9292
  onSign,
9225
- gitdir,
9293
+ gitdir: updatedGitdir,
9226
9294
  message,
9227
9295
  author,
9228
9296
  committer,
@@ -9274,9 +9342,11 @@ async function currentBranch({
9274
9342
  try {
9275
9343
  assertParameter('fs', fs);
9276
9344
  assertParameter('gitdir', gitdir);
9345
+ const fsp = new FileSystem(fs);
9346
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
9277
9347
  return await _currentBranch({
9278
- fs: new FileSystem(fs),
9279
- gitdir,
9348
+ fs: fsp,
9349
+ gitdir: updatedGitdir,
9280
9350
  fullname,
9281
9351
  test,
9282
9352
  })
@@ -9350,9 +9420,11 @@ async function deleteBranch({
9350
9420
  try {
9351
9421
  assertParameter('fs', fs);
9352
9422
  assertParameter('ref', ref);
9423
+ const fsp = new FileSystem(fs);
9424
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
9353
9425
  return await _deleteBranch({
9354
- fs: new FileSystem(fs),
9355
- gitdir,
9426
+ fs: fsp,
9427
+ gitdir: updatedGitdir,
9356
9428
  ref,
9357
9429
  })
9358
9430
  } catch (err) {
@@ -9383,7 +9455,9 @@ async function deleteRef({ fs, dir, gitdir = join(dir, '.git'), ref }) {
9383
9455
  try {
9384
9456
  assertParameter('fs', fs);
9385
9457
  assertParameter('ref', ref);
9386
- await GitRefManager.deleteRef({ fs: new FileSystem(fs), gitdir, ref });
9458
+ const fsp = new FileSystem(fs);
9459
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
9460
+ await GitRefManager.deleteRef({ fs: fsp, gitdir: updatedGitdir, ref });
9387
9461
  } catch (err) {
9388
9462
  err.caller = 'git.deleteRef';
9389
9463
  throw err
@@ -9433,9 +9507,11 @@ async function deleteRemote({
9433
9507
  try {
9434
9508
  assertParameter('fs', fs);
9435
9509
  assertParameter('remote', remote);
9510
+ const fsp = new FileSystem(fs);
9511
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
9436
9512
  return await _deleteRemote({
9437
- fs: new FileSystem(fs),
9438
- gitdir,
9513
+ fs: fsp,
9514
+ gitdir: updatedGitdir,
9439
9515
  remote,
9440
9516
  })
9441
9517
  } catch (err) {
@@ -9488,9 +9564,11 @@ async function deleteTag({ fs, dir, gitdir = join(dir, '.git'), ref }) {
9488
9564
  try {
9489
9565
  assertParameter('fs', fs);
9490
9566
  assertParameter('ref', ref);
9567
+ const fsp = new FileSystem(fs);
9568
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
9491
9569
  return await _deleteTag({
9492
- fs: new FileSystem(fs),
9493
- gitdir,
9570
+ fs: fsp,
9571
+ gitdir: updatedGitdir,
9494
9572
  ref,
9495
9573
  })
9496
9574
  } catch (err) {
@@ -9594,10 +9672,12 @@ async function expandOid({
9594
9672
  assertParameter('fs', fs);
9595
9673
  assertParameter('gitdir', gitdir);
9596
9674
  assertParameter('oid', oid);
9675
+ const fsp = new FileSystem(fs);
9676
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
9597
9677
  return await _expandOid({
9598
- fs: new FileSystem(fs),
9678
+ fs: fsp,
9599
9679
  cache,
9600
- gitdir,
9680
+ gitdir: updatedGitdir,
9601
9681
  oid,
9602
9682
  })
9603
9683
  } catch (err) {
@@ -9629,9 +9709,11 @@ async function expandRef({ fs, dir, gitdir = join(dir, '.git'), ref }) {
9629
9709
  assertParameter('fs', fs);
9630
9710
  assertParameter('gitdir', gitdir);
9631
9711
  assertParameter('ref', ref);
9712
+ const fsp = new FileSystem(fs);
9713
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
9632
9714
  return await GitRefManager.expand({
9633
- fs: new FileSystem(fs),
9634
- gitdir,
9715
+ fs: fsp,
9716
+ gitdir: updatedGitdir,
9635
9717
  ref,
9636
9718
  })
9637
9719
  } catch (err) {
@@ -10508,8 +10590,10 @@ async function fastForward({
10508
10590
  timezoneOffset: 0,
10509
10591
  };
10510
10592
 
10593
+ const fsp = new FileSystem(fs);
10594
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
10511
10595
  return await _pull({
10512
- fs: new FileSystem(fs),
10596
+ fs: fsp,
10513
10597
  cache,
10514
10598
  http,
10515
10599
  onProgress,
@@ -10518,7 +10602,7 @@ async function fastForward({
10518
10602
  onAuthSuccess,
10519
10603
  onAuthFailure,
10520
10604
  dir,
10521
- gitdir,
10605
+ gitdir: updatedGitdir,
10522
10606
  ref,
10523
10607
  url,
10524
10608
  remote,
@@ -10627,8 +10711,10 @@ async function fetch({
10627
10711
  assertParameter('http', http);
10628
10712
  assertParameter('gitdir', gitdir);
10629
10713
 
10714
+ const fsp = new FileSystem(fs);
10715
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
10630
10716
  return await _fetch({
10631
- fs: new FileSystem(fs),
10717
+ fs: fsp,
10632
10718
  cache,
10633
10719
  http,
10634
10720
  onProgress,
@@ -10636,7 +10722,7 @@ async function fetch({
10636
10722
  onAuth,
10637
10723
  onAuthSuccess,
10638
10724
  onAuthFailure,
10639
- gitdir,
10725
+ gitdir: updatedGitdir,
10640
10726
  ref,
10641
10727
  remote,
10642
10728
  remoteRef,
@@ -10683,10 +10769,12 @@ async function findMergeBase({
10683
10769
  assertParameter('gitdir', gitdir);
10684
10770
  assertParameter('oids', oids);
10685
10771
 
10772
+ const fsp = new FileSystem(fs);
10773
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
10686
10774
  return await _findMergeBase({
10687
- fs: new FileSystem(fs),
10775
+ fs: fsp,
10688
10776
  cache,
10689
- gitdir,
10777
+ gitdir: updatedGitdir,
10690
10778
  oids,
10691
10779
  })
10692
10780
  } catch (err) {
@@ -10787,9 +10875,11 @@ async function getConfig({ fs, dir, gitdir = join(dir, '.git'), path }) {
10787
10875
  assertParameter('gitdir', gitdir);
10788
10876
  assertParameter('path', path);
10789
10877
 
10878
+ const fsp = new FileSystem(fs);
10879
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
10790
10880
  return await _getConfig({
10791
- fs: new FileSystem(fs),
10792
- gitdir,
10881
+ fs: fsp,
10882
+ gitdir: updatedGitdir,
10793
10883
  path,
10794
10884
  })
10795
10885
  } catch (err) {
@@ -10843,9 +10933,11 @@ async function getConfigAll({
10843
10933
  assertParameter('gitdir', gitdir);
10844
10934
  assertParameter('path', path);
10845
10935
 
10936
+ const fsp = new FileSystem(fs);
10937
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
10846
10938
  return await _getConfigAll({
10847
- fs: new FileSystem(fs),
10848
- gitdir,
10939
+ fs: fsp,
10940
+ gitdir: updatedGitdir,
10849
10941
  path,
10850
10942
  })
10851
10943
  } catch (err) {
@@ -11264,12 +11356,14 @@ async function indexPack({
11264
11356
  assertParameter('gitdir', dir);
11265
11357
  assertParameter('filepath', filepath);
11266
11358
 
11359
+ const fsp = new FileSystem(fs);
11360
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
11267
11361
  return await _indexPack({
11268
- fs: new FileSystem(fs),
11362
+ fs: fsp,
11269
11363
  cache,
11270
11364
  onProgress,
11271
11365
  dir,
11272
- gitdir,
11366
+ gitdir: updatedGitdir,
11273
11367
  filepath,
11274
11368
  })
11275
11369
  } catch (err) {
@@ -11310,11 +11404,13 @@ async function init({
11310
11404
  assertParameter('dir', dir);
11311
11405
  }
11312
11406
 
11407
+ const fsp = new FileSystem(fs);
11408
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
11313
11409
  return await _init({
11314
- fs: new FileSystem(fs),
11410
+ fs: fsp,
11315
11411
  bare,
11316
11412
  dir,
11317
- gitdir,
11413
+ gitdir: updatedGitdir,
11318
11414
  defaultBranch,
11319
11415
  })
11320
11416
  } catch (err) {
@@ -11433,10 +11529,12 @@ async function isDescendent({
11433
11529
  assertParameter('oid', oid);
11434
11530
  assertParameter('ancestor', ancestor);
11435
11531
 
11532
+ const fsp = new FileSystem(fs);
11533
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
11436
11534
  return await _isDescendent({
11437
- fs: new FileSystem(fs),
11535
+ fs: fsp,
11438
11536
  cache,
11439
- gitdir,
11537
+ gitdir: updatedGitdir,
11440
11538
  oid,
11441
11539
  ancestor,
11442
11540
  depth,
@@ -11476,10 +11574,12 @@ async function isIgnored({
11476
11574
  assertParameter('gitdir', gitdir);
11477
11575
  assertParameter('filepath', filepath);
11478
11576
 
11577
+ const fsp = new FileSystem(fs);
11578
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
11479
11579
  return GitIgnoreManager.isIgnored({
11480
- fs: new FileSystem(fs),
11580
+ fs: fsp,
11481
11581
  dir,
11482
- gitdir,
11582
+ gitdir: updatedGitdir,
11483
11583
  filepath,
11484
11584
  })
11485
11585
  } catch (err) {
@@ -11527,9 +11627,11 @@ async function listBranches({
11527
11627
  assertParameter('fs', fs);
11528
11628
  assertParameter('gitdir', gitdir);
11529
11629
 
11630
+ const fsp = new FileSystem(fs);
11631
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
11530
11632
  return GitRefManager.listBranches({
11531
- fs: new FileSystem(fs),
11532
- gitdir,
11633
+ fs: fsp,
11634
+ gitdir: updatedGitdir,
11533
11635
  remote,
11534
11636
  })
11535
11637
  } catch (err) {
@@ -11635,10 +11737,12 @@ async function listFiles({
11635
11737
  assertParameter('fs', fs);
11636
11738
  assertParameter('gitdir', gitdir);
11637
11739
 
11740
+ const fsp = new FileSystem(fs);
11741
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
11638
11742
  return await _listFiles({
11639
- fs: new FileSystem(fs),
11743
+ fs: fsp,
11640
11744
  cache,
11641
- gitdir,
11745
+ gitdir: updatedGitdir,
11642
11746
  ref,
11643
11747
  })
11644
11748
  } catch (err) {
@@ -11715,10 +11819,12 @@ async function listNotes({
11715
11819
  assertParameter('gitdir', gitdir);
11716
11820
  assertParameter('ref', ref);
11717
11821
 
11822
+ const fsp = new FileSystem(fs);
11823
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
11718
11824
  return await _listNotes({
11719
- fs: new FileSystem(fs),
11825
+ fs: fsp,
11720
11826
  cache,
11721
- gitdir,
11827
+ gitdir: updatedGitdir,
11722
11828
  ref,
11723
11829
  })
11724
11830
  } catch (err) {
@@ -11754,7 +11860,9 @@ async function listRefs({
11754
11860
  try {
11755
11861
  assertParameter('fs', fs);
11756
11862
  assertParameter('gitdir', gitdir);
11757
- return GitRefManager.listRefs({ fs: new FileSystem(fs), gitdir, filepath })
11863
+ const fsp = new FileSystem(fs);
11864
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
11865
+ return GitRefManager.listRefs({ fs: fsp, gitdir: updatedGitdir, filepath })
11758
11866
  } catch (err) {
11759
11867
  err.caller = 'git.listRefs';
11760
11868
  throw err
@@ -11804,9 +11912,11 @@ async function listRemotes({ fs, dir, gitdir = join(dir, '.git') }) {
11804
11912
  assertParameter('fs', fs);
11805
11913
  assertParameter('gitdir', gitdir);
11806
11914
 
11915
+ const fsp = new FileSystem(fs);
11916
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
11807
11917
  return await _listRemotes({
11808
- fs: new FileSystem(fs),
11809
- gitdir,
11918
+ fs: fsp,
11919
+ gitdir: updatedGitdir,
11810
11920
  })
11811
11921
  } catch (err) {
11812
11922
  err.caller = 'git.listRemotes';
@@ -12047,7 +12157,9 @@ async function listTags({ fs, dir, gitdir = join(dir, '.git') }) {
12047
12157
  try {
12048
12158
  assertParameter('fs', fs);
12049
12159
  assertParameter('gitdir', gitdir);
12050
- return GitRefManager.listTags({ fs: new FileSystem(fs), gitdir })
12160
+ const fsp = new FileSystem(fs);
12161
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
12162
+ return GitRefManager.listTags({ fs: fsp, gitdir: updatedGitdir })
12051
12163
  } catch (err) {
12052
12164
  err.caller = 'git.listTags';
12053
12165
  throw err
@@ -12342,10 +12454,12 @@ async function log({
12342
12454
  assertParameter('gitdir', gitdir);
12343
12455
  assertParameter('ref', ref);
12344
12456
 
12457
+ const fsp = new FileSystem(fs);
12458
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
12345
12459
  return await _log({
12346
- fs: new FileSystem(fs),
12460
+ fs: fsp,
12347
12461
  cache,
12348
- gitdir,
12462
+ gitdir: updatedGitdir,
12349
12463
  filepath,
12350
12464
  ref,
12351
12465
  depth,
@@ -12499,15 +12613,20 @@ async function merge({
12499
12613
  assertParameter('onSign', onSign);
12500
12614
  }
12501
12615
  const fs = new FileSystem(_fs);
12616
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
12502
12617
 
12503
- const author = await normalizeAuthorObject({ fs, gitdir, author: _author });
12618
+ const author = await normalizeAuthorObject({
12619
+ fs,
12620
+ gitdir: updatedGitdir,
12621
+ author: _author,
12622
+ });
12504
12623
  if (!author && (!fastForwardOnly || !fastForward)) {
12505
12624
  throw new MissingNameError('author')
12506
12625
  }
12507
12626
 
12508
12627
  const committer = await normalizeCommitterObject({
12509
12628
  fs,
12510
- gitdir,
12629
+ gitdir: updatedGitdir,
12511
12630
  author,
12512
12631
  committer: _committer,
12513
12632
  });
@@ -12519,7 +12638,7 @@ async function merge({
12519
12638
  fs,
12520
12639
  cache,
12521
12640
  dir,
12522
- gitdir,
12641
+ gitdir: updatedGitdir,
12523
12642
  ours,
12524
12643
  theirs,
12525
12644
  fastForward,
@@ -12696,10 +12815,12 @@ async function packObjects({
12696
12815
  assertParameter('gitdir', gitdir);
12697
12816
  assertParameter('oids', oids);
12698
12817
 
12818
+ const fsp = new FileSystem(fs);
12819
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
12699
12820
  return await _packObjects({
12700
- fs: new FileSystem(fs),
12821
+ fs: fsp,
12701
12822
  cache,
12702
- gitdir,
12823
+ gitdir: updatedGitdir,
12703
12824
  oids,
12704
12825
  write,
12705
12826
  })
@@ -12792,13 +12913,18 @@ async function pull({
12792
12913
  assertParameter('gitdir', gitdir);
12793
12914
 
12794
12915
  const fs = new FileSystem(_fs);
12916
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
12795
12917
 
12796
- const author = await normalizeAuthorObject({ fs, gitdir, author: _author });
12918
+ const author = await normalizeAuthorObject({
12919
+ fs,
12920
+ gitdir: updatedGitdir,
12921
+ author: _author,
12922
+ });
12797
12923
  if (!author) throw new MissingNameError('author')
12798
12924
 
12799
12925
  const committer = await normalizeCommitterObject({
12800
12926
  fs,
12801
- gitdir,
12927
+ gitdir: updatedGitdir,
12802
12928
  author,
12803
12929
  committer: _committer,
12804
12930
  });
@@ -12814,7 +12940,7 @@ async function pull({
12814
12940
  onAuthSuccess,
12815
12941
  onAuthFailure,
12816
12942
  dir,
12817
- gitdir,
12943
+ gitdir: updatedGitdir,
12818
12944
  ref,
12819
12945
  url,
12820
12946
  remote,
@@ -13376,8 +13502,10 @@ async function push({
13376
13502
  assertParameter('http', http);
13377
13503
  assertParameter('gitdir', gitdir);
13378
13504
 
13505
+ const fsp = new FileSystem(fs);
13506
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
13379
13507
  return await _push({
13380
- fs: new FileSystem(fs),
13508
+ fs: fsp,
13381
13509
  cache,
13382
13510
  http,
13383
13511
  onProgress,
@@ -13386,7 +13514,7 @@ async function push({
13386
13514
  onAuthSuccess,
13387
13515
  onAuthFailure,
13388
13516
  onPrePush,
13389
- gitdir,
13517
+ gitdir: updatedGitdir,
13390
13518
  ref,
13391
13519
  remoteRef,
13392
13520
  remote,
@@ -13505,10 +13633,12 @@ async function readBlob({
13505
13633
  assertParameter('gitdir', gitdir);
13506
13634
  assertParameter('oid', oid);
13507
13635
 
13636
+ const fsp = new FileSystem(fs);
13637
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
13508
13638
  return await _readBlob({
13509
- fs: new FileSystem(fs),
13639
+ fs: fsp,
13510
13640
  cache,
13511
- gitdir,
13641
+ gitdir: updatedGitdir,
13512
13642
  oid,
13513
13643
  filepath,
13514
13644
  })
@@ -13554,10 +13684,12 @@ async function readCommit({
13554
13684
  assertParameter('gitdir', gitdir);
13555
13685
  assertParameter('oid', oid);
13556
13686
 
13687
+ const fsp = new FileSystem(fs);
13688
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
13557
13689
  return await _readCommit({
13558
- fs: new FileSystem(fs),
13690
+ fs: fsp,
13559
13691
  cache,
13560
- gitdir,
13692
+ gitdir: updatedGitdir,
13561
13693
  oid,
13562
13694
  })
13563
13695
  } catch (err) {
@@ -13630,10 +13762,12 @@ async function readNote({
13630
13762
  assertParameter('ref', ref);
13631
13763
  assertParameter('oid', oid);
13632
13764
 
13765
+ const fsp = new FileSystem(fs);
13766
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
13633
13767
  return await _readNote({
13634
- fs: new FileSystem(fs),
13768
+ fs: fsp,
13635
13769
  cache,
13636
- gitdir,
13770
+ gitdir: updatedGitdir,
13637
13771
  ref,
13638
13772
  oid,
13639
13773
  })
@@ -13849,11 +13983,12 @@ async function readObject({
13849
13983
  assertParameter('oid', oid);
13850
13984
 
13851
13985
  const fs = new FileSystem(_fs);
13986
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
13852
13987
  if (filepath !== undefined) {
13853
13988
  oid = await resolveFilepath({
13854
13989
  fs,
13855
13990
  cache,
13856
- gitdir,
13991
+ gitdir: updatedGitdir,
13857
13992
  oid,
13858
13993
  filepath,
13859
13994
  });
@@ -13863,7 +13998,7 @@ async function readObject({
13863
13998
  const result = await _readObject({
13864
13999
  fs,
13865
14000
  cache,
13866
- gitdir,
14001
+ gitdir: updatedGitdir,
13867
14002
  oid,
13868
14003
  format: _format,
13869
14004
  });
@@ -13982,10 +14117,12 @@ async function readTag({
13982
14117
  assertParameter('gitdir', gitdir);
13983
14118
  assertParameter('oid', oid);
13984
14119
 
14120
+ const fsp = new FileSystem(fs);
14121
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
13985
14122
  return await _readTag({
13986
- fs: new FileSystem(fs),
14123
+ fs: fsp,
13987
14124
  cache,
13988
- gitdir,
14125
+ gitdir: updatedGitdir,
13989
14126
  oid,
13990
14127
  })
13991
14128
  } catch (err) {
@@ -14033,10 +14170,12 @@ async function readTree({
14033
14170
  assertParameter('gitdir', gitdir);
14034
14171
  assertParameter('oid', oid);
14035
14172
 
14173
+ const fsp = new FileSystem(fs);
14174
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
14036
14175
  return await _readTree({
14037
- fs: new FileSystem(fs),
14176
+ fs: fsp,
14038
14177
  cache,
14039
- gitdir,
14178
+ gitdir: updatedGitdir,
14040
14179
  oid,
14041
14180
  filepath,
14042
14181
  })
@@ -14079,8 +14218,10 @@ async function remove({
14079
14218
  assertParameter('gitdir', gitdir);
14080
14219
  assertParameter('filepath', filepath);
14081
14220
 
14221
+ const fsp = new FileSystem(_fs);
14222
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
14082
14223
  await GitIndexManager.acquire(
14083
- { fs: new FileSystem(_fs), gitdir, cache },
14224
+ { fs: fsp, gitdir: updatedGitdir, cache },
14084
14225
  async function (index) {
14085
14226
  index.delete({ filepath });
14086
14227
  }
@@ -14221,13 +14362,18 @@ async function removeNote({
14221
14362
  assertParameter('oid', oid);
14222
14363
 
14223
14364
  const fs = new FileSystem(_fs);
14365
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
14224
14366
 
14225
- const author = await normalizeAuthorObject({ fs, gitdir, author: _author });
14367
+ const author = await normalizeAuthorObject({
14368
+ fs,
14369
+ gitdir: updatedGitdir,
14370
+ author: _author,
14371
+ });
14226
14372
  if (!author) throw new MissingNameError('author')
14227
14373
 
14228
14374
  const committer = await normalizeCommitterObject({
14229
14375
  fs,
14230
- gitdir,
14376
+ gitdir: updatedGitdir,
14231
14377
  author,
14232
14378
  committer: _committer,
14233
14379
  });
@@ -14237,7 +14383,7 @@ async function removeNote({
14237
14383
  fs,
14238
14384
  cache,
14239
14385
  onSign,
14240
- gitdir,
14386
+ gitdir: updatedGitdir,
14241
14387
  ref,
14242
14388
  oid,
14243
14389
  author,
@@ -14349,9 +14495,11 @@ async function renameBranch({
14349
14495
  assertParameter('gitdir', gitdir);
14350
14496
  assertParameter('ref', ref);
14351
14497
  assertParameter('oldref', oldref);
14498
+ const fsp = new FileSystem(fs);
14499
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
14352
14500
  return await _renameBranch({
14353
- fs: new FileSystem(fs),
14354
- gitdir,
14501
+ fs: fsp,
14502
+ gitdir: updatedGitdir,
14355
14503
  ref,
14356
14504
  oldref,
14357
14505
  checkout,
@@ -14402,13 +14550,18 @@ async function resetIndex({
14402
14550
  assertParameter('filepath', filepath);
14403
14551
 
14404
14552
  const fs = new FileSystem(_fs);
14553
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
14405
14554
 
14406
14555
  let oid;
14407
14556
  let workdirOid;
14408
14557
 
14409
14558
  try {
14410
14559
  // Resolve commit
14411
- oid = await GitRefManager.resolve({ fs, gitdir, ref: ref || 'HEAD' });
14560
+ oid = await GitRefManager.resolve({
14561
+ fs,
14562
+ gitdir: updatedGitdir,
14563
+ ref: ref || 'HEAD',
14564
+ });
14412
14565
  } catch (e) {
14413
14566
  if (ref) {
14414
14567
  // Only throw the error if a ref is explicitly provided
@@ -14424,7 +14577,7 @@ async function resetIndex({
14424
14577
  oid = await resolveFilepath({
14425
14578
  fs,
14426
14579
  cache,
14427
- gitdir,
14580
+ gitdir: updatedGitdir,
14428
14581
  oid,
14429
14582
  filepath,
14430
14583
  });
@@ -14450,7 +14603,7 @@ async function resetIndex({
14450
14603
  if (object) {
14451
14604
  // ... and has the same hash as the desired state...
14452
14605
  workdirOid = await hashObject$1({
14453
- gitdir,
14606
+ gitdir: updatedGitdir,
14454
14607
  type: 'blob',
14455
14608
  object,
14456
14609
  });
@@ -14460,7 +14613,7 @@ async function resetIndex({
14460
14613
  }
14461
14614
  }
14462
14615
  await GitIndexManager.acquire(
14463
- { fs, gitdir, cache },
14616
+ { fs, gitdir: updatedGitdir, cache },
14464
14617
  async function (index) {
14465
14618
  index.delete({ filepath });
14466
14619
  if (oid) {
@@ -14506,10 +14659,12 @@ async function resolveRef({
14506
14659
  assertParameter('fs', fs);
14507
14660
  assertParameter('gitdir', gitdir);
14508
14661
  assertParameter('ref', ref);
14662
+ const fsp = new FileSystem(fs);
14663
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
14509
14664
 
14510
14665
  const oid = await GitRefManager.resolve({
14511
- fs: new FileSystem(fs),
14512
- gitdir,
14666
+ fs: fsp,
14667
+ gitdir: updatedGitdir,
14513
14668
  ref,
14514
14669
  depth,
14515
14670
  });
@@ -14579,13 +14734,14 @@ async function setConfig({
14579
14734
  // assertParameter('value', value) // We actually allow 'undefined' as a value to unset/delete
14580
14735
 
14581
14736
  const fs = new FileSystem(_fs);
14582
- const config = await GitConfigManager.get({ fs, gitdir });
14737
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
14738
+ const config = await GitConfigManager.get({ fs, gitdir: updatedGitdir });
14583
14739
  if (append) {
14584
14740
  await config.append(path, value);
14585
14741
  } else {
14586
14742
  await config.set(path, value);
14587
14743
  }
14588
- await GitConfigManager.save({ fs, gitdir, config });
14744
+ await GitConfigManager.save({ fs, gitdir: updatedGitdir, config });
14589
14745
  } catch (err) {
14590
14746
  err.caller = 'git.setConfig';
14591
14747
  throw err
@@ -15454,9 +15610,10 @@ async function stash({
15454
15610
 
15455
15611
  try {
15456
15612
  const _fs = new FileSystem(fs);
15613
+ const updatedGitdir = await discoverGitdir({ fsp: _fs, dotgit: gitdir });
15457
15614
  const folders = ['refs', 'logs', 'logs/refs'];
15458
15615
  folders
15459
- .map(f => join(gitdir, f))
15616
+ .map(f => join(updatedGitdir, f))
15460
15617
  .forEach(async folder => {
15461
15618
  if (!(await _fs.exists(folder))) {
15462
15619
  await _fs.mkdir(folder);
@@ -15471,7 +15628,13 @@ async function stash({
15471
15628
  'number that is in range of [0, num of stash pushed]'
15472
15629
  )
15473
15630
  }
15474
- return await opFunc({ fs: _fs, dir, gitdir, message, refIdx })
15631
+ return await opFunc({
15632
+ fs: _fs,
15633
+ dir,
15634
+ gitdir: updatedGitdir,
15635
+ message,
15636
+ refIdx,
15637
+ })
15475
15638
  }
15476
15639
  throw new Error(`To be implemented: ${op}`)
15477
15640
  } catch (err) {
@@ -15530,25 +15693,26 @@ async function status({
15530
15693
  assertParameter('filepath', filepath);
15531
15694
 
15532
15695
  const fs = new FileSystem(_fs);
15696
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
15533
15697
  const ignored = await GitIgnoreManager.isIgnored({
15534
15698
  fs,
15535
- gitdir,
15699
+ gitdir: updatedGitdir,
15536
15700
  dir,
15537
15701
  filepath,
15538
15702
  });
15539
15703
  if (ignored) {
15540
15704
  return 'ignored'
15541
15705
  }
15542
- const headTree = await getHeadTree({ fs, cache, gitdir });
15706
+ const headTree = await getHeadTree({ fs, cache, gitdir: updatedGitdir });
15543
15707
  const treeOid = await getOidAtPath({
15544
15708
  fs,
15545
15709
  cache,
15546
- gitdir,
15710
+ gitdir: updatedGitdir,
15547
15711
  tree: headTree,
15548
15712
  path: filepath,
15549
15713
  });
15550
15714
  const indexEntry = await GitIndexManager.acquire(
15551
- { fs, gitdir, cache },
15715
+ { fs, gitdir: updatedGitdir, cache },
15552
15716
  async function (index) {
15553
15717
  for (const entry of index) {
15554
15718
  if (entry.path === filepath) return entry
@@ -15568,7 +15732,7 @@ async function status({
15568
15732
  } else {
15569
15733
  const object = await fs.read(join(dir, filepath));
15570
15734
  const workdirOid = await hashObject$1({
15571
- gitdir,
15735
+ gitdir: updatedGitdir,
15572
15736
  type: 'blob',
15573
15737
  object,
15574
15738
  });
@@ -15580,7 +15744,7 @@ async function status({
15580
15744
  if (stats.size !== -1) {
15581
15745
  // We don't await this so we can return faster for one-off cases.
15582
15746
  GitIndexManager.acquire(
15583
- { fs, gitdir, cache },
15747
+ { fs, gitdir: updatedGitdir, cache },
15584
15748
  async function (index) {
15585
15749
  index.insert({ filepath, stats, oid: workdirOid });
15586
15750
  }
@@ -15640,7 +15804,7 @@ async function status({
15640
15804
  }
15641
15805
  }
15642
15806
 
15643
- async function getOidAtPath({ fs, cache, gitdir, tree, path }) {
15807
+ async function getOidAtPath({ fs, cache, gitdir: updatedGitdir, tree, path }) {
15644
15808
  if (typeof path === 'string') path = path.split('/');
15645
15809
  const dirname = path.shift();
15646
15810
  for (const entry of tree) {
@@ -15651,12 +15815,12 @@ async function getOidAtPath({ fs, cache, gitdir, tree, path }) {
15651
15815
  const { type, object } = await _readObject({
15652
15816
  fs,
15653
15817
  cache,
15654
- gitdir,
15818
+ gitdir: updatedGitdir,
15655
15819
  oid: entry.oid,
15656
15820
  });
15657
15821
  if (type === 'tree') {
15658
15822
  const tree = GitTree.from(object);
15659
- return getOidAtPath({ fs, cache, gitdir, tree, path })
15823
+ return getOidAtPath({ fs, cache, gitdir: updatedGitdir, tree, path })
15660
15824
  }
15661
15825
  if (type === 'blob') {
15662
15826
  throw new ObjectTypeError(entry.oid, type, 'blob', path.join('/'))
@@ -15666,18 +15830,22 @@ async function getOidAtPath({ fs, cache, gitdir, tree, path }) {
15666
15830
  return null
15667
15831
  }
15668
15832
 
15669
- async function getHeadTree({ fs, cache, gitdir }) {
15833
+ async function getHeadTree({ fs, cache, gitdir: updatedGitdir }) {
15670
15834
  // Get the tree from the HEAD commit.
15671
15835
  let oid;
15672
15836
  try {
15673
- oid = await GitRefManager.resolve({ fs, gitdir, ref: 'HEAD' });
15837
+ oid = await GitRefManager.resolve({
15838
+ fs,
15839
+ gitdir: updatedGitdir,
15840
+ ref: 'HEAD',
15841
+ });
15674
15842
  } catch (e) {
15675
15843
  // Handle fresh branches with no commits
15676
15844
  if (e instanceof NotFoundError) {
15677
15845
  return []
15678
15846
  }
15679
15847
  }
15680
- const { tree } = await _readTree({ fs, cache, gitdir, oid });
15848
+ const { tree } = await _readTree({ fs, cache, gitdir: updatedGitdir, oid });
15681
15849
  return tree
15682
15850
  }
15683
15851
 
@@ -15842,11 +16010,12 @@ async function statusMatrix({
15842
16010
  assertParameter('ref', ref);
15843
16011
 
15844
16012
  const fs = new FileSystem(_fs);
16013
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
15845
16014
  return await _walk({
15846
16015
  fs,
15847
16016
  cache,
15848
16017
  dir,
15849
- gitdir,
16018
+ gitdir: updatedGitdir,
15850
16019
  trees: [TREE({ ref }), WORKDIR(), STAGE()],
15851
16020
  map: async function (filepath, [head, workdir, stage]) {
15852
16021
  // Ignore ignored files, but only if they are not already tracked.
@@ -15958,17 +16127,21 @@ async function tag({
15958
16127
  ref = ref.startsWith('refs/tags/') ? ref : `refs/tags/${ref}`;
15959
16128
 
15960
16129
  // Resolve passed object
16130
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
15961
16131
  const value = await GitRefManager.resolve({
15962
16132
  fs,
15963
- gitdir,
16133
+ gitdir: updatedGitdir,
15964
16134
  ref: object || 'HEAD',
15965
16135
  });
15966
16136
 
15967
- if (!force && (await GitRefManager.exists({ fs, gitdir, ref }))) {
16137
+ if (
16138
+ !force &&
16139
+ (await GitRefManager.exists({ fs, gitdir: updatedGitdir, ref }))
16140
+ ) {
15968
16141
  throw new AlreadyExistsError('tag', ref)
15969
16142
  }
15970
16143
 
15971
- await GitRefManager.writeRef({ fs, gitdir, ref, value });
16144
+ await GitRefManager.writeRef({ fs, gitdir: updatedGitdir, ref, value });
15972
16145
  } catch (err) {
15973
16146
  err.caller = 'git.tag';
15974
16147
  throw err
@@ -16036,10 +16209,11 @@ async function updateIndex$1({
16036
16209
  assertParameter('filepath', filepath);
16037
16210
 
16038
16211
  const fs = new FileSystem(_fs);
16212
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
16039
16213
 
16040
16214
  if (remove) {
16041
16215
  return await GitIndexManager.acquire(
16042
- { fs, gitdir, cache },
16216
+ { fs, gitdir: updatedGitdir, cache },
16043
16217
  async function (index) {
16044
16218
  if (!force) {
16045
16219
  // Check if the file is still present in the working directory
@@ -16084,7 +16258,7 @@ async function updateIndex$1({
16084
16258
  }
16085
16259
 
16086
16260
  return await GitIndexManager.acquire(
16087
- { fs, gitdir, cache },
16261
+ { fs, gitdir: updatedGitdir, cache },
16088
16262
  async function (index) {
16089
16263
  if (!add && !index.has({ filepath })) {
16090
16264
  // If the index does not contain the filepath yet and `add` is not set, we should throw
@@ -16104,7 +16278,7 @@ async function updateIndex$1({
16104
16278
 
16105
16279
  oid = await _writeObject({
16106
16280
  fs,
16107
- gitdir,
16281
+ gitdir: updatedGitdir,
16108
16282
  type: 'blob',
16109
16283
  format: 'content',
16110
16284
  object,
@@ -16423,11 +16597,13 @@ async function walk({
16423
16597
  assertParameter('gitdir', gitdir);
16424
16598
  assertParameter('trees', trees);
16425
16599
 
16600
+ const fsp = new FileSystem(fs);
16601
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
16426
16602
  return await _walk({
16427
- fs: new FileSystem(fs),
16603
+ fs: fsp,
16428
16604
  cache,
16429
16605
  dir,
16430
- gitdir,
16606
+ gitdir: updatedGitdir,
16431
16607
  trees,
16432
16608
  map,
16433
16609
  reduce,
@@ -16469,9 +16645,11 @@ async function writeBlob({ fs, dir, gitdir = join(dir, '.git'), blob }) {
16469
16645
  assertParameter('gitdir', gitdir);
16470
16646
  assertParameter('blob', blob);
16471
16647
 
16648
+ const fsp = new FileSystem(fs);
16649
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
16472
16650
  return await _writeObject({
16473
- fs: new FileSystem(fs),
16474
- gitdir,
16651
+ fs: fsp,
16652
+ gitdir: updatedGitdir,
16475
16653
  type: 'blob',
16476
16654
  object: blob,
16477
16655
  format: 'content',
@@ -16508,9 +16686,11 @@ async function writeCommit({
16508
16686
  assertParameter('gitdir', gitdir);
16509
16687
  assertParameter('commit', commit);
16510
16688
 
16689
+ const fsp = new FileSystem(fs);
16690
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
16511
16691
  return await _writeCommit({
16512
- fs: new FileSystem(fs),
16513
- gitdir,
16692
+ fs: fsp,
16693
+ gitdir: updatedGitdir,
16514
16694
  commit,
16515
16695
  })
16516
16696
  } catch (err) {
@@ -16598,6 +16778,7 @@ async function writeObject({
16598
16778
  }) {
16599
16779
  try {
16600
16780
  const fs = new FileSystem(_fs);
16781
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
16601
16782
  // Convert object to buffer
16602
16783
  if (format === 'parsed') {
16603
16784
  switch (type) {
@@ -16621,7 +16802,7 @@ async function writeObject({
16621
16802
  }
16622
16803
  oid = await _writeObject({
16623
16804
  fs,
16624
- gitdir,
16805
+ gitdir: updatedGitdir,
16625
16806
  type,
16626
16807
  object,
16627
16808
  oid,
@@ -16689,26 +16870,30 @@ async function writeRef({
16689
16870
  throw new InvalidRefNameError(ref, cleanGitRef.clean(ref))
16690
16871
  }
16691
16872
 
16692
- if (!force && (await GitRefManager.exists({ fs, gitdir, ref }))) {
16873
+ const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
16874
+ if (
16875
+ !force &&
16876
+ (await GitRefManager.exists({ fs, gitdir: updatedGitdir, ref }))
16877
+ ) {
16693
16878
  throw new AlreadyExistsError('ref', ref)
16694
16879
  }
16695
16880
 
16696
16881
  if (symbolic) {
16697
16882
  await GitRefManager.writeSymbolicRef({
16698
16883
  fs,
16699
- gitdir,
16884
+ gitdir: updatedGitdir,
16700
16885
  ref,
16701
16886
  value,
16702
16887
  });
16703
16888
  } else {
16704
16889
  value = await GitRefManager.resolve({
16705
16890
  fs,
16706
- gitdir,
16891
+ gitdir: updatedGitdir,
16707
16892
  ref: value,
16708
16893
  });
16709
16894
  await GitRefManager.writeRef({
16710
16895
  fs,
16711
- gitdir,
16896
+ gitdir: updatedGitdir,
16712
16897
  ref,
16713
16898
  value,
16714
16899
  });
@@ -16787,9 +16972,11 @@ async function writeTag({ fs, dir, gitdir = join(dir, '.git'), tag }) {
16787
16972
  assertParameter('gitdir', gitdir);
16788
16973
  assertParameter('tag', tag);
16789
16974
 
16975
+ const fsp = new FileSystem(fs);
16976
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
16790
16977
  return await _writeTag({
16791
- fs: new FileSystem(fs),
16792
- gitdir,
16978
+ fs: fsp,
16979
+ gitdir: updatedGitdir,
16793
16980
  tag,
16794
16981
  })
16795
16982
  } catch (err) {
@@ -16820,9 +17007,11 @@ async function writeTree({ fs, dir, gitdir = join(dir, '.git'), tree }) {
16820
17007
  assertParameter('gitdir', gitdir);
16821
17008
  assertParameter('tree', tree);
16822
17009
 
17010
+ const fsp = new FileSystem(fs);
17011
+ const updatedGitdir = await discoverGitdir({ fsp, dotgit: gitdir });
16823
17012
  return await _writeTree({
16824
- fs: new FileSystem(fs),
16825
- gitdir,
17013
+ fs: fsp,
17014
+ gitdir: updatedGitdir,
16826
17015
  tree,
16827
17016
  })
16828
17017
  } catch (err) {