isomorphic-git 1.41.9 → 1.42.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
@@ -28,7 +28,7 @@ import diff3Merge from 'diff3';
28
28
  * @property {Object} [agent] - An HTTP or HTTPS agent that manages connections for the HTTP client (Node.js only)
29
29
  * @property {AsyncIterableIterator<Uint8Array>} [body] - An async iterator of Uint8Arrays that make up the body of POST requests
30
30
  * @property {ProgressCallback} [onProgress] - Reserved for future use (emitting `GitProgressEvent`s)
31
- * @property {object} [signal] - Reserved for future use (canceling a request)
31
+ * @property {AbortSignal} [signal] - Signal to abort the HTTP request
32
32
  * @property {Object} [fetchOptions={}] - Additional options to pass to fetch (Web) or simple-get (Node)
33
33
  */
34
34
 
@@ -9384,6 +9384,7 @@ class GitRemoteHTTP {
9384
9384
  * @param {string} args.service - The Git service (e.g., "git-upload-pack").
9385
9385
  * @param {string} args.url - The URL of the remote repository.
9386
9386
  * @param {Object<string, string>} args.headers - HTTP headers to include in the request.
9387
+ * @param {AbortSignal} [args.signal] - Signal to abort the operation.
9387
9388
  * @param {1 | 2} args.protocolVersion - The Git protocol version to use.
9388
9389
  * @returns {Promise<Object>} - The parsed response from the remote repository.
9389
9390
  * @throws {HttpError} - If the HTTP request fails.
@@ -9400,6 +9401,7 @@ class GitRemoteHTTP {
9400
9401
  service,
9401
9402
  url: _origUrl,
9402
9403
  headers,
9404
+ signal,
9403
9405
  protocolVersion,
9404
9406
  }) {
9405
9407
  let { url, auth } = extractAuthFromUrl(_origUrl);
@@ -9420,6 +9422,7 @@ class GitRemoteHTTP {
9420
9422
  method: 'GET',
9421
9423
  url: `${proxifiedURL}/info/refs?service=${service}`,
9422
9424
  headers,
9425
+ signal,
9423
9426
  });
9424
9427
 
9425
9428
  // the default loop behavior
@@ -9495,6 +9498,7 @@ class GitRemoteHTTP {
9495
9498
  * @param {Object<string, string>} [args.headers] - HTTP headers to include in the request.
9496
9499
  * @param {any} args.body - The request body to send.
9497
9500
  * @param {any} args.auth - Authentication credentials.
9501
+ * @param {AbortSignal} [args.signal] - Signal to abort the operation.
9498
9502
  * @returns {Promise<GitHttpResponse>} - The HTTP response from the remote repository.
9499
9503
  * @throws {HttpError} - If the HTTP request fails.
9500
9504
  */
@@ -9507,6 +9511,7 @@ class GitRemoteHTTP {
9507
9511
  auth,
9508
9512
  body,
9509
9513
  headers,
9514
+ signal,
9510
9515
  }) {
9511
9516
  // We already have the "correct" auth value at this point, but
9512
9517
  // we need to strip out the username/password from the URL yet again.
@@ -9525,6 +9530,7 @@ class GitRemoteHTTP {
9525
9530
  url: `${url}/${service}`,
9526
9531
  body,
9527
9532
  headers,
9533
+ signal,
9528
9534
  });
9529
9535
  if (res.statusCode !== 200) {
9530
9536
  const { response } = stringifyBody(res);
@@ -9760,8 +9766,8 @@ function filterCapabilities(server, client) {
9760
9766
 
9761
9767
  const pkg = {
9762
9768
  name: 'isomorphic-git',
9763
- version: '1.41.9',
9764
- agent: 'git/isomorphic-git@1.41.9',
9769
+ version: '1.42.1',
9770
+ agent: 'git/isomorphic-git@1.42.1',
9765
9771
  };
9766
9772
 
9767
9773
  class FIFO {
@@ -12070,6 +12076,30 @@ async function getConfigAll({
12070
12076
  *
12071
12077
  */
12072
12078
 
12079
+ // Assign `value` at the `/`-separated `path` inside `root`, creating the
12080
+ // intermediate objects as we go.
12081
+ //
12082
+ // Ref names come straight off the wire, so a path segment must never be allowed
12083
+ // to walk out of `root` and into the prototype chain. The `hasOwnProperty` check
12084
+ // takes care of inherited keys such as `constructor` by shadowing them with a
12085
+ // fresh object; `__proto__` gets no such treatment because assigning it invokes
12086
+ // the setter instead of creating an own property, so refs containing it are
12087
+ // dropped.
12088
+ //
12089
+ // NB: deliberately not a JSDoc comment. `__tests__/__helpers__/generate-docs.cjs`
12090
+ // turns every documented function in `src/api` into a public doc page.
12091
+ function assignRefPath(root, path, value) {
12092
+ const parts = path.split('/');
12093
+ const last = parts.pop();
12094
+ if (last === '__proto__' || parts.includes('__proto__')) return
12095
+ let o = root;
12096
+ for (const part of parts) {
12097
+ if (!Object.prototype.hasOwnProperty.call(o, part)) o[part] = {};
12098
+ o = o[part];
12099
+ }
12100
+ o[last] = value;
12101
+ }
12102
+
12073
12103
  /**
12074
12104
  * List a remote servers branches, tags, and capabilities.
12075
12105
  *
@@ -12134,25 +12164,11 @@ async function getRemoteInfo({
12134
12164
  // Convert the flat list into an object tree, because I figure 99% of the time
12135
12165
  // that will be easier to use.
12136
12166
  for (const [ref, oid] of remote.refs) {
12137
- const parts = ref.split('/');
12138
- const last = parts.pop();
12139
- let o = result;
12140
- for (const part of parts) {
12141
- o[part] = o[part] || {};
12142
- o = o[part];
12143
- }
12144
- o[last] = oid;
12167
+ assignRefPath(result, ref, oid);
12145
12168
  }
12146
12169
  // Merge symrefs on top of refs to more closely match actual git repo layouts
12147
12170
  for (const [symref, ref] of remote.symrefs) {
12148
- const parts = symref.split('/');
12149
- const last = parts.pop();
12150
- let o = result;
12151
- for (const part of parts) {
12152
- o[part] = o[part] || {};
12153
- o = o[part];
12154
- }
12155
- o[last] = ref;
12171
+ assignRefPath(result, symref, ref);
12156
12172
  }
12157
12173
  return result
12158
12174
  } catch (err) {
@@ -14326,6 +14342,7 @@ async function writeReceivePackRequest({
14326
14342
  * @param {boolean} [args.delete = false]
14327
14343
  * @param {string} [args.url]
14328
14344
  * @param {string} [args.corsProxy]
14345
+ * @param {AbortSignal} [args.signal]
14329
14346
  * @param {Object<string, string>} [args.headers]
14330
14347
  *
14331
14348
  * @returns {Promise<PushResult>}
@@ -14349,6 +14366,7 @@ async function _push({
14349
14366
  delete: _delete = false,
14350
14367
  corsProxy,
14351
14368
  headers = {},
14369
+ signal,
14352
14370
  }) {
14353
14371
  const ref = _ref || (await _currentBranch({ fs, gitdir }));
14354
14372
  if (typeof ref === 'undefined') {
@@ -14397,6 +14415,7 @@ async function _push({
14397
14415
  url,
14398
14416
  headers,
14399
14417
  protocolVersion: 1,
14418
+ signal,
14400
14419
  });
14401
14420
  const auth = httpRemote.auth; // hack to get new credentials from CredentialManager API
14402
14421
  let fullRemoteRef;
@@ -14444,13 +14463,20 @@ async function _push({
14444
14463
 
14445
14464
  // If remote branch is present, look for a common merge base.
14446
14465
  if (oldoid !== '0000000000000000000000000000000000000000') {
14447
- // trick to speed up common force push scenarios
14448
- const mergebase = await _findMergeBase({
14449
- fs,
14450
- cache,
14451
- gitdir,
14452
- oids: [oid, oldoid],
14453
- });
14466
+ // Speeds up common force-push / thin-pack scenarios. The advertised
14467
+ // remote tip may be absent locally (e.g. remote advanced since clone);
14468
+ // that is normal and must not surface as NotFoundError from merge-base.
14469
+ let mergebase = [];
14470
+ try {
14471
+ mergebase = await _findMergeBase({
14472
+ fs,
14473
+ cache,
14474
+ gitdir,
14475
+ oids: [oid, oldoid],
14476
+ });
14477
+ } catch (e) {
14478
+ mergebase = [];
14479
+ }
14454
14480
  for (const oid of mergebase) finish.push(oid);
14455
14481
  if (thinPack) {
14456
14482
  skipObjects = await listObjects({ fs, cache, gitdir, oids: mergebase });
@@ -14552,6 +14578,7 @@ async function _push({
14552
14578
  auth,
14553
14579
  headers,
14554
14580
  body: [...packstream1, ...packstream2],
14581
+ signal,
14555
14582
  });
14556
14583
  const { packfile, progress } = await GitSideBand.demux(res.body);
14557
14584
  if (onMessage) {
@@ -14628,6 +14655,7 @@ async function _push({
14628
14655
  * @param {string} [args.corsProxy] - Optional [CORS proxy](https://www.npmjs.com/%40isomorphic-git/cors-proxy). Overrides value in repo config.
14629
14656
  * @param {Object<string, string>} [args.headers] - Additional headers to include in HTTP requests, similar to git's `extraHeader` config
14630
14657
  * @param {object} [args.cache] - a [cache](cache.md) object
14658
+ * @param {AbortSignal} [args.signal] - Optional signal to abort the push operation
14631
14659
  *
14632
14660
  * @returns {Promise<PushResult>} Resolves successfully when push completes with a detailed description of the operation from the server.
14633
14661
  * @see PushResult
@@ -14665,6 +14693,7 @@ async function push({
14665
14693
  corsProxy,
14666
14694
  headers = {},
14667
14695
  cache = {},
14696
+ signal,
14668
14697
  }) {
14669
14698
  try {
14670
14699
  assertParameter('fs', fs);
@@ -14692,6 +14721,7 @@ async function push({
14692
14721
  delete: _delete,
14693
14722
  corsProxy,
14694
14723
  headers,
14724
+ signal,
14695
14725
  })
14696
14726
  } catch (err) {
14697
14727
  err.caller = 'git.push';
@@ -301,9 +301,9 @@ export type GitHttpRequest = {
301
301
  */
302
302
  onProgress?: ProgressCallback | undefined;
303
303
  /**
304
- * - Reserved for future use (canceling a request)
304
+ * - Signal to abort the HTTP request
305
305
  */
306
- signal?: object;
306
+ signal?: AbortSignal | undefined;
307
307
  /**
308
308
  * - Additional options to pass to fetch (Web) or simple-get (Node)
309
309
  */
@@ -1659,17 +1659,6 @@ export function getConfigAll({ fs, dir, gitdir, path, }: {
1659
1659
  gitdir?: string | undefined;
1660
1660
  path: string;
1661
1661
  }): Promise<Array<any>>;
1662
- /**
1663
- *
1664
- * @typedef {Object} GetRemoteInfoResult - The object returned has the following schema:
1665
- * @property {string[]} capabilities - The list of capabilities returned by the server (part of the Git protocol)
1666
- * @property {Object} [refs]
1667
- * @property {string} [HEAD] - The default branch of the remote
1668
- * @property {Object<string, string>} [refs.heads] - The branches on the remote
1669
- * @property {Object<string, string>} [refs.pull] - The special branches representing pull requests (non-standard)
1670
- * @property {Object<string, string>} [refs.tags] - The tags on the remote
1671
- *
1672
- */
1673
1662
  /**
1674
1663
  * List a remote servers branches, tags, and capabilities.
1675
1664
  *
@@ -2516,6 +2505,7 @@ export function pull({ fs: _fs, http, onProgress, onMessage, onAuth, onAuthSucce
2516
2505
  * @param {string} [args.corsProxy] - Optional [CORS proxy](https://www.npmjs.com/%40isomorphic-git/cors-proxy). Overrides value in repo config.
2517
2506
  * @param {Object<string, string>} [args.headers] - Additional headers to include in HTTP requests, similar to git's `extraHeader` config
2518
2507
  * @param {object} [args.cache] - a [cache](cache.md) object
2508
+ * @param {AbortSignal} [args.signal] - Optional signal to abort the push operation
2519
2509
  *
2520
2510
  * @returns {Promise<PushResult>} Resolves successfully when push completes with a detailed description of the operation from the server.
2521
2511
  * @see PushResult
@@ -2533,7 +2523,7 @@ export function pull({ fs: _fs, http, onProgress, onMessage, onAuth, onAuthSucce
2533
2523
  * console.log(pushResult)
2534
2524
  *
2535
2525
  */
2536
- export function push({ fs, http, onProgress, onMessage, onAuth, onAuthSuccess, onAuthFailure, onPrePush, dir, gitdir, ref, remoteRef, remote, url, force, delete: _delete, corsProxy, headers, cache, }: {
2526
+ export function push({ fs, http, onProgress, onMessage, onAuth, onAuthSuccess, onAuthFailure, onPrePush, dir, gitdir, ref, remoteRef, remote, url, force, delete: _delete, corsProxy, headers, cache, signal, }: {
2537
2527
  fs: FsClient;
2538
2528
  http: HttpClient;
2539
2529
  onProgress?: ProgressCallback | undefined;
@@ -2555,6 +2545,7 @@ export function push({ fs, http, onProgress, onMessage, onAuth, onAuthSuccess, o
2555
2545
  [x: string]: string;
2556
2546
  } | undefined;
2557
2547
  cache?: object;
2548
+ signal?: AbortSignal | undefined;
2558
2549
  }): Promise<PushResult>;
2559
2550
  /**
2560
2551
  *
@@ -4503,7 +4494,7 @@ declare namespace NoCommitError {
4503
4494
  * @property {Object} [agent] - An HTTP or HTTPS agent that manages connections for the HTTP client (Node.js only)
4504
4495
  * @property {AsyncIterableIterator<Uint8Array>} [body] - An async iterator of Uint8Arrays that make up the body of POST requests
4505
4496
  * @property {ProgressCallback} [onProgress] - Reserved for future use (emitting `GitProgressEvent`s)
4506
- * @property {object} [signal] - Reserved for future use (canceling a request)
4497
+ * @property {AbortSignal} [signal] - Signal to abort the HTTP request
4507
4498
  * @property {Object} [fetchOptions={}] - Additional options to pass to fetch (Web) or simple-get (Node)
4508
4499
  */
4509
4500
  /**