isomorphic-git 1.44.13 → 1.44.15
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 +159 -36
- package/index.js +159 -36
- package/index.umd.min.js +1 -1
- package/index.umd.min.js.map +1 -1
- package/managers/index.cjs +60 -3
- package/managers/index.js +60 -3
- package/managers/index.umd.min.js +1 -1
- package/managers/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -1190,7 +1190,16 @@ class GitIndexManager {
|
|
|
1190
1190
|
if (unmergedPaths.length && !allowUnmerged)
|
|
1191
1191
|
throw new UnmergedPathsError(unmergedPaths)
|
|
1192
1192
|
|
|
1193
|
-
|
|
1193
|
+
try {
|
|
1194
|
+
result = await closure(index);
|
|
1195
|
+
} catch (err) {
|
|
1196
|
+
// A failed closure may already have mutated the in-memory index. Drop
|
|
1197
|
+
// it so the next acquire reloads the unchanged index from disk, rather
|
|
1198
|
+
// than flushing a half-applied change that was never written.
|
|
1199
|
+
theIndexCache.map.delete(filepath);
|
|
1200
|
+
theIndexCache.stats.delete(filepath);
|
|
1201
|
+
throw err
|
|
1202
|
+
}
|
|
1194
1203
|
if (index._dirty) {
|
|
1195
1204
|
// Acquire a file lock while we're writing the index file
|
|
1196
1205
|
// let fileLock = await Lock(filepath)
|
|
@@ -1548,16 +1557,45 @@ class GitPackedRefs {
|
|
|
1548
1557
|
}
|
|
1549
1558
|
|
|
1550
1559
|
class GitRefSpec {
|
|
1551
|
-
constructor({
|
|
1560
|
+
constructor({
|
|
1561
|
+
remotePath,
|
|
1562
|
+
remoteSuffix = '',
|
|
1563
|
+
localPath,
|
|
1564
|
+
force,
|
|
1565
|
+
matchPrefix,
|
|
1566
|
+
negative = false,
|
|
1567
|
+
}) {
|
|
1552
1568
|
Object.assign(this, {
|
|
1553
1569
|
remotePath,
|
|
1570
|
+
remoteSuffix,
|
|
1554
1571
|
localPath,
|
|
1555
1572
|
force,
|
|
1556
1573
|
matchPrefix,
|
|
1574
|
+
negative,
|
|
1557
1575
|
});
|
|
1558
1576
|
}
|
|
1559
1577
|
|
|
1560
1578
|
static from(refspec) {
|
|
1579
|
+
// A negative refspec like `^refs/heads/tmp/*` excludes the refs it matches,
|
|
1580
|
+
// and a refspec without a destination like `refs/heads/main` doesn't store
|
|
1581
|
+
// the ref locally.
|
|
1582
|
+
if (refspec.startsWith('^') || !refspec.includes(':')) {
|
|
1583
|
+
const negative = refspec.startsWith('^');
|
|
1584
|
+
const [, forceMatch, remote] = refspec
|
|
1585
|
+
.slice(negative ? 1 : 0)
|
|
1586
|
+
.match(/^(\+?)(.*)$/);
|
|
1587
|
+
// The `*` of a pattern can be followed by the rest of the name, like
|
|
1588
|
+
// `refs/heads/*-tmp`.
|
|
1589
|
+
const star = remote.indexOf('*');
|
|
1590
|
+
return new GitRefSpec({
|
|
1591
|
+
remotePath: star === -1 ? remote : remote.slice(0, star),
|
|
1592
|
+
remoteSuffix: star === -1 ? '' : remote.slice(star + 1),
|
|
1593
|
+
localPath: null,
|
|
1594
|
+
force: forceMatch === '+',
|
|
1595
|
+
matchPrefix: star !== -1,
|
|
1596
|
+
negative,
|
|
1597
|
+
})
|
|
1598
|
+
}
|
|
1561
1599
|
const [forceMatch, remotePath, remoteGlobMatch, localPath, localGlobMatch] =
|
|
1562
1600
|
refspec.match(/^(\+?)(.*?)(\*?):(.*?)(\*?)$/).slice(1);
|
|
1563
1601
|
const force = forceMatch === '+';
|
|
@@ -1577,7 +1615,19 @@ class GitRefSpec {
|
|
|
1577
1615
|
// TODO: We need to run resolveRef on both paths to expand them to their full name.
|
|
1578
1616
|
}
|
|
1579
1617
|
|
|
1618
|
+
matches(remoteBranch) {
|
|
1619
|
+
// Like canonical git, the `*` matches any part of the name, even an empty
|
|
1620
|
+
// one, as long as the prefix and the suffix don't overlap.
|
|
1621
|
+
return this.matchPrefix
|
|
1622
|
+
? remoteBranch.length >=
|
|
1623
|
+
this.remotePath.length + this.remoteSuffix.length &&
|
|
1624
|
+
remoteBranch.startsWith(this.remotePath) &&
|
|
1625
|
+
remoteBranch.endsWith(this.remoteSuffix)
|
|
1626
|
+
: remoteBranch === this.remotePath
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1580
1629
|
translate(remoteBranch) {
|
|
1630
|
+
if (this.localPath === null) return null
|
|
1581
1631
|
if (this.matchPrefix) {
|
|
1582
1632
|
if (remoteBranch.startsWith(this.remotePath)) {
|
|
1583
1633
|
return this.localPath + remoteBranch.replace(this.remotePath, '')
|
|
@@ -1589,6 +1639,7 @@ class GitRefSpec {
|
|
|
1589
1639
|
}
|
|
1590
1640
|
|
|
1591
1641
|
reverseTranslate(localBranch) {
|
|
1642
|
+
if (this.localPath === null) return null
|
|
1592
1643
|
if (this.matchPrefix) {
|
|
1593
1644
|
if (localBranch.startsWith(this.localPath)) {
|
|
1594
1645
|
return this.remotePath + localBranch.replace(this.localPath, '')
|
|
@@ -1618,10 +1669,15 @@ class GitRefSpecSet {
|
|
|
1618
1669
|
this.rules.push(rule);
|
|
1619
1670
|
}
|
|
1620
1671
|
|
|
1672
|
+
isExcluded(remoteRef) {
|
|
1673
|
+
return this.rules.some(rule => rule.negative && rule.matches(remoteRef))
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1621
1676
|
translate(remoteRefs) {
|
|
1622
1677
|
const result = [];
|
|
1623
1678
|
for (const rule of this.rules) {
|
|
1624
1679
|
for (const remoteRef of remoteRefs) {
|
|
1680
|
+
if (this.isExcluded(remoteRef)) continue
|
|
1625
1681
|
const localRef = rule.translate(remoteRef);
|
|
1626
1682
|
if (localRef) {
|
|
1627
1683
|
result.push([remoteRef, localRef]);
|
|
@@ -1633,6 +1689,7 @@ class GitRefSpecSet {
|
|
|
1633
1689
|
|
|
1634
1690
|
translateOne(remoteRef) {
|
|
1635
1691
|
let result = null;
|
|
1692
|
+
if (this.isExcluded(remoteRef)) return result
|
|
1636
1693
|
for (const rule of this.rules) {
|
|
1637
1694
|
const localRef = rule.translate(remoteRef);
|
|
1638
1695
|
if (localRef) {
|
|
@@ -1644,7 +1701,7 @@ class GitRefSpecSet {
|
|
|
1644
1701
|
|
|
1645
1702
|
localNamespaces() {
|
|
1646
1703
|
return this.rules
|
|
1647
|
-
.filter(rule => rule.matchPrefix)
|
|
1704
|
+
.filter(rule => rule.matchPrefix && rule.localPath !== null)
|
|
1648
1705
|
.map(rule => rule.localPath.replace(/\/$/, ''))
|
|
1649
1706
|
}
|
|
1650
1707
|
}
|
|
@@ -5857,6 +5914,31 @@ class FileSystem {
|
|
|
5857
5914
|
}
|
|
5858
5915
|
}
|
|
5859
5916
|
|
|
5917
|
+
/**
|
|
5918
|
+
* Refuse to materialize a working-tree entry whose parent path traverses a
|
|
5919
|
+
* symbolic link. A leading component that is a symlink could otherwise redirect
|
|
5920
|
+
* a write or mkdir outside the working tree. git applies the same check: it does
|
|
5921
|
+
* not follow symlinks in the leading path when writing working-tree files.
|
|
5922
|
+
*
|
|
5923
|
+
* @param {import('../models/FileSystem.js').FileSystem} fs
|
|
5924
|
+
* @param {string} dir
|
|
5925
|
+
* @param {string} fullpath
|
|
5926
|
+
*/
|
|
5927
|
+
async function assertNoSymlinkInLeadingPath(fs, dir, fullpath) {
|
|
5928
|
+
const parts = fullpath.split('/');
|
|
5929
|
+
parts.pop(); // the final segment is the entry being written, not a leading dir
|
|
5930
|
+
let current = dir;
|
|
5931
|
+
for (const part of parts) {
|
|
5932
|
+
if (part === '' || part === '.') continue
|
|
5933
|
+
current = `${current}/${part}`;
|
|
5934
|
+
const stats = await fs.lstat(current);
|
|
5935
|
+
// lstat returns null when the path doesn't exist yet (nothing to traverse).
|
|
5936
|
+
if (stats && stats.isSymbolicLink()) {
|
|
5937
|
+
throw new UnsafeFilepathError(fullpath)
|
|
5938
|
+
}
|
|
5939
|
+
}
|
|
5940
|
+
}
|
|
5941
|
+
|
|
5860
5942
|
function assertParameter(name, value) {
|
|
5861
5943
|
if (value === undefined) {
|
|
5862
5944
|
throw new MissingParameterError(name)
|
|
@@ -5941,6 +6023,50 @@ async function modified(entry, base) {
|
|
|
5941
6023
|
return true
|
|
5942
6024
|
}
|
|
5943
6025
|
|
|
6026
|
+
/**
|
|
6027
|
+
* Materialize one tracked blob in the working tree.
|
|
6028
|
+
*
|
|
6029
|
+
* A symlink must never be followed when writing, neither in the leading path
|
|
6030
|
+
* nor at the destination itself: a tracked symlink can point anywhere, so
|
|
6031
|
+
* following one redirects the write outside the working tree. git behaves the
|
|
6032
|
+
* same way — it replaces the symlink instead of writing through it.
|
|
6033
|
+
*
|
|
6034
|
+
* @param {object} args
|
|
6035
|
+
* @param {import('../models/FileSystem.js').FileSystem} args.fs
|
|
6036
|
+
* @param {string} args.dir - The working tree directory path
|
|
6037
|
+
* @param {string} args.filepath - Path of the entry, relative to `dir`
|
|
6038
|
+
* @param {number} args.mode - The entry's file mode, e.g. 0o100644
|
|
6039
|
+
* @param {Uint8Array|string} args.content - The blob contents
|
|
6040
|
+
* @returns {Promise<void>}
|
|
6041
|
+
*/
|
|
6042
|
+
async function writeWorkingTreeEntry({
|
|
6043
|
+
fs,
|
|
6044
|
+
dir,
|
|
6045
|
+
filepath,
|
|
6046
|
+
mode,
|
|
6047
|
+
content,
|
|
6048
|
+
}) {
|
|
6049
|
+
await assertNoSymlinkInLeadingPath(fs, dir, filepath);
|
|
6050
|
+
const path = `${dir}/${filepath}`;
|
|
6051
|
+
const symlink = mode === 0o120000;
|
|
6052
|
+
// lstat does not follow the final component, so an existing symlink is
|
|
6053
|
+
// removed rather than written through. Removing it first also lets `mode`
|
|
6054
|
+
// take effect, which only happens when the file is created.
|
|
6055
|
+
const stats = await fs.lstat(path);
|
|
6056
|
+
if (stats && (symlink || stats.isSymbolicLink())) {
|
|
6057
|
+
await fs.rm(path);
|
|
6058
|
+
}
|
|
6059
|
+
if (symlink) {
|
|
6060
|
+
// `fs.write` creates the missing parent directories itself, `fs.writelink`
|
|
6061
|
+
// does not. The leading path is already checked above, so creating them
|
|
6062
|
+
// here cannot traverse a symlink either.
|
|
6063
|
+
await fs.mkdir(dirname(path));
|
|
6064
|
+
await fs.writelink(path, Buffer.from(content));
|
|
6065
|
+
} else {
|
|
6066
|
+
await fs.write(path, content, { mode });
|
|
6067
|
+
}
|
|
6068
|
+
}
|
|
6069
|
+
|
|
5944
6070
|
// @ts-check
|
|
5945
6071
|
|
|
5946
6072
|
/**
|
|
@@ -6019,6 +6145,14 @@ async function abortMerge({
|
|
|
6019
6145
|
},
|
|
6020
6146
|
});
|
|
6021
6147
|
|
|
6148
|
+
// Refuse the whole reset before touching the index or the working tree, so
|
|
6149
|
+
// an unsafe path cannot leave either of them half reset.
|
|
6150
|
+
for (const entry of results) {
|
|
6151
|
+
if (entry && entry.type === 'blob') {
|
|
6152
|
+
await assertNoSymlinkInLeadingPath(fs, dir, entry.path);
|
|
6153
|
+
}
|
|
6154
|
+
}
|
|
6155
|
+
|
|
6022
6156
|
await GitIndexManager.acquire(
|
|
6023
6157
|
{ fs, gitdir: updatedGitdir, cache },
|
|
6024
6158
|
async function (index) {
|
|
@@ -6036,14 +6170,25 @@ async function abortMerge({
|
|
|
6036
6170
|
}
|
|
6037
6171
|
|
|
6038
6172
|
if (entry.type === 'blob') {
|
|
6039
|
-
|
|
6040
|
-
|
|
6173
|
+
await writeWorkingTreeEntry({
|
|
6174
|
+
fs,
|
|
6175
|
+
dir,
|
|
6176
|
+
filepath: entry.path,
|
|
6041
6177
|
mode: entry.mode,
|
|
6178
|
+
content: entry.content,
|
|
6042
6179
|
});
|
|
6180
|
+
// Stage the file as it now sits on disk, so the entry does not
|
|
6181
|
+
// look modified afterwards. The mode is the one being restored,
|
|
6182
|
+
// never the one lstat reports: an existing file keeps its old
|
|
6183
|
+
// permissions, because `mode` only applies when a file is
|
|
6184
|
+
// created, and Windows does not report the executable bit.
|
|
6185
|
+
const stats = await fs.lstat(`${dir}/${entry.path}`);
|
|
6186
|
+
stats.mode = entry.mode;
|
|
6043
6187
|
index.insert({
|
|
6044
6188
|
filepath: entry.path,
|
|
6045
6189
|
oid: entry.oid,
|
|
6046
6190
|
stage: 0,
|
|
6191
|
+
stats,
|
|
6047
6192
|
});
|
|
6048
6193
|
}
|
|
6049
6194
|
}
|
|
@@ -7541,31 +7686,6 @@ async function branch({
|
|
|
7541
7686
|
}
|
|
7542
7687
|
}
|
|
7543
7688
|
|
|
7544
|
-
/**
|
|
7545
|
-
* Refuse to materialize a working-tree entry whose parent path traverses a
|
|
7546
|
-
* symbolic link. A leading component that is a symlink could otherwise redirect
|
|
7547
|
-
* a write or mkdir outside the working tree. git applies the same check: it does
|
|
7548
|
-
* not follow symlinks in the leading path when writing working-tree files.
|
|
7549
|
-
*
|
|
7550
|
-
* @param {import('../models/FileSystem.js').FileSystem} fs
|
|
7551
|
-
* @param {string} dir
|
|
7552
|
-
* @param {string} fullpath
|
|
7553
|
-
*/
|
|
7554
|
-
async function assertNoSymlinkInLeadingPath(fs, dir, fullpath) {
|
|
7555
|
-
const parts = fullpath.split('/');
|
|
7556
|
-
parts.pop(); // the final segment is the entry being written, not a leading dir
|
|
7557
|
-
let current = dir;
|
|
7558
|
-
for (const part of parts) {
|
|
7559
|
-
if (part === '' || part === '.') continue
|
|
7560
|
-
current = `${current}/${part}`;
|
|
7561
|
-
const stats = await fs.lstat(current);
|
|
7562
|
-
// lstat returns null when the path doesn't exist yet (nothing to traverse).
|
|
7563
|
-
if (stats && stats.isSymbolicLink()) {
|
|
7564
|
-
throw new UnsafeFilepathError(fullpath)
|
|
7565
|
-
}
|
|
7566
|
-
}
|
|
7567
|
-
}
|
|
7568
|
-
|
|
7569
7689
|
const worthWalking = (filepath, root) => {
|
|
7570
7690
|
if (filepath === '.' || root == null || root.length === 0 || root === '.') {
|
|
7571
7691
|
return true
|
|
@@ -8804,11 +8924,14 @@ async function mergeTree({
|
|
|
8804
8924
|
gitdir,
|
|
8805
8925
|
trees: [TREE({ ref: results.oid })],
|
|
8806
8926
|
map: async function (filepath, [entry]) {
|
|
8807
|
-
const path = `${dir}/${filepath}`;
|
|
8808
8927
|
if ((await entry.type()) === 'blob') {
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8928
|
+
await writeWorkingTreeEntry({
|
|
8929
|
+
fs,
|
|
8930
|
+
dir,
|
|
8931
|
+
filepath,
|
|
8932
|
+
mode: await entry.mode(),
|
|
8933
|
+
content: await entry.content(),
|
|
8934
|
+
});
|
|
8812
8935
|
}
|
|
8813
8936
|
return true
|
|
8814
8937
|
},
|
|
@@ -10302,8 +10425,8 @@ function filterCapabilities(server, client) {
|
|
|
10302
10425
|
|
|
10303
10426
|
const pkg = {
|
|
10304
10427
|
name: 'isomorphic-git',
|
|
10305
|
-
version: '1.44.
|
|
10306
|
-
agent: 'git/isomorphic-git@1.44.
|
|
10428
|
+
version: '1.44.15',
|
|
10429
|
+
agent: 'git/isomorphic-git@1.44.15',
|
|
10307
10430
|
};
|
|
10308
10431
|
|
|
10309
10432
|
class FIFO {
|
package/index.js
CHANGED
|
@@ -1184,7 +1184,16 @@ class GitIndexManager {
|
|
|
1184
1184
|
if (unmergedPaths.length && !allowUnmerged)
|
|
1185
1185
|
throw new UnmergedPathsError(unmergedPaths)
|
|
1186
1186
|
|
|
1187
|
-
|
|
1187
|
+
try {
|
|
1188
|
+
result = await closure(index);
|
|
1189
|
+
} catch (err) {
|
|
1190
|
+
// A failed closure may already have mutated the in-memory index. Drop
|
|
1191
|
+
// it so the next acquire reloads the unchanged index from disk, rather
|
|
1192
|
+
// than flushing a half-applied change that was never written.
|
|
1193
|
+
theIndexCache.map.delete(filepath);
|
|
1194
|
+
theIndexCache.stats.delete(filepath);
|
|
1195
|
+
throw err
|
|
1196
|
+
}
|
|
1188
1197
|
if (index._dirty) {
|
|
1189
1198
|
// Acquire a file lock while we're writing the index file
|
|
1190
1199
|
// let fileLock = await Lock(filepath)
|
|
@@ -1542,16 +1551,45 @@ class GitPackedRefs {
|
|
|
1542
1551
|
}
|
|
1543
1552
|
|
|
1544
1553
|
class GitRefSpec {
|
|
1545
|
-
constructor({
|
|
1554
|
+
constructor({
|
|
1555
|
+
remotePath,
|
|
1556
|
+
remoteSuffix = '',
|
|
1557
|
+
localPath,
|
|
1558
|
+
force,
|
|
1559
|
+
matchPrefix,
|
|
1560
|
+
negative = false,
|
|
1561
|
+
}) {
|
|
1546
1562
|
Object.assign(this, {
|
|
1547
1563
|
remotePath,
|
|
1564
|
+
remoteSuffix,
|
|
1548
1565
|
localPath,
|
|
1549
1566
|
force,
|
|
1550
1567
|
matchPrefix,
|
|
1568
|
+
negative,
|
|
1551
1569
|
});
|
|
1552
1570
|
}
|
|
1553
1571
|
|
|
1554
1572
|
static from(refspec) {
|
|
1573
|
+
// A negative refspec like `^refs/heads/tmp/*` excludes the refs it matches,
|
|
1574
|
+
// and a refspec without a destination like `refs/heads/main` doesn't store
|
|
1575
|
+
// the ref locally.
|
|
1576
|
+
if (refspec.startsWith('^') || !refspec.includes(':')) {
|
|
1577
|
+
const negative = refspec.startsWith('^');
|
|
1578
|
+
const [, forceMatch, remote] = refspec
|
|
1579
|
+
.slice(negative ? 1 : 0)
|
|
1580
|
+
.match(/^(\+?)(.*)$/);
|
|
1581
|
+
// The `*` of a pattern can be followed by the rest of the name, like
|
|
1582
|
+
// `refs/heads/*-tmp`.
|
|
1583
|
+
const star = remote.indexOf('*');
|
|
1584
|
+
return new GitRefSpec({
|
|
1585
|
+
remotePath: star === -1 ? remote : remote.slice(0, star),
|
|
1586
|
+
remoteSuffix: star === -1 ? '' : remote.slice(star + 1),
|
|
1587
|
+
localPath: null,
|
|
1588
|
+
force: forceMatch === '+',
|
|
1589
|
+
matchPrefix: star !== -1,
|
|
1590
|
+
negative,
|
|
1591
|
+
})
|
|
1592
|
+
}
|
|
1555
1593
|
const [forceMatch, remotePath, remoteGlobMatch, localPath, localGlobMatch] =
|
|
1556
1594
|
refspec.match(/^(\+?)(.*?)(\*?):(.*?)(\*?)$/).slice(1);
|
|
1557
1595
|
const force = forceMatch === '+';
|
|
@@ -1571,7 +1609,19 @@ class GitRefSpec {
|
|
|
1571
1609
|
// TODO: We need to run resolveRef on both paths to expand them to their full name.
|
|
1572
1610
|
}
|
|
1573
1611
|
|
|
1612
|
+
matches(remoteBranch) {
|
|
1613
|
+
// Like canonical git, the `*` matches any part of the name, even an empty
|
|
1614
|
+
// one, as long as the prefix and the suffix don't overlap.
|
|
1615
|
+
return this.matchPrefix
|
|
1616
|
+
? remoteBranch.length >=
|
|
1617
|
+
this.remotePath.length + this.remoteSuffix.length &&
|
|
1618
|
+
remoteBranch.startsWith(this.remotePath) &&
|
|
1619
|
+
remoteBranch.endsWith(this.remoteSuffix)
|
|
1620
|
+
: remoteBranch === this.remotePath
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1574
1623
|
translate(remoteBranch) {
|
|
1624
|
+
if (this.localPath === null) return null
|
|
1575
1625
|
if (this.matchPrefix) {
|
|
1576
1626
|
if (remoteBranch.startsWith(this.remotePath)) {
|
|
1577
1627
|
return this.localPath + remoteBranch.replace(this.remotePath, '')
|
|
@@ -1583,6 +1633,7 @@ class GitRefSpec {
|
|
|
1583
1633
|
}
|
|
1584
1634
|
|
|
1585
1635
|
reverseTranslate(localBranch) {
|
|
1636
|
+
if (this.localPath === null) return null
|
|
1586
1637
|
if (this.matchPrefix) {
|
|
1587
1638
|
if (localBranch.startsWith(this.localPath)) {
|
|
1588
1639
|
return this.remotePath + localBranch.replace(this.localPath, '')
|
|
@@ -1612,10 +1663,15 @@ class GitRefSpecSet {
|
|
|
1612
1663
|
this.rules.push(rule);
|
|
1613
1664
|
}
|
|
1614
1665
|
|
|
1666
|
+
isExcluded(remoteRef) {
|
|
1667
|
+
return this.rules.some(rule => rule.negative && rule.matches(remoteRef))
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1615
1670
|
translate(remoteRefs) {
|
|
1616
1671
|
const result = [];
|
|
1617
1672
|
for (const rule of this.rules) {
|
|
1618
1673
|
for (const remoteRef of remoteRefs) {
|
|
1674
|
+
if (this.isExcluded(remoteRef)) continue
|
|
1619
1675
|
const localRef = rule.translate(remoteRef);
|
|
1620
1676
|
if (localRef) {
|
|
1621
1677
|
result.push([remoteRef, localRef]);
|
|
@@ -1627,6 +1683,7 @@ class GitRefSpecSet {
|
|
|
1627
1683
|
|
|
1628
1684
|
translateOne(remoteRef) {
|
|
1629
1685
|
let result = null;
|
|
1686
|
+
if (this.isExcluded(remoteRef)) return result
|
|
1630
1687
|
for (const rule of this.rules) {
|
|
1631
1688
|
const localRef = rule.translate(remoteRef);
|
|
1632
1689
|
if (localRef) {
|
|
@@ -1638,7 +1695,7 @@ class GitRefSpecSet {
|
|
|
1638
1695
|
|
|
1639
1696
|
localNamespaces() {
|
|
1640
1697
|
return this.rules
|
|
1641
|
-
.filter(rule => rule.matchPrefix)
|
|
1698
|
+
.filter(rule => rule.matchPrefix && rule.localPath !== null)
|
|
1642
1699
|
.map(rule => rule.localPath.replace(/\/$/, ''))
|
|
1643
1700
|
}
|
|
1644
1701
|
}
|
|
@@ -5845,6 +5902,31 @@ class FileSystem {
|
|
|
5845
5902
|
}
|
|
5846
5903
|
}
|
|
5847
5904
|
|
|
5905
|
+
/**
|
|
5906
|
+
* Refuse to materialize a working-tree entry whose parent path traverses a
|
|
5907
|
+
* symbolic link. A leading component that is a symlink could otherwise redirect
|
|
5908
|
+
* a write or mkdir outside the working tree. git applies the same check: it does
|
|
5909
|
+
* not follow symlinks in the leading path when writing working-tree files.
|
|
5910
|
+
*
|
|
5911
|
+
* @param {import('../models/FileSystem.js').FileSystem} fs
|
|
5912
|
+
* @param {string} dir
|
|
5913
|
+
* @param {string} fullpath
|
|
5914
|
+
*/
|
|
5915
|
+
async function assertNoSymlinkInLeadingPath(fs, dir, fullpath) {
|
|
5916
|
+
const parts = fullpath.split('/');
|
|
5917
|
+
parts.pop(); // the final segment is the entry being written, not a leading dir
|
|
5918
|
+
let current = dir;
|
|
5919
|
+
for (const part of parts) {
|
|
5920
|
+
if (part === '' || part === '.') continue
|
|
5921
|
+
current = `${current}/${part}`;
|
|
5922
|
+
const stats = await fs.lstat(current);
|
|
5923
|
+
// lstat returns null when the path doesn't exist yet (nothing to traverse).
|
|
5924
|
+
if (stats && stats.isSymbolicLink()) {
|
|
5925
|
+
throw new UnsafeFilepathError(fullpath)
|
|
5926
|
+
}
|
|
5927
|
+
}
|
|
5928
|
+
}
|
|
5929
|
+
|
|
5848
5930
|
function assertParameter(name, value) {
|
|
5849
5931
|
if (value === undefined) {
|
|
5850
5932
|
throw new MissingParameterError(name)
|
|
@@ -5929,6 +6011,50 @@ async function modified(entry, base) {
|
|
|
5929
6011
|
return true
|
|
5930
6012
|
}
|
|
5931
6013
|
|
|
6014
|
+
/**
|
|
6015
|
+
* Materialize one tracked blob in the working tree.
|
|
6016
|
+
*
|
|
6017
|
+
* A symlink must never be followed when writing, neither in the leading path
|
|
6018
|
+
* nor at the destination itself: a tracked symlink can point anywhere, so
|
|
6019
|
+
* following one redirects the write outside the working tree. git behaves the
|
|
6020
|
+
* same way — it replaces the symlink instead of writing through it.
|
|
6021
|
+
*
|
|
6022
|
+
* @param {object} args
|
|
6023
|
+
* @param {import('../models/FileSystem.js').FileSystem} args.fs
|
|
6024
|
+
* @param {string} args.dir - The working tree directory path
|
|
6025
|
+
* @param {string} args.filepath - Path of the entry, relative to `dir`
|
|
6026
|
+
* @param {number} args.mode - The entry's file mode, e.g. 0o100644
|
|
6027
|
+
* @param {Uint8Array|string} args.content - The blob contents
|
|
6028
|
+
* @returns {Promise<void>}
|
|
6029
|
+
*/
|
|
6030
|
+
async function writeWorkingTreeEntry({
|
|
6031
|
+
fs,
|
|
6032
|
+
dir,
|
|
6033
|
+
filepath,
|
|
6034
|
+
mode,
|
|
6035
|
+
content,
|
|
6036
|
+
}) {
|
|
6037
|
+
await assertNoSymlinkInLeadingPath(fs, dir, filepath);
|
|
6038
|
+
const path = `${dir}/${filepath}`;
|
|
6039
|
+
const symlink = mode === 0o120000;
|
|
6040
|
+
// lstat does not follow the final component, so an existing symlink is
|
|
6041
|
+
// removed rather than written through. Removing it first also lets `mode`
|
|
6042
|
+
// take effect, which only happens when the file is created.
|
|
6043
|
+
const stats = await fs.lstat(path);
|
|
6044
|
+
if (stats && (symlink || stats.isSymbolicLink())) {
|
|
6045
|
+
await fs.rm(path);
|
|
6046
|
+
}
|
|
6047
|
+
if (symlink) {
|
|
6048
|
+
// `fs.write` creates the missing parent directories itself, `fs.writelink`
|
|
6049
|
+
// does not. The leading path is already checked above, so creating them
|
|
6050
|
+
// here cannot traverse a symlink either.
|
|
6051
|
+
await fs.mkdir(dirname(path));
|
|
6052
|
+
await fs.writelink(path, Buffer.from(content));
|
|
6053
|
+
} else {
|
|
6054
|
+
await fs.write(path, content, { mode });
|
|
6055
|
+
}
|
|
6056
|
+
}
|
|
6057
|
+
|
|
5932
6058
|
// @ts-check
|
|
5933
6059
|
|
|
5934
6060
|
/**
|
|
@@ -6007,6 +6133,14 @@ async function abortMerge({
|
|
|
6007
6133
|
},
|
|
6008
6134
|
});
|
|
6009
6135
|
|
|
6136
|
+
// Refuse the whole reset before touching the index or the working tree, so
|
|
6137
|
+
// an unsafe path cannot leave either of them half reset.
|
|
6138
|
+
for (const entry of results) {
|
|
6139
|
+
if (entry && entry.type === 'blob') {
|
|
6140
|
+
await assertNoSymlinkInLeadingPath(fs, dir, entry.path);
|
|
6141
|
+
}
|
|
6142
|
+
}
|
|
6143
|
+
|
|
6010
6144
|
await GitIndexManager.acquire(
|
|
6011
6145
|
{ fs, gitdir: updatedGitdir, cache },
|
|
6012
6146
|
async function (index) {
|
|
@@ -6024,14 +6158,25 @@ async function abortMerge({
|
|
|
6024
6158
|
}
|
|
6025
6159
|
|
|
6026
6160
|
if (entry.type === 'blob') {
|
|
6027
|
-
|
|
6028
|
-
|
|
6161
|
+
await writeWorkingTreeEntry({
|
|
6162
|
+
fs,
|
|
6163
|
+
dir,
|
|
6164
|
+
filepath: entry.path,
|
|
6029
6165
|
mode: entry.mode,
|
|
6166
|
+
content: entry.content,
|
|
6030
6167
|
});
|
|
6168
|
+
// Stage the file as it now sits on disk, so the entry does not
|
|
6169
|
+
// look modified afterwards. The mode is the one being restored,
|
|
6170
|
+
// never the one lstat reports: an existing file keeps its old
|
|
6171
|
+
// permissions, because `mode` only applies when a file is
|
|
6172
|
+
// created, and Windows does not report the executable bit.
|
|
6173
|
+
const stats = await fs.lstat(`${dir}/${entry.path}`);
|
|
6174
|
+
stats.mode = entry.mode;
|
|
6031
6175
|
index.insert({
|
|
6032
6176
|
filepath: entry.path,
|
|
6033
6177
|
oid: entry.oid,
|
|
6034
6178
|
stage: 0,
|
|
6179
|
+
stats,
|
|
6035
6180
|
});
|
|
6036
6181
|
}
|
|
6037
6182
|
}
|
|
@@ -7529,31 +7674,6 @@ async function branch({
|
|
|
7529
7674
|
}
|
|
7530
7675
|
}
|
|
7531
7676
|
|
|
7532
|
-
/**
|
|
7533
|
-
* Refuse to materialize a working-tree entry whose parent path traverses a
|
|
7534
|
-
* symbolic link. A leading component that is a symlink could otherwise redirect
|
|
7535
|
-
* a write or mkdir outside the working tree. git applies the same check: it does
|
|
7536
|
-
* not follow symlinks in the leading path when writing working-tree files.
|
|
7537
|
-
*
|
|
7538
|
-
* @param {import('../models/FileSystem.js').FileSystem} fs
|
|
7539
|
-
* @param {string} dir
|
|
7540
|
-
* @param {string} fullpath
|
|
7541
|
-
*/
|
|
7542
|
-
async function assertNoSymlinkInLeadingPath(fs, dir, fullpath) {
|
|
7543
|
-
const parts = fullpath.split('/');
|
|
7544
|
-
parts.pop(); // the final segment is the entry being written, not a leading dir
|
|
7545
|
-
let current = dir;
|
|
7546
|
-
for (const part of parts) {
|
|
7547
|
-
if (part === '' || part === '.') continue
|
|
7548
|
-
current = `${current}/${part}`;
|
|
7549
|
-
const stats = await fs.lstat(current);
|
|
7550
|
-
// lstat returns null when the path doesn't exist yet (nothing to traverse).
|
|
7551
|
-
if (stats && stats.isSymbolicLink()) {
|
|
7552
|
-
throw new UnsafeFilepathError(fullpath)
|
|
7553
|
-
}
|
|
7554
|
-
}
|
|
7555
|
-
}
|
|
7556
|
-
|
|
7557
7677
|
const worthWalking = (filepath, root) => {
|
|
7558
7678
|
if (filepath === '.' || root == null || root.length === 0 || root === '.') {
|
|
7559
7679
|
return true
|
|
@@ -8792,11 +8912,14 @@ async function mergeTree({
|
|
|
8792
8912
|
gitdir,
|
|
8793
8913
|
trees: [TREE({ ref: results.oid })],
|
|
8794
8914
|
map: async function (filepath, [entry]) {
|
|
8795
|
-
const path = `${dir}/${filepath}`;
|
|
8796
8915
|
if ((await entry.type()) === 'blob') {
|
|
8797
|
-
|
|
8798
|
-
|
|
8799
|
-
|
|
8916
|
+
await writeWorkingTreeEntry({
|
|
8917
|
+
fs,
|
|
8918
|
+
dir,
|
|
8919
|
+
filepath,
|
|
8920
|
+
mode: await entry.mode(),
|
|
8921
|
+
content: await entry.content(),
|
|
8922
|
+
});
|
|
8800
8923
|
}
|
|
8801
8924
|
return true
|
|
8802
8925
|
},
|
|
@@ -10290,8 +10413,8 @@ function filterCapabilities(server, client) {
|
|
|
10290
10413
|
|
|
10291
10414
|
const pkg = {
|
|
10292
10415
|
name: 'isomorphic-git',
|
|
10293
|
-
version: '1.44.
|
|
10294
|
-
agent: 'git/isomorphic-git@1.44.
|
|
10416
|
+
version: '1.44.15',
|
|
10417
|
+
agent: 'git/isomorphic-git@1.44.15',
|
|
10295
10418
|
};
|
|
10296
10419
|
|
|
10297
10420
|
class FIFO {
|