isomorphic-git 1.28.0 → 1.30.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
@@ -1483,6 +1483,10 @@ function compareRefNames(a, b) {
1483
1483
 
1484
1484
  // This is straight from parse_unit_factor in config.c of canonical git
1485
1485
  const num = val => {
1486
+ if (typeof val === 'number') {
1487
+ return val
1488
+ }
1489
+
1486
1490
  val = val.toLowerCase();
1487
1491
  let n = parseInt(val);
1488
1492
  if (val.endsWith('k')) n *= 1024;
@@ -1493,6 +1497,10 @@ const num = val => {
1493
1497
 
1494
1498
  // This is straight from git_parse_maybe_bool_text in config.c of canonical git
1495
1499
  const bool = val => {
1500
+ if (typeof val === 'boolean') {
1501
+ return val
1502
+ }
1503
+
1496
1504
  val = val.trim().toLowerCase();
1497
1505
  if (val === 'true' || val === 'yes' || val === 'on') return true
1498
1506
  if (val === 'false' || val === 'no' || val === 'off') return false
@@ -1608,6 +1616,7 @@ const normalizePath = path => {
1608
1616
  name,
1609
1617
  path: getPath(section, subsection, name),
1610
1618
  sectionPath: getPath(section, subsection, null),
1619
+ isSection: !!section,
1611
1620
  }
1612
1621
  };
1613
1622
 
@@ -1668,7 +1677,7 @@ class GitConfig {
1668
1677
 
1669
1678
  async getSubsections(section) {
1670
1679
  return this.parsedConfig
1671
- .filter(config => config.section === section && config.isSection)
1680
+ .filter(config => config.isSection && config.section === section)
1672
1681
  .map(config => config.subsection)
1673
1682
  }
1674
1683
 
@@ -1690,7 +1699,9 @@ class GitConfig {
1690
1699
  name,
1691
1700
  path: normalizedPath,
1692
1701
  sectionPath,
1702
+ isSection,
1693
1703
  } = normalizePath(path);
1704
+
1694
1705
  const configIndex = findLastIndex(
1695
1706
  this.parsedConfig,
1696
1707
  config => config.path === normalizedPath
@@ -1732,6 +1743,7 @@ class GitConfig {
1732
1743
  } else {
1733
1744
  // Add a new section
1734
1745
  const newSection = {
1746
+ isSection,
1735
1747
  section,
1736
1748
  subsection,
1737
1749
  modified: true,
@@ -4118,6 +4130,8 @@ class GitWalkerFs {
4118
4130
  this.cache = cache;
4119
4131
  this.dir = dir;
4120
4132
  this.gitdir = gitdir;
4133
+
4134
+ this.config = null;
4121
4135
  const walker = this;
4122
4136
  this.ConstructEntry = class WorkdirEntry {
4123
4137
  constructor(fullpath) {
@@ -4204,7 +4218,7 @@ class GitWalkerFs {
4204
4218
  if ((await entry.type()) === 'tree') {
4205
4219
  entry._content = undefined;
4206
4220
  } else {
4207
- const config = await GitConfigManager.get({ fs, gitdir });
4221
+ const config = await this._getGitConfig(fs, gitdir);
4208
4222
  const autocrlf = await config.get('core.autocrlf');
4209
4223
  const content = await fs.read(`${dir}/${entry._fullpath}`, { autocrlf });
4210
4224
  // workaround for a BrowserFS edge case
@@ -4220,6 +4234,7 @@ class GitWalkerFs {
4220
4234
 
4221
4235
  async oid(entry) {
4222
4236
  if (entry._oid === false) {
4237
+ const self = this;
4223
4238
  const { fs, gitdir, cache } = this;
4224
4239
  let oid;
4225
4240
  // See if we can use the SHA1 hash in the index.
@@ -4228,7 +4243,7 @@ class GitWalkerFs {
4228
4243
  ) {
4229
4244
  const stage = index.entriesMap.get(entry._fullpath);
4230
4245
  const stats = await entry.stat();
4231
- const config = await GitConfigManager.get({ fs, gitdir });
4246
+ const config = await self._getGitConfig(fs, gitdir);
4232
4247
  const filemode = await config.get('core.filemode');
4233
4248
  const trustino =
4234
4249
  typeof process !== 'undefined'
@@ -4267,6 +4282,14 @@ class GitWalkerFs {
4267
4282
  }
4268
4283
  return entry._oid
4269
4284
  }
4285
+
4286
+ async _getGitConfig(fs, gitdir) {
4287
+ if (this.config) {
4288
+ return this.config
4289
+ }
4290
+ this.config = await GitConfigManager.get({ fs, gitdir });
4291
+ return this.config
4292
+ }
4270
4293
  }
4271
4294
 
4272
4295
  // @ts-check
@@ -5060,6 +5083,8 @@ async function add({
5060
5083
 
5061
5084
  const fs = new FileSystem(_fs);
5062
5085
  await GitIndexManager.acquire({ fs, gitdir, cache }, async index => {
5086
+ const config = await GitConfigManager.get({ fs, gitdir });
5087
+ const autocrlf = await config.get('core.autocrlf');
5063
5088
  return addToIndex({
5064
5089
  dir,
5065
5090
  gitdir,
@@ -5068,6 +5093,7 @@ async function add({
5068
5093
  index,
5069
5094
  force,
5070
5095
  parallel,
5096
+ autocrlf,
5071
5097
  })
5072
5098
  });
5073
5099
  } catch (err) {
@@ -5084,6 +5110,7 @@ async function addToIndex({
5084
5110
  index,
5085
5111
  force,
5086
5112
  parallel,
5113
+ autocrlf,
5087
5114
  }) {
5088
5115
  // TODO: Should ignore UNLESS it's already in the index.
5089
5116
  filepath = Array.isArray(filepath) ? filepath : [filepath];
@@ -5112,6 +5139,7 @@ async function addToIndex({
5112
5139
  index,
5113
5140
  force,
5114
5141
  parallel,
5142
+ autocrlf,
5115
5143
  })
5116
5144
  );
5117
5145
  await Promise.all(promises);
@@ -5125,12 +5153,11 @@ async function addToIndex({
5125
5153
  index,
5126
5154
  force,
5127
5155
  parallel,
5156
+ autocrlf,
5128
5157
  });
5129
5158
  }
5130
5159
  }
5131
5160
  } else {
5132
- const config = await GitConfigManager.get({ fs, gitdir });
5133
- const autocrlf = await config.get('core.autocrlf');
5134
5161
  const object = stats.isSymbolicLink()
5135
5162
  ? await fs.readlink(join(dir, currentFilepath)).then(posixifyPathBuffer)
5136
5163
  : await fs.read(join(dir, currentFilepath), { autocrlf });
@@ -7599,8 +7626,8 @@ function filterCapabilities(server, client) {
7599
7626
 
7600
7627
  const pkg = {
7601
7628
  name: 'isomorphic-git',
7602
- version: '1.28.0',
7603
- agent: 'git/isomorphic-git@1.28.0',
7629
+ version: '1.30.0',
7630
+ agent: 'git/isomorphic-git@1.30.0',
7604
7631
  };
7605
7632
 
7606
7633
  class FIFO {
@@ -11064,6 +11091,40 @@ async function listNotes({
11064
11091
 
11065
11092
  // @ts-check
11066
11093
 
11094
+ /**
11095
+ * List refs
11096
+ *
11097
+ * @param {object} args
11098
+ * @param {FsClient} args.fs - a file system client
11099
+ * @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
11100
+ * @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
11101
+ * @param {string} [args.filepath] - [required] The refs path to list
11102
+ *
11103
+ * @returns {Promise<Array<string>>} Resolves successfully with an array of ref names below the supplied `filepath`
11104
+ *
11105
+ * @example
11106
+ * let refs = await git.listRefs({ fs, dir: '/tutorial', filepath: 'refs/heads' })
11107
+ * console.log(refs)
11108
+ *
11109
+ */
11110
+ async function listRefs({
11111
+ fs,
11112
+ dir,
11113
+ gitdir = join(dir, '.git'),
11114
+ filepath,
11115
+ }) {
11116
+ try {
11117
+ assertParameter('fs', fs);
11118
+ assertParameter('gitdir', gitdir);
11119
+ return GitRefManager.listRefs({ fs: new FileSystem(fs), gitdir, filepath })
11120
+ } catch (err) {
11121
+ err.caller = 'git.listRefs';
11122
+ throw err
11123
+ }
11124
+ }
11125
+
11126
+ // @ts-check
11127
+
11067
11128
  /**
11068
11129
  * @param {object} args
11069
11130
  * @param {import('../models/FileSystem.js').FileSystem} args.fs
@@ -16050,6 +16111,7 @@ var index = {
16050
16111
  listBranches,
16051
16112
  listFiles,
16052
16113
  listNotes,
16114
+ listRefs,
16053
16115
  listRemotes,
16054
16116
  listServerRefs,
16055
16117
  listTags,
@@ -16085,4 +16147,4 @@ var index = {
16085
16147
  };
16086
16148
 
16087
16149
  export default index;
16088
- export { Errors, STAGE, TREE, WORKDIR, abortMerge, add, addNote, addRemote, annotatedTag, branch, checkout, clone, commit, currentBranch, deleteBranch, deleteRef, deleteRemote, deleteTag, expandOid, expandRef, fastForward, fetch, findMergeBase, findRoot, getConfig, getConfigAll, getRemoteInfo, getRemoteInfo2, hashBlob, indexPack, init, isDescendent, isIgnored, listBranches, listFiles, listNotes, listRemotes, listServerRefs, listTags, log, merge, packObjects, pull, push, readBlob, readCommit, readNote, readObject, readTag, readTree, remove, removeNote, renameBranch, resetIndex, resolveRef, setConfig, stash, status, statusMatrix, tag, updateIndex, version, walk, writeBlob, writeCommit, writeObject, writeRef, writeTag, writeTree };
16150
+ export { Errors, STAGE, TREE, WORKDIR, abortMerge, add, addNote, addRemote, annotatedTag, branch, checkout, clone, commit, currentBranch, deleteBranch, deleteRef, deleteRemote, deleteTag, expandOid, expandRef, fastForward, fetch, findMergeBase, findRoot, getConfig, getConfigAll, getRemoteInfo, getRemoteInfo2, hashBlob, indexPack, init, isDescendent, isIgnored, listBranches, listFiles, listNotes, listRefs, listRemotes, listServerRefs, listTags, log, merge, packObjects, pull, push, readBlob, readCommit, readNote, readObject, readTag, readTree, remove, removeNote, renameBranch, resetIndex, resolveRef, setConfig, stash, status, statusMatrix, tag, updateIndex, version, walk, writeBlob, writeCommit, writeObject, writeRef, writeTag, writeTree };