isomorphic-git 1.39.0 → 1.40.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.cjs CHANGED
@@ -66,6 +66,7 @@ var diff3Merge = _interopDefault(require('diff3'));
66
66
  * @property {string} message Commit message
67
67
  * @property {string} tree SHA-1 object id of corresponding file tree
68
68
  * @property {string[]} parent an array of zero or more SHA-1 object ids
69
+ * @property {Array.<Array.<string|null>>} [changes] Changed files as `[newOid, oldOid, filepath]`; present when `log` is called with `includeChanges: true`.
69
70
  * @property {Object} author
70
71
  * @property {string} author.name The author's name
71
72
  * @property {string} author.email The author's email
@@ -9523,8 +9524,8 @@ function filterCapabilities(server, client) {
9523
9524
 
9524
9525
  const pkg = {
9525
9526
  name: 'isomorphic-git',
9526
- version: '1.39.0',
9527
- agent: 'git/isomorphic-git@1.39.0',
9527
+ version: '1.40.0',
9528
+ agent: 'git/isomorphic-git@1.40.0',
9528
9529
  };
9529
9530
 
9530
9531
  class FIFO {
@@ -13097,7 +13098,7 @@ async function _resolveFileId({
13097
13098
  * @param {number|void} args.depth
13098
13099
  * @param {boolean=} [args.force=false] do not throw error if filepath is not exist (works only for a single file). defaults to false
13099
13100
  * @param {boolean=} [args.follow=false] Continue listing the history of a file beyond renames (works only for a single file). defaults to false
13100
- * @param {boolean=} args.follow Continue listing the history of a file beyond renames (works only for a single file). defaults to false
13101
+ * @param {boolean=} [args.includeChanges=false] Include changed file object ids for each commit.
13101
13102
  *
13102
13103
  * @returns {Promise<Array<ReadCommitResult>>} Resolves to an array of ReadCommitResult objects
13103
13104
  * @see ReadCommitResult
@@ -13118,6 +13119,7 @@ async function _log({
13118
13119
  since,
13119
13120
  force,
13120
13121
  follow,
13122
+ includeChanges,
13121
13123
  }) {
13122
13124
  const sinceTimestamp =
13123
13125
  typeof since === 'undefined'
@@ -13245,9 +13247,57 @@ async function _log({
13245
13247
  // Process tips in order by age
13246
13248
  tips.sort((a, b) => compareAge(a.commit, b.commit));
13247
13249
  }
13250
+ if (includeChanges) {
13251
+ for (const commit of commits) {
13252
+ commit.commit.changes = await getChanges({
13253
+ fs,
13254
+ cache,
13255
+ gitdir,
13256
+ commit,
13257
+ shallow: shallowCommits.has(commit.oid),
13258
+ });
13259
+ }
13260
+ }
13248
13261
  return commits
13249
13262
  }
13250
13263
 
13264
+ async function getChanges({ fs, cache, gitdir, commit, shallow }) {
13265
+ const parent =
13266
+ shallow || !commit.commit.parent[0]
13267
+ ? '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
13268
+ : commit.commit.parent[0];
13269
+ return _walk({
13270
+ fs,
13271
+ cache,
13272
+ gitdir,
13273
+ trees: [TREE({ ref: commit.oid }), TREE({ ref: parent })],
13274
+ map: async (filepath, [current, previous]) => {
13275
+ const [currentType, previousType] = await Promise.all([
13276
+ current && current.type(),
13277
+ previous && previous.type(),
13278
+ ]);
13279
+ if (currentType === 'tree') {
13280
+ if (previousType && previousType !== 'tree') {
13281
+ return [null, await previous.oid(), filepath]
13282
+ }
13283
+ return
13284
+ }
13285
+ if (previousType === 'tree') {
13286
+ if (currentType) {
13287
+ return [await current.oid(), null, filepath]
13288
+ }
13289
+ return
13290
+ }
13291
+ const [newOid, oldOid] = await Promise.all([
13292
+ current ? current.oid() : null,
13293
+ previous ? previous.oid() : null,
13294
+ ]);
13295
+ if (newOid === oldOid) return
13296
+ return [newOid, oldOid, filepath]
13297
+ },
13298
+ })
13299
+ }
13300
+
13251
13301
  // @ts-check
13252
13302
 
13253
13303
  /**
@@ -13263,6 +13313,7 @@ async function _log({
13263
13313
  * @param {Date} [args.since] - Return history newer than the given date. Can be combined with `depth` to get whichever is shorter.
13264
13314
  * @param {boolean=} [args.force=false] do not throw error if filepath is not exist (works only for a single file). defaults to false
13265
13315
  * @param {boolean=} [args.follow=false] Continue listing the history of a file beyond renames (works only for a single file). defaults to false
13316
+ * @param {boolean=} [args.includeChanges=false] Include changed file object ids for each commit. Each tuple is `[newOid, oldOid, filepath]`; an added or removed file has a null old or new oid, respectively.
13266
13317
  * @param {object} [args.cache] - a [cache](cache.md) object
13267
13318
  *
13268
13319
  * @returns {Promise<Array<ReadCommitResult>>} Resolves to an array of ReadCommitResult objects
@@ -13289,6 +13340,7 @@ async function log({
13289
13340
  since, // Date
13290
13341
  force,
13291
13342
  follow,
13343
+ includeChanges = false,
13292
13344
  cache = {},
13293
13345
  }) {
13294
13346
  try {
@@ -13308,6 +13360,7 @@ async function log({
13308
13360
  since,
13309
13361
  force,
13310
13362
  follow,
13363
+ includeChanges,
13311
13364
  })
13312
13365
  } catch (err) {
13313
13366
  err.caller = 'git.log';
package/index.d.cts CHANGED
@@ -354,6 +354,10 @@ export type CommitObject = {
354
354
  * an array of zero or more SHA-1 object ids
355
355
  */
356
356
  parent: string[];
357
+ /**
358
+ * Changed files as `[newOid, oldOid, filepath]`; present when `log` is called with `includeChanges: true`.
359
+ */
360
+ changes?: (string | null)[][] | undefined;
357
361
  author: {
358
362
  name: string;
359
363
  email: string;
@@ -2181,6 +2185,7 @@ export function listTags({ fs, dir, gitdir }: {
2181
2185
  * @param {Date} [args.since] - Return history newer than the given date. Can be combined with `depth` to get whichever is shorter.
2182
2186
  * @param {boolean=} [args.force=false] do not throw error if filepath is not exist (works only for a single file). defaults to false
2183
2187
  * @param {boolean=} [args.follow=false] Continue listing the history of a file beyond renames (works only for a single file). defaults to false
2188
+ * @param {boolean=} [args.includeChanges=false] Include changed file object ids for each commit. Each tuple is `[newOid, oldOid, filepath]`; an added or removed file has a null old or new oid, respectively.
2184
2189
  * @param {object} [args.cache] - a [cache](cache.md) object
2185
2190
  *
2186
2191
  * @returns {Promise<Array<ReadCommitResult>>} Resolves to an array of ReadCommitResult objects
@@ -2197,7 +2202,7 @@ export function listTags({ fs, dir, gitdir }: {
2197
2202
  * console.log(commits)
2198
2203
  *
2199
2204
  */
2200
- export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follow, cache, }: {
2205
+ export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follow, includeChanges, cache, }: {
2201
2206
  fs: FsClient;
2202
2207
  dir?: string | undefined;
2203
2208
  gitdir?: string | undefined;
@@ -2207,6 +2212,7 @@ export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follo
2207
2212
  since?: Date | undefined;
2208
2213
  force?: boolean | undefined;
2209
2214
  follow?: boolean | undefined;
2215
+ includeChanges?: boolean | undefined;
2210
2216
  cache?: object;
2211
2217
  }): Promise<Array<ReadCommitResult>>;
2212
2218
  /**
@@ -4521,6 +4527,7 @@ declare namespace NoCommitError {
4521
4527
  * @property {string} message Commit message
4522
4528
  * @property {string} tree SHA-1 object id of corresponding file tree
4523
4529
  * @property {string[]} parent an array of zero or more SHA-1 object ids
4530
+ * @property {Array.<Array.<string|null>>} [changes] Changed files as `[newOid, oldOid, filepath]`; present when `log` is called with `includeChanges: true`.
4524
4531
  * @property {Object} author
4525
4532
  * @property {string} author.name The author's name
4526
4533
  * @property {string} author.email The author's email
package/index.d.ts CHANGED
@@ -353,6 +353,10 @@ export type CommitObject = {
353
353
  * an array of zero or more SHA-1 object ids
354
354
  */
355
355
  parent: string[];
356
+ /**
357
+ * Changed files as `[newOid, oldOid, filepath]`; present when `log` is called with `includeChanges: true`.
358
+ */
359
+ changes?: (string | null)[][] | undefined;
356
360
  author: {
357
361
  name: string;
358
362
  email: string;
@@ -2180,6 +2184,7 @@ export function listTags({ fs, dir, gitdir }: {
2180
2184
  * @param {Date} [args.since] - Return history newer than the given date. Can be combined with `depth` to get whichever is shorter.
2181
2185
  * @param {boolean=} [args.force=false] do not throw error if filepath is not exist (works only for a single file). defaults to false
2182
2186
  * @param {boolean=} [args.follow=false] Continue listing the history of a file beyond renames (works only for a single file). defaults to false
2187
+ * @param {boolean=} [args.includeChanges=false] Include changed file object ids for each commit. Each tuple is `[newOid, oldOid, filepath]`; an added or removed file has a null old or new oid, respectively.
2183
2188
  * @param {object} [args.cache] - a [cache](cache.md) object
2184
2189
  *
2185
2190
  * @returns {Promise<Array<ReadCommitResult>>} Resolves to an array of ReadCommitResult objects
@@ -2196,7 +2201,7 @@ export function listTags({ fs, dir, gitdir }: {
2196
2201
  * console.log(commits)
2197
2202
  *
2198
2203
  */
2199
- export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follow, cache, }: {
2204
+ export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follow, includeChanges, cache, }: {
2200
2205
  fs: FsClient;
2201
2206
  dir?: string | undefined;
2202
2207
  gitdir?: string | undefined;
@@ -2206,6 +2211,7 @@ export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follo
2206
2211
  since?: Date | undefined;
2207
2212
  force?: boolean | undefined;
2208
2213
  follow?: boolean | undefined;
2214
+ includeChanges?: boolean | undefined;
2209
2215
  cache?: object;
2210
2216
  }): Promise<Array<ReadCommitResult>>;
2211
2217
  /**
@@ -4520,6 +4526,7 @@ declare namespace NoCommitError {
4520
4526
  * @property {string} message Commit message
4521
4527
  * @property {string} tree SHA-1 object id of corresponding file tree
4522
4528
  * @property {string[]} parent an array of zero or more SHA-1 object ids
4529
+ * @property {Array.<Array.<string|null>>} [changes] Changed files as `[newOid, oldOid, filepath]`; present when `log` is called with `includeChanges: true`.
4523
4530
  * @property {Object} author
4524
4531
  * @property {string} author.name The author's name
4525
4532
  * @property {string} author.email The author's email
package/index.js CHANGED
@@ -59,6 +59,7 @@ import diff3Merge from 'diff3';
59
59
  * @property {string} message Commit message
60
60
  * @property {string} tree SHA-1 object id of corresponding file tree
61
61
  * @property {string[]} parent an array of zero or more SHA-1 object ids
62
+ * @property {Array.<Array.<string|null>>} [changes] Changed files as `[newOid, oldOid, filepath]`; present when `log` is called with `includeChanges: true`.
62
63
  * @property {Object} author
63
64
  * @property {string} author.name The author's name
64
65
  * @property {string} author.email The author's email
@@ -9510,8 +9511,8 @@ function filterCapabilities(server, client) {
9510
9511
 
9511
9512
  const pkg = {
9512
9513
  name: 'isomorphic-git',
9513
- version: '1.39.0',
9514
- agent: 'git/isomorphic-git@1.39.0',
9514
+ version: '1.40.0',
9515
+ agent: 'git/isomorphic-git@1.40.0',
9515
9516
  };
9516
9517
 
9517
9518
  class FIFO {
@@ -13084,7 +13085,7 @@ async function _resolveFileId({
13084
13085
  * @param {number|void} args.depth
13085
13086
  * @param {boolean=} [args.force=false] do not throw error if filepath is not exist (works only for a single file). defaults to false
13086
13087
  * @param {boolean=} [args.follow=false] Continue listing the history of a file beyond renames (works only for a single file). defaults to false
13087
- * @param {boolean=} args.follow Continue listing the history of a file beyond renames (works only for a single file). defaults to false
13088
+ * @param {boolean=} [args.includeChanges=false] Include changed file object ids for each commit.
13088
13089
  *
13089
13090
  * @returns {Promise<Array<ReadCommitResult>>} Resolves to an array of ReadCommitResult objects
13090
13091
  * @see ReadCommitResult
@@ -13105,6 +13106,7 @@ async function _log({
13105
13106
  since,
13106
13107
  force,
13107
13108
  follow,
13109
+ includeChanges,
13108
13110
  }) {
13109
13111
  const sinceTimestamp =
13110
13112
  typeof since === 'undefined'
@@ -13232,9 +13234,57 @@ async function _log({
13232
13234
  // Process tips in order by age
13233
13235
  tips.sort((a, b) => compareAge(a.commit, b.commit));
13234
13236
  }
13237
+ if (includeChanges) {
13238
+ for (const commit of commits) {
13239
+ commit.commit.changes = await getChanges({
13240
+ fs,
13241
+ cache,
13242
+ gitdir,
13243
+ commit,
13244
+ shallow: shallowCommits.has(commit.oid),
13245
+ });
13246
+ }
13247
+ }
13235
13248
  return commits
13236
13249
  }
13237
13250
 
13251
+ async function getChanges({ fs, cache, gitdir, commit, shallow }) {
13252
+ const parent =
13253
+ shallow || !commit.commit.parent[0]
13254
+ ? '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
13255
+ : commit.commit.parent[0];
13256
+ return _walk({
13257
+ fs,
13258
+ cache,
13259
+ gitdir,
13260
+ trees: [TREE({ ref: commit.oid }), TREE({ ref: parent })],
13261
+ map: async (filepath, [current, previous]) => {
13262
+ const [currentType, previousType] = await Promise.all([
13263
+ current && current.type(),
13264
+ previous && previous.type(),
13265
+ ]);
13266
+ if (currentType === 'tree') {
13267
+ if (previousType && previousType !== 'tree') {
13268
+ return [null, await previous.oid(), filepath]
13269
+ }
13270
+ return
13271
+ }
13272
+ if (previousType === 'tree') {
13273
+ if (currentType) {
13274
+ return [await current.oid(), null, filepath]
13275
+ }
13276
+ return
13277
+ }
13278
+ const [newOid, oldOid] = await Promise.all([
13279
+ current ? current.oid() : null,
13280
+ previous ? previous.oid() : null,
13281
+ ]);
13282
+ if (newOid === oldOid) return
13283
+ return [newOid, oldOid, filepath]
13284
+ },
13285
+ })
13286
+ }
13287
+
13238
13288
  // @ts-check
13239
13289
 
13240
13290
  /**
@@ -13250,6 +13300,7 @@ async function _log({
13250
13300
  * @param {Date} [args.since] - Return history newer than the given date. Can be combined with `depth` to get whichever is shorter.
13251
13301
  * @param {boolean=} [args.force=false] do not throw error if filepath is not exist (works only for a single file). defaults to false
13252
13302
  * @param {boolean=} [args.follow=false] Continue listing the history of a file beyond renames (works only for a single file). defaults to false
13303
+ * @param {boolean=} [args.includeChanges=false] Include changed file object ids for each commit. Each tuple is `[newOid, oldOid, filepath]`; an added or removed file has a null old or new oid, respectively.
13253
13304
  * @param {object} [args.cache] - a [cache](cache.md) object
13254
13305
  *
13255
13306
  * @returns {Promise<Array<ReadCommitResult>>} Resolves to an array of ReadCommitResult objects
@@ -13276,6 +13327,7 @@ async function log({
13276
13327
  since, // Date
13277
13328
  force,
13278
13329
  follow,
13330
+ includeChanges = false,
13279
13331
  cache = {},
13280
13332
  }) {
13281
13333
  try {
@@ -13295,6 +13347,7 @@ async function log({
13295
13347
  since,
13296
13348
  force,
13297
13349
  follow,
13350
+ includeChanges,
13298
13351
  })
13299
13352
  } catch (err) {
13300
13353
  err.caller = 'git.log';
@@ -353,6 +353,10 @@ export type CommitObject = {
353
353
  * an array of zero or more SHA-1 object ids
354
354
  */
355
355
  parent: string[];
356
+ /**
357
+ * Changed files as `[newOid, oldOid, filepath]`; present when `log` is called with `includeChanges: true`.
358
+ */
359
+ changes?: (string | null)[][] | undefined;
356
360
  author: {
357
361
  name: string;
358
362
  email: string;
@@ -2180,6 +2184,7 @@ export function listTags({ fs, dir, gitdir }: {
2180
2184
  * @param {Date} [args.since] - Return history newer than the given date. Can be combined with `depth` to get whichever is shorter.
2181
2185
  * @param {boolean=} [args.force=false] do not throw error if filepath is not exist (works only for a single file). defaults to false
2182
2186
  * @param {boolean=} [args.follow=false] Continue listing the history of a file beyond renames (works only for a single file). defaults to false
2187
+ * @param {boolean=} [args.includeChanges=false] Include changed file object ids for each commit. Each tuple is `[newOid, oldOid, filepath]`; an added or removed file has a null old or new oid, respectively.
2183
2188
  * @param {object} [args.cache] - a [cache](cache.md) object
2184
2189
  *
2185
2190
  * @returns {Promise<Array<ReadCommitResult>>} Resolves to an array of ReadCommitResult objects
@@ -2196,7 +2201,7 @@ export function listTags({ fs, dir, gitdir }: {
2196
2201
  * console.log(commits)
2197
2202
  *
2198
2203
  */
2199
- export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follow, cache, }: {
2204
+ export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follow, includeChanges, cache, }: {
2200
2205
  fs: FsClient;
2201
2206
  dir?: string | undefined;
2202
2207
  gitdir?: string | undefined;
@@ -2206,6 +2211,7 @@ export function log({ fs, dir, gitdir, filepath, ref, depth, since, force, follo
2206
2211
  since?: Date | undefined;
2207
2212
  force?: boolean | undefined;
2208
2213
  follow?: boolean | undefined;
2214
+ includeChanges?: boolean | undefined;
2209
2215
  cache?: object;
2210
2216
  }): Promise<Array<ReadCommitResult>>;
2211
2217
  /**
@@ -4520,6 +4526,7 @@ declare namespace NoCommitError {
4520
4526
  * @property {string} message Commit message
4521
4527
  * @property {string} tree SHA-1 object id of corresponding file tree
4522
4528
  * @property {string[]} parent an array of zero or more SHA-1 object ids
4529
+ * @property {Array.<Array.<string|null>>} [changes] Changed files as `[newOid, oldOid, filepath]`; present when `log` is called with `includeChanges: true`.
4523
4530
  * @property {Object} author
4524
4531
  * @property {string} author.name The author's name
4525
4532
  * @property {string} author.email The author's email