isomorphic-git 1.44.6 → 1.44.8

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/README.md CHANGED
@@ -465,6 +465,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
465
465
  <td align="center"><a href="https://github.com/snowyukitty"><img src="https://avatars.githubusercontent.com/u/270071858?v=4?s=60" width="60px;" alt=""/><br /><sub><b>snowyukitty</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=snowyukitty" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=snowyukitty" title="Tests">⚠️</a></td>
466
466
  <td align="center"><a href="https://github.com/ShahabAhmed01"><img src="https://avatars.githubusercontent.com/u/192491541?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Shahab Ahmed</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=ShahabAhmed01" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=ShahabAhmed01" title="Tests">⚠️</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=ShahabAhmed01" title="Documentation">📖</a></td>
467
467
  <td align="center"><a href="https://github.com/wleeaf"><img src="https://avatars.githubusercontent.com/u/179125857?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Wleeaf</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=wleeaf" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=wleeaf" title="Tests">⚠️</a></td>
468
+ <td align="center"><a href="https://github.com/SergioSRcode"><img src="https://avatars.githubusercontent.com/u/104135678?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Sergio</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=SergioSRcode" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=SergioSRcode" title="Documentation">📖</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=SergioSRcode" title="Tests">⚠️</a></td>
468
469
  </tr>
469
470
  </table>
470
471
 
package/index.cjs CHANGED
@@ -707,13 +707,25 @@ function parseCacheEntryFlags(bits) {
707
707
  extended: Boolean(bits & 0b0100000000000000),
708
708
  stage: (bits & 0b0011000000000000) >> 12,
709
709
  nameLength: bits & 0b0000111111111111,
710
+ skipWorktree: false,
711
+ intentToAdd: false,
710
712
  }
711
713
  }
712
714
 
715
+ // Bits of the version 3 extended flags field that git understands:
716
+ // 1-bit reserved, 1-bit skip-worktree, 1-bit intent-to-add, 13 unused bits
717
+ const SKIP_WORKTREE = 0b0100000000000000;
718
+ const INTENT_TO_ADD = 0b0010000000000000;
719
+
720
+ function hasExtendedFlags(entry) {
721
+ return Boolean(entry.flags.skipWorktree || entry.flags.intentToAdd)
722
+ }
723
+
713
724
  function renderCacheEntryFlags(entry) {
714
725
  const flags = entry.flags;
715
- // 1-bit extended flag (must be zero in version 2)
716
- flags.extended = false;
726
+ // 1-bit extended flag, set only when the entry needs the extended
727
+ // flags field that version 3 adds
728
+ flags.extended = hasExtendedFlags(entry);
717
729
  // 12-bit name length if the length is less than 0xFFF; otherwise 0xFFF
718
730
  // is stored in this field.
719
731
  flags.nameLength = Math.min(Buffer.from(entry.path).length, 0xfff);
@@ -725,6 +737,13 @@ function renderCacheEntryFlags(entry) {
725
737
  )
726
738
  }
727
739
 
740
+ function renderCacheEntryExtendedFlags(entry) {
741
+ return (
742
+ (entry.flags.skipWorktree ? SKIP_WORKTREE : 0) +
743
+ (entry.flags.intentToAdd ? INTENT_TO_ADD : 0)
744
+ )
745
+ }
746
+
728
747
  class GitIndex {
729
748
  /*::
730
749
  _entries: Map<string, CacheEntry>
@@ -784,7 +803,7 @@ class GitIndex {
784
803
  }
785
804
 
786
805
  const version = reader.readUInt32BE();
787
- if (version !== 2) {
806
+ if (version !== 2 && version !== 3) {
788
807
  throw new InternalError(`Unsupported dircache version: ${version}`)
789
808
  }
790
809
  const numEntries = reader.readUInt32BE();
@@ -804,7 +823,16 @@ class GitIndex {
804
823
  entry.oid = reader.slice(20).toString('hex');
805
824
  const flags = reader.readUInt16BE();
806
825
  entry.flags = parseCacheEntryFlags(flags);
807
- // TODO: handle if (version === 3 && entry.flags.extended)
826
+ if (entry.flags.extended) {
827
+ const extendedFlags = reader.readUInt16BE();
828
+ if (extendedFlags & ~(SKIP_WORKTREE | INTENT_TO_ADD)) {
829
+ throw new InternalError(
830
+ `Unknown index entry format: 0x${extendedFlags.toString(16)}`
831
+ )
832
+ }
833
+ entry.flags.skipWorktree = Boolean(extendedFlags & SKIP_WORKTREE);
834
+ entry.flags.intentToAdd = Boolean(extendedFlags & INTENT_TO_ADD);
835
+ }
808
836
  const pathlength = buffer.indexOf(0, reader.tell() + 1) - reader.tell();
809
837
  if (pathlength < 1) {
810
838
  throw new InternalError(`Got a path length of: ${pathlength}`)
@@ -883,6 +911,9 @@ class GitIndex {
883
911
  }
884
912
  stats = normalizeStats(stats);
885
913
  const bfilepath = Buffer.from(filepath);
914
+ // Keep the skip-worktree bit of a path outside the sparse checkout.
915
+ // Intent-to-add is cleared, since the path is now staged.
916
+ const existing = stage === 0 ? this._entries.get(filepath) : undefined;
886
917
  const entry = {
887
918
  ctimeSeconds: stats.ctimeSeconds,
888
919
  ctimeNanoseconds: stats.ctimeNanoseconds,
@@ -904,6 +935,8 @@ class GitIndex {
904
935
  extended: false,
905
936
  stage,
906
937
  nameLength: bfilepath.length < 0xfff ? bfilepath.length : 0xfff,
938
+ skipWorktree: Boolean(existing?.flags.skipWorktree),
939
+ intentToAdd: false,
907
940
  },
908
941
  stages: [],
909
942
  };
@@ -947,8 +980,11 @@ class GitIndex {
947
980
 
948
981
  static async _entryToBuffer(entry) {
949
982
  const bpath = Buffer.from(entry.path);
950
- // the fixed length + the filename + at least one null char => align by 8
951
- const length = Math.ceil((62 + bpath.length + 1) / 8) * 8;
983
+ const extended = hasExtendedFlags(entry);
984
+ // the fixed length + the extended flags (if any) + the filename + at
985
+ // least one null char => align by 8
986
+ const length =
987
+ Math.ceil((62 + (extended ? 2 : 0) + bpath.length + 1) / 8) * 8;
952
988
  const written = Buffer.alloc(length);
953
989
  const writer = new BufferCursor(written);
954
990
  const stat = normalizeStats(entry);
@@ -964,6 +1000,9 @@ class GitIndex {
964
1000
  writer.writeUInt32BE(stat.size);
965
1001
  writer.write(entry.oid, 20, 'hex');
966
1002
  writer.writeUInt16BE(renderCacheEntryFlags(entry));
1003
+ if (extended) {
1004
+ writer.writeUInt16BE(renderCacheEntryExtendedFlags(entry));
1005
+ }
967
1006
  writer.write(entry.path, bpath.length, 'utf8');
968
1007
  return written
969
1008
  }
@@ -972,7 +1011,8 @@ class GitIndex {
972
1011
  const header = Buffer.alloc(12);
973
1012
  const writer = new BufferCursor(header);
974
1013
  writer.write('DIRC', 4, 'utf8');
975
- writer.writeUInt32BE(2);
1014
+ // Like canonical git, only use version 3 when an entry needs it
1015
+ writer.writeUInt32BE(this.entriesFlat.some(hasExtendedFlags) ? 3 : 2);
976
1016
  writer.writeUInt32BE(this.entriesFlat.length);
977
1017
 
978
1018
  let entryBuffers = [];
@@ -5118,9 +5158,11 @@ class GitWalkerFs {
5118
5158
  // 1) if we can (because the oid and mode are the same)
5119
5159
  // 2) and only if we need to (because other stats differ)
5120
5160
  // 3) and only if the caller opted in to refreshing the index
5161
+ // 4) and not for an intent-to-add entry, which inserting would stage
5121
5162
  if (
5122
5163
  self.refresh &&
5123
5164
  stage &&
5165
+ !stage.flags.intentToAdd &&
5124
5166
  oid === stage.oid &&
5125
5167
  (!filemode || stats.mode === stage.mode) &&
5126
5168
  compareStats(stats, stage, filemode, trustino)
@@ -6628,7 +6670,10 @@ async function _commit({
6628
6670
  return GitIndexManager.acquire(
6629
6671
  { fs, gitdir, cache, allowUnmerged: false },
6630
6672
  async function (index) {
6631
- const inodes = flatFileListToDirectoryStructure(index.entries);
6673
+ // Entries added with `git add --intent-to-add` are not part of the tree
6674
+ const inodes = flatFileListToDirectoryStructure(
6675
+ index.entries.filter(entry => !entry.flags.intentToAdd)
6676
+ );
6632
6677
  const inode = inodes.get('.');
6633
6678
  if (!tree) {
6634
6679
  tree = await constructTree({ fs, gitdir, inode, dryRun });
@@ -9712,13 +9757,25 @@ class GitPktLine {
9712
9757
  const reader = new StreamReader(stream);
9713
9758
  return async function read() {
9714
9759
  try {
9715
- let length = await reader.read(4);
9716
- if (length == null) return true
9717
- length = parseInt(length.toString('utf8'), 16);
9760
+ const header = await reader.read(4);
9761
+ if (header == null || header.length === 0) return true
9762
+ const hex = header.toString('utf8');
9763
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
9764
+ throw new ParseError('four hexadecimal digits', hex)
9765
+ }
9766
+ const length = parseInt(hex, 16);
9718
9767
  if (length === 0) return null
9719
9768
  if (length === 1) return null // delim packets
9769
+ if (length < 4) {
9770
+ throw new ParseError('pkt-line length of 0, 1, or at least 4', hex)
9771
+ }
9720
9772
  const buffer = await reader.read(length - 4);
9721
- if (buffer == null) return true
9773
+ if (buffer == null || buffer.length !== length - 4) {
9774
+ throw new ParseError(
9775
+ `${length - 4} bytes of pkt-line data`,
9776
+ `${buffer == null ? 0 : buffer.length} bytes`
9777
+ )
9778
+ }
9722
9779
  return buffer
9723
9780
  } catch (err) {
9724
9781
  stream.error = err;
@@ -10210,8 +10267,8 @@ function filterCapabilities(server, client) {
10210
10267
 
10211
10268
  const pkg = {
10212
10269
  name: 'isomorphic-git',
10213
- version: '1.44.6',
10214
- agent: 'git/isomorphic-git@1.44.6',
10270
+ version: '1.44.8',
10271
+ agent: 'git/isomorphic-git@1.44.8',
10215
10272
  };
10216
10273
 
10217
10274
  class FIFO {
@@ -17155,8 +17212,14 @@ async function status({
17155
17212
  type: 'blob',
17156
17213
  object,
17157
17214
  });
17158
- // If the oid in the index === working dir oid but stats differed update cache
17159
- if (refresh && I && indexEntry.oid === workdirOid) {
17215
+ // If the oid in the index === working dir oid but stats differed update cache.
17216
+ // An intent-to-add entry is left alone: inserting it again would stage it.
17217
+ if (
17218
+ refresh &&
17219
+ I &&
17220
+ !indexEntry.flags.intentToAdd &&
17221
+ indexEntry.oid === workdirOid
17222
+ ) {
17160
17223
  // and as long as our fs.stats aren't bad.
17161
17224
  // size of -1 happens over a BrowserFS HTTP Backend that doesn't serve Content-Length headers
17162
17225
  // (like the Karma webserver) because BrowserFS HTTP Backend uses HTTP HEAD requests to do fs.stat
package/index.js CHANGED
@@ -700,13 +700,25 @@ function parseCacheEntryFlags(bits) {
700
700
  extended: Boolean(bits & 0b0100000000000000),
701
701
  stage: (bits & 0b0011000000000000) >> 12,
702
702
  nameLength: bits & 0b0000111111111111,
703
+ skipWorktree: false,
704
+ intentToAdd: false,
703
705
  }
704
706
  }
705
707
 
708
+ // Bits of the version 3 extended flags field that git understands:
709
+ // 1-bit reserved, 1-bit skip-worktree, 1-bit intent-to-add, 13 unused bits
710
+ const SKIP_WORKTREE = 0b0100000000000000;
711
+ const INTENT_TO_ADD = 0b0010000000000000;
712
+
713
+ function hasExtendedFlags(entry) {
714
+ return Boolean(entry.flags.skipWorktree || entry.flags.intentToAdd)
715
+ }
716
+
706
717
  function renderCacheEntryFlags(entry) {
707
718
  const flags = entry.flags;
708
- // 1-bit extended flag (must be zero in version 2)
709
- flags.extended = false;
719
+ // 1-bit extended flag, set only when the entry needs the extended
720
+ // flags field that version 3 adds
721
+ flags.extended = hasExtendedFlags(entry);
710
722
  // 12-bit name length if the length is less than 0xFFF; otherwise 0xFFF
711
723
  // is stored in this field.
712
724
  flags.nameLength = Math.min(Buffer.from(entry.path).length, 0xfff);
@@ -718,6 +730,13 @@ function renderCacheEntryFlags(entry) {
718
730
  )
719
731
  }
720
732
 
733
+ function renderCacheEntryExtendedFlags(entry) {
734
+ return (
735
+ (entry.flags.skipWorktree ? SKIP_WORKTREE : 0) +
736
+ (entry.flags.intentToAdd ? INTENT_TO_ADD : 0)
737
+ )
738
+ }
739
+
721
740
  class GitIndex {
722
741
  /*::
723
742
  _entries: Map<string, CacheEntry>
@@ -777,7 +796,7 @@ class GitIndex {
777
796
  }
778
797
 
779
798
  const version = reader.readUInt32BE();
780
- if (version !== 2) {
799
+ if (version !== 2 && version !== 3) {
781
800
  throw new InternalError(`Unsupported dircache version: ${version}`)
782
801
  }
783
802
  const numEntries = reader.readUInt32BE();
@@ -797,7 +816,16 @@ class GitIndex {
797
816
  entry.oid = reader.slice(20).toString('hex');
798
817
  const flags = reader.readUInt16BE();
799
818
  entry.flags = parseCacheEntryFlags(flags);
800
- // TODO: handle if (version === 3 && entry.flags.extended)
819
+ if (entry.flags.extended) {
820
+ const extendedFlags = reader.readUInt16BE();
821
+ if (extendedFlags & ~(SKIP_WORKTREE | INTENT_TO_ADD)) {
822
+ throw new InternalError(
823
+ `Unknown index entry format: 0x${extendedFlags.toString(16)}`
824
+ )
825
+ }
826
+ entry.flags.skipWorktree = Boolean(extendedFlags & SKIP_WORKTREE);
827
+ entry.flags.intentToAdd = Boolean(extendedFlags & INTENT_TO_ADD);
828
+ }
801
829
  const pathlength = buffer.indexOf(0, reader.tell() + 1) - reader.tell();
802
830
  if (pathlength < 1) {
803
831
  throw new InternalError(`Got a path length of: ${pathlength}`)
@@ -876,6 +904,9 @@ class GitIndex {
876
904
  }
877
905
  stats = normalizeStats(stats);
878
906
  const bfilepath = Buffer.from(filepath);
907
+ // Keep the skip-worktree bit of a path outside the sparse checkout.
908
+ // Intent-to-add is cleared, since the path is now staged.
909
+ const existing = stage === 0 ? this._entries.get(filepath) : undefined;
879
910
  const entry = {
880
911
  ctimeSeconds: stats.ctimeSeconds,
881
912
  ctimeNanoseconds: stats.ctimeNanoseconds,
@@ -897,6 +928,8 @@ class GitIndex {
897
928
  extended: false,
898
929
  stage,
899
930
  nameLength: bfilepath.length < 0xfff ? bfilepath.length : 0xfff,
931
+ skipWorktree: Boolean(existing?.flags.skipWorktree),
932
+ intentToAdd: false,
900
933
  },
901
934
  stages: [],
902
935
  };
@@ -940,8 +973,11 @@ class GitIndex {
940
973
 
941
974
  static async _entryToBuffer(entry) {
942
975
  const bpath = Buffer.from(entry.path);
943
- // the fixed length + the filename + at least one null char => align by 8
944
- const length = Math.ceil((62 + bpath.length + 1) / 8) * 8;
976
+ const extended = hasExtendedFlags(entry);
977
+ // the fixed length + the extended flags (if any) + the filename + at
978
+ // least one null char => align by 8
979
+ const length =
980
+ Math.ceil((62 + (extended ? 2 : 0) + bpath.length + 1) / 8) * 8;
945
981
  const written = Buffer.alloc(length);
946
982
  const writer = new BufferCursor(written);
947
983
  const stat = normalizeStats(entry);
@@ -957,6 +993,9 @@ class GitIndex {
957
993
  writer.writeUInt32BE(stat.size);
958
994
  writer.write(entry.oid, 20, 'hex');
959
995
  writer.writeUInt16BE(renderCacheEntryFlags(entry));
996
+ if (extended) {
997
+ writer.writeUInt16BE(renderCacheEntryExtendedFlags(entry));
998
+ }
960
999
  writer.write(entry.path, bpath.length, 'utf8');
961
1000
  return written
962
1001
  }
@@ -965,7 +1004,8 @@ class GitIndex {
965
1004
  const header = Buffer.alloc(12);
966
1005
  const writer = new BufferCursor(header);
967
1006
  writer.write('DIRC', 4, 'utf8');
968
- writer.writeUInt32BE(2);
1007
+ // Like canonical git, only use version 3 when an entry needs it
1008
+ writer.writeUInt32BE(this.entriesFlat.some(hasExtendedFlags) ? 3 : 2);
969
1009
  writer.writeUInt32BE(this.entriesFlat.length);
970
1010
 
971
1011
  let entryBuffers = [];
@@ -5105,9 +5145,11 @@ class GitWalkerFs {
5105
5145
  // 1) if we can (because the oid and mode are the same)
5106
5146
  // 2) and only if we need to (because other stats differ)
5107
5147
  // 3) and only if the caller opted in to refreshing the index
5148
+ // 4) and not for an intent-to-add entry, which inserting would stage
5108
5149
  if (
5109
5150
  self.refresh &&
5110
5151
  stage &&
5152
+ !stage.flags.intentToAdd &&
5111
5153
  oid === stage.oid &&
5112
5154
  (!filemode || stats.mode === stage.mode) &&
5113
5155
  compareStats(stats, stage, filemode, trustino)
@@ -6615,7 +6657,10 @@ async function _commit({
6615
6657
  return GitIndexManager.acquire(
6616
6658
  { fs, gitdir, cache, allowUnmerged: false },
6617
6659
  async function (index) {
6618
- const inodes = flatFileListToDirectoryStructure(index.entries);
6660
+ // Entries added with `git add --intent-to-add` are not part of the tree
6661
+ const inodes = flatFileListToDirectoryStructure(
6662
+ index.entries.filter(entry => !entry.flags.intentToAdd)
6663
+ );
6619
6664
  const inode = inodes.get('.');
6620
6665
  if (!tree) {
6621
6666
  tree = await constructTree({ fs, gitdir, inode, dryRun });
@@ -9699,13 +9744,25 @@ class GitPktLine {
9699
9744
  const reader = new StreamReader(stream);
9700
9745
  return async function read() {
9701
9746
  try {
9702
- let length = await reader.read(4);
9703
- if (length == null) return true
9704
- length = parseInt(length.toString('utf8'), 16);
9747
+ const header = await reader.read(4);
9748
+ if (header == null || header.length === 0) return true
9749
+ const hex = header.toString('utf8');
9750
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
9751
+ throw new ParseError('four hexadecimal digits', hex)
9752
+ }
9753
+ const length = parseInt(hex, 16);
9705
9754
  if (length === 0) return null
9706
9755
  if (length === 1) return null // delim packets
9756
+ if (length < 4) {
9757
+ throw new ParseError('pkt-line length of 0, 1, or at least 4', hex)
9758
+ }
9707
9759
  const buffer = await reader.read(length - 4);
9708
- if (buffer == null) return true
9760
+ if (buffer == null || buffer.length !== length - 4) {
9761
+ throw new ParseError(
9762
+ `${length - 4} bytes of pkt-line data`,
9763
+ `${buffer == null ? 0 : buffer.length} bytes`
9764
+ )
9765
+ }
9709
9766
  return buffer
9710
9767
  } catch (err) {
9711
9768
  stream.error = err;
@@ -10197,8 +10254,8 @@ function filterCapabilities(server, client) {
10197
10254
 
10198
10255
  const pkg = {
10199
10256
  name: 'isomorphic-git',
10200
- version: '1.44.6',
10201
- agent: 'git/isomorphic-git@1.44.6',
10257
+ version: '1.44.8',
10258
+ agent: 'git/isomorphic-git@1.44.8',
10202
10259
  };
10203
10260
 
10204
10261
  class FIFO {
@@ -17142,8 +17199,14 @@ async function status({
17142
17199
  type: 'blob',
17143
17200
  object,
17144
17201
  });
17145
- // If the oid in the index === working dir oid but stats differed update cache
17146
- if (refresh && I && indexEntry.oid === workdirOid) {
17202
+ // If the oid in the index === working dir oid but stats differed update cache.
17203
+ // An intent-to-add entry is left alone: inserting it again would stage it.
17204
+ if (
17205
+ refresh &&
17206
+ I &&
17207
+ !indexEntry.flags.intentToAdd &&
17208
+ indexEntry.oid === workdirOid
17209
+ ) {
17147
17210
  // and as long as our fs.stats aren't bad.
17148
17211
  // size of -1 happens over a BrowserFS HTTP Backend that doesn't serve Content-Length headers
17149
17212
  // (like the Karma webserver) because BrowserFS HTTP Backend uses HTTP HEAD requests to do fs.stat