isomorphic-git 1.41.8 → 1.42.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.
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
 
@@ -7110,11 +7110,17 @@ const worthWalking = (filepath, root) => {
7110
7110
  if (filepath === '.' || root == null || root.length === 0 || root === '.') {
7111
7111
  return true
7112
7112
  }
7113
- if (root.length >= filepath.length) {
7114
- return root.startsWith(filepath)
7115
- } else {
7116
- return filepath.startsWith(root)
7113
+ // A shared prefix only counts when it lands on a path component boundary,
7114
+ // otherwise the root 'src' would also pull in 'src2/a.js' and 'srcfoo.txt'.
7115
+ const base = root.endsWith('/') ? root.slice(0, -1) : root;
7116
+ if (base === '.') {
7117
+ return true
7118
+ }
7119
+ if (base.length >= filepath.length) {
7120
+ // Keep walking while filepath is still an ancestor of the wanted root.
7121
+ return base === filepath || base.startsWith(`${filepath}/`)
7117
7122
  }
7123
+ return filepath.startsWith(`${base}/`)
7118
7124
  };
7119
7125
 
7120
7126
  // @ts-check
@@ -9378,6 +9384,7 @@ class GitRemoteHTTP {
9378
9384
  * @param {string} args.service - The Git service (e.g., "git-upload-pack").
9379
9385
  * @param {string} args.url - The URL of the remote repository.
9380
9386
  * @param {Object<string, string>} args.headers - HTTP headers to include in the request.
9387
+ * @param {AbortSignal} [args.signal] - Signal to abort the operation.
9381
9388
  * @param {1 | 2} args.protocolVersion - The Git protocol version to use.
9382
9389
  * @returns {Promise<Object>} - The parsed response from the remote repository.
9383
9390
  * @throws {HttpError} - If the HTTP request fails.
@@ -9394,6 +9401,7 @@ class GitRemoteHTTP {
9394
9401
  service,
9395
9402
  url: _origUrl,
9396
9403
  headers,
9404
+ signal,
9397
9405
  protocolVersion,
9398
9406
  }) {
9399
9407
  let { url, auth } = extractAuthFromUrl(_origUrl);
@@ -9414,6 +9422,7 @@ class GitRemoteHTTP {
9414
9422
  method: 'GET',
9415
9423
  url: `${proxifiedURL}/info/refs?service=${service}`,
9416
9424
  headers,
9425
+ signal,
9417
9426
  });
9418
9427
 
9419
9428
  // the default loop behavior
@@ -9489,6 +9498,7 @@ class GitRemoteHTTP {
9489
9498
  * @param {Object<string, string>} [args.headers] - HTTP headers to include in the request.
9490
9499
  * @param {any} args.body - The request body to send.
9491
9500
  * @param {any} args.auth - Authentication credentials.
9501
+ * @param {AbortSignal} [args.signal] - Signal to abort the operation.
9492
9502
  * @returns {Promise<GitHttpResponse>} - The HTTP response from the remote repository.
9493
9503
  * @throws {HttpError} - If the HTTP request fails.
9494
9504
  */
@@ -9501,6 +9511,7 @@ class GitRemoteHTTP {
9501
9511
  auth,
9502
9512
  body,
9503
9513
  headers,
9514
+ signal,
9504
9515
  }) {
9505
9516
  // We already have the "correct" auth value at this point, but
9506
9517
  // we need to strip out the username/password from the URL yet again.
@@ -9519,6 +9530,7 @@ class GitRemoteHTTP {
9519
9530
  url: `${url}/${service}`,
9520
9531
  body,
9521
9532
  headers,
9533
+ signal,
9522
9534
  });
9523
9535
  if (res.statusCode !== 200) {
9524
9536
  const { response } = stringifyBody(res);
@@ -9754,8 +9766,8 @@ function filterCapabilities(server, client) {
9754
9766
 
9755
9767
  const pkg = {
9756
9768
  name: 'isomorphic-git',
9757
- version: '1.41.8',
9758
- agent: 'git/isomorphic-git@1.41.8',
9769
+ version: '1.42.0',
9770
+ agent: 'git/isomorphic-git@1.42.0',
9759
9771
  };
9760
9772
 
9761
9773
  class FIFO {
@@ -12064,6 +12076,30 @@ async function getConfigAll({
12064
12076
  *
12065
12077
  */
12066
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
+
12067
12103
  /**
12068
12104
  * List a remote servers branches, tags, and capabilities.
12069
12105
  *
@@ -12128,25 +12164,11 @@ async function getRemoteInfo({
12128
12164
  // Convert the flat list into an object tree, because I figure 99% of the time
12129
12165
  // that will be easier to use.
12130
12166
  for (const [ref, oid] of remote.refs) {
12131
- const parts = ref.split('/');
12132
- const last = parts.pop();
12133
- let o = result;
12134
- for (const part of parts) {
12135
- o[part] = o[part] || {};
12136
- o = o[part];
12137
- }
12138
- o[last] = oid;
12167
+ assignRefPath(result, ref, oid);
12139
12168
  }
12140
12169
  // Merge symrefs on top of refs to more closely match actual git repo layouts
12141
12170
  for (const [symref, ref] of remote.symrefs) {
12142
- const parts = symref.split('/');
12143
- const last = parts.pop();
12144
- let o = result;
12145
- for (const part of parts) {
12146
- o[part] = o[part] || {};
12147
- o = o[part];
12148
- }
12149
- o[last] = ref;
12171
+ assignRefPath(result, symref, ref);
12150
12172
  }
12151
12173
  return result
12152
12174
  } catch (err) {
@@ -14320,6 +14342,7 @@ async function writeReceivePackRequest({
14320
14342
  * @param {boolean} [args.delete = false]
14321
14343
  * @param {string} [args.url]
14322
14344
  * @param {string} [args.corsProxy]
14345
+ * @param {AbortSignal} [args.signal]
14323
14346
  * @param {Object<string, string>} [args.headers]
14324
14347
  *
14325
14348
  * @returns {Promise<PushResult>}
@@ -14343,6 +14366,7 @@ async function _push({
14343
14366
  delete: _delete = false,
14344
14367
  corsProxy,
14345
14368
  headers = {},
14369
+ signal,
14346
14370
  }) {
14347
14371
  const ref = _ref || (await _currentBranch({ fs, gitdir }));
14348
14372
  if (typeof ref === 'undefined') {
@@ -14391,6 +14415,7 @@ async function _push({
14391
14415
  url,
14392
14416
  headers,
14393
14417
  protocolVersion: 1,
14418
+ signal,
14394
14419
  });
14395
14420
  const auth = httpRemote.auth; // hack to get new credentials from CredentialManager API
14396
14421
  let fullRemoteRef;
@@ -14546,6 +14571,7 @@ async function _push({
14546
14571
  auth,
14547
14572
  headers,
14548
14573
  body: [...packstream1, ...packstream2],
14574
+ signal,
14549
14575
  });
14550
14576
  const { packfile, progress } = await GitSideBand.demux(res.body);
14551
14577
  if (onMessage) {
@@ -14622,6 +14648,7 @@ async function _push({
14622
14648
  * @param {string} [args.corsProxy] - Optional [CORS proxy](https://www.npmjs.com/%40isomorphic-git/cors-proxy). Overrides value in repo config.
14623
14649
  * @param {Object<string, string>} [args.headers] - Additional headers to include in HTTP requests, similar to git's `extraHeader` config
14624
14650
  * @param {object} [args.cache] - a [cache](cache.md) object
14651
+ * @param {AbortSignal} [args.signal] - Optional signal to abort the push operation
14625
14652
  *
14626
14653
  * @returns {Promise<PushResult>} Resolves successfully when push completes with a detailed description of the operation from the server.
14627
14654
  * @see PushResult
@@ -14659,6 +14686,7 @@ async function push({
14659
14686
  corsProxy,
14660
14687
  headers = {},
14661
14688
  cache = {},
14689
+ signal,
14662
14690
  }) {
14663
14691
  try {
14664
14692
  assertParameter('fs', fs);
@@ -14686,6 +14714,7 @@ async function push({
14686
14714
  delete: _delete,
14687
14715
  corsProxy,
14688
14716
  headers,
14717
+ signal,
14689
14718
  })
14690
14719
  } catch (err) {
14691
14720
  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
  /**