isomorphic-git 1.40.1 → 1.40.3

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
@@ -5765,6 +5765,18 @@ async function add({
5765
5765
  }
5766
5766
  }
5767
5767
 
5768
+ // True for a path the index already holds, and for a folder holding one. The
5769
+ // exact lookup is a Map hit; the prefix scan only runs for folders, since a
5770
+ // tracked file always answers on the first check.
5771
+ function isTracked(index, filepath) {
5772
+ if (index.has({ filepath })) return true
5773
+ const prefix = `${filepath}/`;
5774
+ for (const entry of index.entriesMap.keys()) {
5775
+ if (entry.startsWith(prefix)) return true
5776
+ }
5777
+ return false
5778
+ }
5779
+
5768
5780
  async function addToIndex({
5769
5781
  dir,
5770
5782
  gitdir,
@@ -5775,10 +5787,13 @@ async function addToIndex({
5775
5787
  parallel,
5776
5788
  autocrlf,
5777
5789
  }) {
5778
- // TODO: Should ignore UNLESS it's already in the index.
5779
5790
  filepath = Array.isArray(filepath) ? filepath : [filepath];
5780
5791
  const promises = filepath.map(async currentFilepath => {
5781
- if (!force) {
5792
+ // .gitignore governs untracked paths. Once a path is in the index, adding a
5793
+ // matching rule does not stop canonical git from staging further changes,
5794
+ // and an ignored folder is still walked for the sake of what it tracks:
5795
+ // the recursion below re-checks every child, so only tracked ones get in.
5796
+ if (!force && !isTracked(index, currentFilepath)) {
5782
5797
  const ignored = await GitIgnoreManager.isIgnored({
5783
5798
  fs,
5784
5799
  dir,
@@ -9557,8 +9572,8 @@ function filterCapabilities(server, client) {
9557
9572
 
9558
9573
  const pkg = {
9559
9574
  name: 'isomorphic-git',
9560
- version: '1.40.1',
9561
- agent: 'git/isomorphic-git@1.40.1',
9575
+ version: '1.40.3',
9576
+ agent: 'git/isomorphic-git@1.40.3',
9562
9577
  };
9563
9578
 
9564
9579
  class FIFO {
@@ -16341,15 +16356,6 @@ async function status({
16341
16356
 
16342
16357
  const fs = new FileSystem(_fs);
16343
16358
  const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
16344
- const ignored = await GitIgnoreManager.isIgnored({
16345
- fs,
16346
- gitdir: updatedGitdir,
16347
- dir,
16348
- filepath,
16349
- });
16350
- if (ignored) {
16351
- return 'ignored'
16352
- }
16353
16359
  const headTree = await getHeadTree({ fs, cache, gitdir: updatedGitdir });
16354
16360
  const treeOid = await getOidAtPath({
16355
16361
  fs,
@@ -16367,6 +16373,20 @@ async function status({
16367
16373
  return null
16368
16374
  }
16369
16375
  );
16376
+ // .gitignore governs untracked files. A file in HEAD or in the index is
16377
+ // tracked, so canonical git keeps reporting its real state, and
16378
+ // `git check-ignore` does not match it. statusMatrix already does this.
16379
+ if (treeOid === null && indexEntry === null) {
16380
+ const ignored = await GitIgnoreManager.isIgnored({
16381
+ fs,
16382
+ gitdir: updatedGitdir,
16383
+ dir,
16384
+ filepath,
16385
+ });
16386
+ if (ignored) {
16387
+ return 'ignored'
16388
+ }
16389
+ }
16370
16390
  const stats = await fs.lstat(join(dir, filepath));
16371
16391
 
16372
16392
  const H = treeOid !== null; // head
@@ -16377,7 +16397,12 @@ async function status({
16377
16397
  if (I && !compareStats(indexEntry, stats)) {
16378
16398
  return indexEntry.oid
16379
16399
  } else {
16380
- const object = await fs.read(join(dir, filepath));
16400
+ // Read through the same core.autocrlf normalisation GitWalkerFs uses,
16401
+ // so the working copy hashes to the blob that was stored. Without it a
16402
+ // CRLF checkout of an LF blob reads as modified.
16403
+ const config = await GitConfigManager.get({ fs, gitdir: updatedGitdir });
16404
+ const autocrlf = await config.get('core.autocrlf');
16405
+ const object = await fs.read(join(dir, filepath), { autocrlf });
16381
16406
  const workdirOid = await hashObject$1({
16382
16407
  gitdir: updatedGitdir,
16383
16408
  type: 'blob',
package/index.js CHANGED
@@ -5752,6 +5752,18 @@ async function add({
5752
5752
  }
5753
5753
  }
5754
5754
 
5755
+ // True for a path the index already holds, and for a folder holding one. The
5756
+ // exact lookup is a Map hit; the prefix scan only runs for folders, since a
5757
+ // tracked file always answers on the first check.
5758
+ function isTracked(index, filepath) {
5759
+ if (index.has({ filepath })) return true
5760
+ const prefix = `${filepath}/`;
5761
+ for (const entry of index.entriesMap.keys()) {
5762
+ if (entry.startsWith(prefix)) return true
5763
+ }
5764
+ return false
5765
+ }
5766
+
5755
5767
  async function addToIndex({
5756
5768
  dir,
5757
5769
  gitdir,
@@ -5762,10 +5774,13 @@ async function addToIndex({
5762
5774
  parallel,
5763
5775
  autocrlf,
5764
5776
  }) {
5765
- // TODO: Should ignore UNLESS it's already in the index.
5766
5777
  filepath = Array.isArray(filepath) ? filepath : [filepath];
5767
5778
  const promises = filepath.map(async currentFilepath => {
5768
- if (!force) {
5779
+ // .gitignore governs untracked paths. Once a path is in the index, adding a
5780
+ // matching rule does not stop canonical git from staging further changes,
5781
+ // and an ignored folder is still walked for the sake of what it tracks:
5782
+ // the recursion below re-checks every child, so only tracked ones get in.
5783
+ if (!force && !isTracked(index, currentFilepath)) {
5769
5784
  const ignored = await GitIgnoreManager.isIgnored({
5770
5785
  fs,
5771
5786
  dir,
@@ -9544,8 +9559,8 @@ function filterCapabilities(server, client) {
9544
9559
 
9545
9560
  const pkg = {
9546
9561
  name: 'isomorphic-git',
9547
- version: '1.40.1',
9548
- agent: 'git/isomorphic-git@1.40.1',
9562
+ version: '1.40.3',
9563
+ agent: 'git/isomorphic-git@1.40.3',
9549
9564
  };
9550
9565
 
9551
9566
  class FIFO {
@@ -16328,15 +16343,6 @@ async function status({
16328
16343
 
16329
16344
  const fs = new FileSystem(_fs);
16330
16345
  const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir });
16331
- const ignored = await GitIgnoreManager.isIgnored({
16332
- fs,
16333
- gitdir: updatedGitdir,
16334
- dir,
16335
- filepath,
16336
- });
16337
- if (ignored) {
16338
- return 'ignored'
16339
- }
16340
16346
  const headTree = await getHeadTree({ fs, cache, gitdir: updatedGitdir });
16341
16347
  const treeOid = await getOidAtPath({
16342
16348
  fs,
@@ -16354,6 +16360,20 @@ async function status({
16354
16360
  return null
16355
16361
  }
16356
16362
  );
16363
+ // .gitignore governs untracked files. A file in HEAD or in the index is
16364
+ // tracked, so canonical git keeps reporting its real state, and
16365
+ // `git check-ignore` does not match it. statusMatrix already does this.
16366
+ if (treeOid === null && indexEntry === null) {
16367
+ const ignored = await GitIgnoreManager.isIgnored({
16368
+ fs,
16369
+ gitdir: updatedGitdir,
16370
+ dir,
16371
+ filepath,
16372
+ });
16373
+ if (ignored) {
16374
+ return 'ignored'
16375
+ }
16376
+ }
16357
16377
  const stats = await fs.lstat(join(dir, filepath));
16358
16378
 
16359
16379
  const H = treeOid !== null; // head
@@ -16364,7 +16384,12 @@ async function status({
16364
16384
  if (I && !compareStats(indexEntry, stats)) {
16365
16385
  return indexEntry.oid
16366
16386
  } else {
16367
- const object = await fs.read(join(dir, filepath));
16387
+ // Read through the same core.autocrlf normalisation GitWalkerFs uses,
16388
+ // so the working copy hashes to the blob that was stored. Without it a
16389
+ // CRLF checkout of an LF blob reads as modified.
16390
+ const config = await GitConfigManager.get({ fs, gitdir: updatedGitdir });
16391
+ const autocrlf = await config.get('core.autocrlf');
16392
+ const object = await fs.read(join(dir, filepath), { autocrlf });
16368
16393
  const workdirOid = await hashObject$1({
16369
16394
  gitdir: updatedGitdir,
16370
16395
  type: 'blob',