isomorphic-git 1.14.0 → 1.15.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/README.md +1 -0
- package/browser-tests.json +2 -2
- package/index.cjs +167 -3
- package/index.d.ts +57 -3
- package/index.js +167 -4
- package/index.umd.min.d.ts +57 -3
- package/index.umd.min.js +2 -2
- package/index.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/size_report.html +1 -1
package/README.md
CHANGED
|
@@ -195,6 +195,7 @@ unless there is a major version bump.
|
|
|
195
195
|
- [status](https://isomorphic-git.github.io/docs/status.html)
|
|
196
196
|
- [statusMatrix](https://isomorphic-git.github.io/docs/statusMatrix.html)
|
|
197
197
|
- [tag](https://isomorphic-git.github.io/docs/tag.html)
|
|
198
|
+
- [updateIndex](https://isomorphic-git.github.io/docs/updateIndex.html)
|
|
198
199
|
- [version](https://isomorphic-git.github.io/docs/version.html)
|
|
199
200
|
- [walk](https://isomorphic-git.github.io/docs/walk.html)
|
|
200
201
|
- [writeBlob](https://isomorphic-git.github.io/docs/writeBlob.html)
|
package/browser-tests.json
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
"Firefox 97.0.0 (Ubuntu 0.0.0)",
|
|
4
4
|
"Chrome Mobile 96.0.4664 (Android 0.0.0)",
|
|
5
5
|
"Chrome 79.0.3945 (Windows 10 0.0.0)",
|
|
6
|
-
"Safari 13.
|
|
7
|
-
"
|
|
6
|
+
"Mobile Safari 13.0.0 (iOS 13.0.0)",
|
|
7
|
+
"Safari 13.1.0 (Mac OS X 10.15.4)"
|
|
8
8
|
]
|
package/index.cjs
CHANGED
|
@@ -762,6 +762,10 @@ class GitIndex {
|
|
|
762
762
|
this._dirty = true;
|
|
763
763
|
}
|
|
764
764
|
|
|
765
|
+
has({ filepath }) {
|
|
766
|
+
return this._entries.has(filepath)
|
|
767
|
+
}
|
|
768
|
+
|
|
765
769
|
render() {
|
|
766
770
|
return this.entries
|
|
767
771
|
.map(entry => `${entry.mode.toString(8)} ${entry.oid} ${entry.path}`)
|
|
@@ -3119,12 +3123,14 @@ HttpError.code = 'HttpError';
|
|
|
3119
3123
|
|
|
3120
3124
|
class InvalidFilepathError extends BaseError {
|
|
3121
3125
|
/**
|
|
3122
|
-
* @param {'leading-slash'|'trailing-slash'} [reason]
|
|
3126
|
+
* @param {'leading-slash'|'trailing-slash'|'directory'} [reason]
|
|
3123
3127
|
*/
|
|
3124
3128
|
constructor(reason) {
|
|
3125
3129
|
let message = 'invalid filepath';
|
|
3126
3130
|
if (reason === 'leading-slash' || reason === 'trailing-slash') {
|
|
3127
3131
|
message = `"filepath" parameter should not include leading or trailing directory separators because these can cause problems on some platforms.`;
|
|
3132
|
+
} else if (reason === 'directory') {
|
|
3133
|
+
message = `"filepath" should not be a directory.`;
|
|
3128
3134
|
}
|
|
3129
3135
|
super(message);
|
|
3130
3136
|
this.code = this.name = InvalidFilepathError.code;
|
|
@@ -6912,8 +6918,8 @@ function filterCapabilities(server, client) {
|
|
|
6912
6918
|
|
|
6913
6919
|
const pkg = {
|
|
6914
6920
|
name: 'isomorphic-git',
|
|
6915
|
-
version: '1.
|
|
6916
|
-
agent: 'git/isomorphic-git@1.
|
|
6921
|
+
version: '1.15.0',
|
|
6922
|
+
agent: 'git/isomorphic-git@1.15.0',
|
|
6917
6923
|
};
|
|
6918
6924
|
|
|
6919
6925
|
class FIFO {
|
|
@@ -13489,6 +13495,162 @@ async function tag({
|
|
|
13489
13495
|
|
|
13490
13496
|
// @ts-check
|
|
13491
13497
|
|
|
13498
|
+
/**
|
|
13499
|
+
* Register file contents in the working tree or object database to the git index (aka staging area).
|
|
13500
|
+
*
|
|
13501
|
+
* @param {object} args
|
|
13502
|
+
* @param {FsClient} args.fs - a file system client
|
|
13503
|
+
* @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
|
|
13504
|
+
* @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
|
|
13505
|
+
* @param {string} args.filepath - File to act upon.
|
|
13506
|
+
* @param {string} [args.oid] - OID of the object in the object database to add to the index with the specified filepath.
|
|
13507
|
+
* @param {number} [args.mode = 100644] - The file mode to add the file to the index.
|
|
13508
|
+
* @param {boolean} [args.add] - Adds the specified file to the index if it does not yet exist in the index.
|
|
13509
|
+
* @param {boolean} [args.remove] - Remove the specified file from the index if it does not exist in the workspace anymore.
|
|
13510
|
+
* @param {boolean} [args.force] - Remove the specified file from the index, even if it still exists in the workspace.
|
|
13511
|
+
* @param {object} [args.cache] - a [cache](cache.md) object
|
|
13512
|
+
*
|
|
13513
|
+
* @returns {Promise<string | void>} Resolves successfully with the SHA-1 object id of the object written or updated in the index, or nothing if the file was removed.
|
|
13514
|
+
*
|
|
13515
|
+
* @example
|
|
13516
|
+
* await git.updateIndex({
|
|
13517
|
+
* fs,
|
|
13518
|
+
* dir: '/tutorial',
|
|
13519
|
+
* filepath: 'readme.md'
|
|
13520
|
+
* })
|
|
13521
|
+
*
|
|
13522
|
+
* @example
|
|
13523
|
+
* // Manually create a blob in the object database.
|
|
13524
|
+
* let oid = await git.writeBlob({
|
|
13525
|
+
* fs,
|
|
13526
|
+
* dir: '/tutorial',
|
|
13527
|
+
* blob: new Uint8Array([])
|
|
13528
|
+
* })
|
|
13529
|
+
*
|
|
13530
|
+
* // Write the object in the object database to the index.
|
|
13531
|
+
* await git.updateIndex({
|
|
13532
|
+
* fs,
|
|
13533
|
+
* dir: '/tutorial',
|
|
13534
|
+
* add: true,
|
|
13535
|
+
* filepath: 'readme.md',
|
|
13536
|
+
* oid
|
|
13537
|
+
* })
|
|
13538
|
+
*/
|
|
13539
|
+
async function updateIndex({
|
|
13540
|
+
fs: _fs,
|
|
13541
|
+
dir,
|
|
13542
|
+
gitdir = join(dir, '.git'),
|
|
13543
|
+
cache = {},
|
|
13544
|
+
filepath,
|
|
13545
|
+
oid,
|
|
13546
|
+
mode,
|
|
13547
|
+
add,
|
|
13548
|
+
remove,
|
|
13549
|
+
force,
|
|
13550
|
+
}) {
|
|
13551
|
+
try {
|
|
13552
|
+
assertParameter('fs', _fs);
|
|
13553
|
+
assertParameter('gitdir', gitdir);
|
|
13554
|
+
assertParameter('filepath', filepath);
|
|
13555
|
+
|
|
13556
|
+
const fs = new FileSystem(_fs);
|
|
13557
|
+
|
|
13558
|
+
if (remove) {
|
|
13559
|
+
return await GitIndexManager.acquire(
|
|
13560
|
+
{ fs, gitdir, cache },
|
|
13561
|
+
async function(index) {
|
|
13562
|
+
let fileStats;
|
|
13563
|
+
|
|
13564
|
+
if (!force) {
|
|
13565
|
+
// Check if the file is still present in the working directory
|
|
13566
|
+
fileStats = await fs.lstat(join(dir, filepath));
|
|
13567
|
+
|
|
13568
|
+
if (fileStats) {
|
|
13569
|
+
// Do nothing if we don't force and the file still exists in the workdir
|
|
13570
|
+
return
|
|
13571
|
+
}
|
|
13572
|
+
}
|
|
13573
|
+
|
|
13574
|
+
// Remove the file from the index if it's forced or the file does not exist
|
|
13575
|
+
index.delete({
|
|
13576
|
+
filepath,
|
|
13577
|
+
});
|
|
13578
|
+
}
|
|
13579
|
+
)
|
|
13580
|
+
}
|
|
13581
|
+
|
|
13582
|
+
// Test if it is a file and exists on disk if `remove` is not provided, only of no oid is provided
|
|
13583
|
+
let fileStats;
|
|
13584
|
+
|
|
13585
|
+
if (!oid) {
|
|
13586
|
+
fileStats = await fs.lstat(join(dir, filepath));
|
|
13587
|
+
|
|
13588
|
+
if (!fileStats) {
|
|
13589
|
+
throw new NotFoundError(
|
|
13590
|
+
`file at "${filepath}" on disk and "remove" not set`
|
|
13591
|
+
)
|
|
13592
|
+
}
|
|
13593
|
+
|
|
13594
|
+
if (fileStats.isDirectory()) {
|
|
13595
|
+
throw new InvalidFilepathError('directory')
|
|
13596
|
+
}
|
|
13597
|
+
}
|
|
13598
|
+
|
|
13599
|
+
return await GitIndexManager.acquire({ fs, gitdir, cache }, async function(
|
|
13600
|
+
index
|
|
13601
|
+
) {
|
|
13602
|
+
if (!add && !index.has({ filepath })) {
|
|
13603
|
+
// If the index does not contain the filepath yet and `add` is not set, we should throw
|
|
13604
|
+
throw new NotFoundError(
|
|
13605
|
+
`file at "${filepath}" in index and "add" not set`
|
|
13606
|
+
)
|
|
13607
|
+
}
|
|
13608
|
+
|
|
13609
|
+
// By default we use 0 for the stats of the index file
|
|
13610
|
+
let stats = {
|
|
13611
|
+
ctime: new Date(0),
|
|
13612
|
+
mtime: new Date(0),
|
|
13613
|
+
dev: 0,
|
|
13614
|
+
ino: 0,
|
|
13615
|
+
mode,
|
|
13616
|
+
uid: 0,
|
|
13617
|
+
gid: 0,
|
|
13618
|
+
size: 0,
|
|
13619
|
+
};
|
|
13620
|
+
|
|
13621
|
+
if (!oid) {
|
|
13622
|
+
stats = fileStats;
|
|
13623
|
+
|
|
13624
|
+
// Write the file to the object database
|
|
13625
|
+
const object = stats.isSymbolicLink()
|
|
13626
|
+
? await fs.readlink(join(dir, filepath))
|
|
13627
|
+
: await fs.read(join(dir, filepath));
|
|
13628
|
+
|
|
13629
|
+
oid = await _writeObject({
|
|
13630
|
+
fs,
|
|
13631
|
+
gitdir,
|
|
13632
|
+
type: 'blob',
|
|
13633
|
+
format: 'content',
|
|
13634
|
+
object,
|
|
13635
|
+
});
|
|
13636
|
+
}
|
|
13637
|
+
|
|
13638
|
+
index.insert({
|
|
13639
|
+
filepath,
|
|
13640
|
+
oid: oid,
|
|
13641
|
+
stats,
|
|
13642
|
+
});
|
|
13643
|
+
|
|
13644
|
+
return oid
|
|
13645
|
+
})
|
|
13646
|
+
} catch (err) {
|
|
13647
|
+
err.caller = 'git.updateIndex';
|
|
13648
|
+
throw err
|
|
13649
|
+
}
|
|
13650
|
+
}
|
|
13651
|
+
|
|
13652
|
+
// @ts-check
|
|
13653
|
+
|
|
13492
13654
|
/**
|
|
13493
13655
|
* Return the version number of isomorphic-git
|
|
13494
13656
|
*
|
|
@@ -14259,6 +14421,7 @@ var index = {
|
|
|
14259
14421
|
removeNote,
|
|
14260
14422
|
renameBranch,
|
|
14261
14423
|
resetIndex,
|
|
14424
|
+
updateIndex,
|
|
14262
14425
|
resolveRef,
|
|
14263
14426
|
status,
|
|
14264
14427
|
statusMatrix,
|
|
@@ -14332,6 +14495,7 @@ exports.setConfig = setConfig;
|
|
|
14332
14495
|
exports.status = status;
|
|
14333
14496
|
exports.statusMatrix = statusMatrix;
|
|
14334
14497
|
exports.tag = tag;
|
|
14498
|
+
exports.updateIndex = updateIndex;
|
|
14335
14499
|
exports.version = version;
|
|
14336
14500
|
exports.walk = walk;
|
|
14337
14501
|
exports.writeBlob = writeBlob;
|
package/index.d.ts
CHANGED
|
@@ -685,6 +685,7 @@ declare namespace index {
|
|
|
685
685
|
export { removeNote };
|
|
686
686
|
export { renameBranch };
|
|
687
687
|
export { resetIndex };
|
|
688
|
+
export { updateIndex };
|
|
688
689
|
export { resolveRef };
|
|
689
690
|
export { status };
|
|
690
691
|
export { statusMatrix };
|
|
@@ -3107,6 +3108,59 @@ export function tag({ fs: _fs, dir, gitdir, ref, object, force, }: {
|
|
|
3107
3108
|
object?: string;
|
|
3108
3109
|
force?: boolean;
|
|
3109
3110
|
}): Promise<void>;
|
|
3111
|
+
/**
|
|
3112
|
+
* Register file contents in the working tree or object database to the git index (aka staging area).
|
|
3113
|
+
*
|
|
3114
|
+
* @param {object} args
|
|
3115
|
+
* @param {FsClient} args.fs - a file system client
|
|
3116
|
+
* @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
|
|
3117
|
+
* @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
|
|
3118
|
+
* @param {string} args.filepath - File to act upon.
|
|
3119
|
+
* @param {string} [args.oid] - OID of the object in the object database to add to the index with the specified filepath.
|
|
3120
|
+
* @param {number} [args.mode = 100644] - The file mode to add the file to the index.
|
|
3121
|
+
* @param {boolean} [args.add] - Adds the specified file to the index if it does not yet exist in the index.
|
|
3122
|
+
* @param {boolean} [args.remove] - Remove the specified file from the index if it does not exist in the workspace anymore.
|
|
3123
|
+
* @param {boolean} [args.force] - Remove the specified file from the index, even if it still exists in the workspace.
|
|
3124
|
+
* @param {object} [args.cache] - a [cache](cache.md) object
|
|
3125
|
+
*
|
|
3126
|
+
* @returns {Promise<string | void>} Resolves successfully with the SHA-1 object id of the object written or updated in the index, or nothing if the file was removed.
|
|
3127
|
+
*
|
|
3128
|
+
* @example
|
|
3129
|
+
* await git.updateIndex({
|
|
3130
|
+
* fs,
|
|
3131
|
+
* dir: '/tutorial',
|
|
3132
|
+
* filepath: 'readme.md'
|
|
3133
|
+
* })
|
|
3134
|
+
*
|
|
3135
|
+
* @example
|
|
3136
|
+
* // Manually create a blob in the object database.
|
|
3137
|
+
* let oid = await git.writeBlob({
|
|
3138
|
+
* fs,
|
|
3139
|
+
* dir: '/tutorial',
|
|
3140
|
+
* blob: new Uint8Array([])
|
|
3141
|
+
* })
|
|
3142
|
+
*
|
|
3143
|
+
* // Write the object in the object database to the index.
|
|
3144
|
+
* await git.updateIndex({
|
|
3145
|
+
* fs,
|
|
3146
|
+
* dir: '/tutorial',
|
|
3147
|
+
* add: true,
|
|
3148
|
+
* filepath: 'readme.md',
|
|
3149
|
+
* oid
|
|
3150
|
+
* })
|
|
3151
|
+
*/
|
|
3152
|
+
export function updateIndex({ fs: _fs, dir, gitdir, cache, filepath, oid, mode, add, remove, force, }: {
|
|
3153
|
+
fs: CallbackFsClient | PromiseFsClient;
|
|
3154
|
+
dir: string;
|
|
3155
|
+
gitdir?: string;
|
|
3156
|
+
filepath: string;
|
|
3157
|
+
oid?: string;
|
|
3158
|
+
mode?: number;
|
|
3159
|
+
add?: boolean;
|
|
3160
|
+
remove?: boolean;
|
|
3161
|
+
force?: boolean;
|
|
3162
|
+
cache?: any;
|
|
3163
|
+
}): Promise<string | void>;
|
|
3110
3164
|
/**
|
|
3111
3165
|
* Return the version number of isomorphic-git
|
|
3112
3166
|
*
|
|
@@ -3735,13 +3789,13 @@ declare namespace InternalError {
|
|
|
3735
3789
|
}
|
|
3736
3790
|
declare class InvalidFilepathError extends BaseError {
|
|
3737
3791
|
/**
|
|
3738
|
-
* @param {'leading-slash'|'trailing-slash'} [reason]
|
|
3792
|
+
* @param {'leading-slash'|'trailing-slash'|'directory'} [reason]
|
|
3739
3793
|
*/
|
|
3740
|
-
constructor(reason?: "leading-slash" | "trailing-slash" | undefined);
|
|
3794
|
+
constructor(reason?: "leading-slash" | "trailing-slash" | "directory" | undefined);
|
|
3741
3795
|
code: "InvalidFilepathError";
|
|
3742
3796
|
name: "InvalidFilepathError";
|
|
3743
3797
|
data: {
|
|
3744
|
-
reason: "leading-slash" | "trailing-slash" | undefined;
|
|
3798
|
+
reason: "leading-slash" | "trailing-slash" | "directory" | undefined;
|
|
3745
3799
|
};
|
|
3746
3800
|
}
|
|
3747
3801
|
declare namespace InvalidFilepathError {
|
package/index.js
CHANGED
|
@@ -756,6 +756,10 @@ class GitIndex {
|
|
|
756
756
|
this._dirty = true;
|
|
757
757
|
}
|
|
758
758
|
|
|
759
|
+
has({ filepath }) {
|
|
760
|
+
return this._entries.has(filepath)
|
|
761
|
+
}
|
|
762
|
+
|
|
759
763
|
render() {
|
|
760
764
|
return this.entries
|
|
761
765
|
.map(entry => `${entry.mode.toString(8)} ${entry.oid} ${entry.path}`)
|
|
@@ -3113,12 +3117,14 @@ HttpError.code = 'HttpError';
|
|
|
3113
3117
|
|
|
3114
3118
|
class InvalidFilepathError extends BaseError {
|
|
3115
3119
|
/**
|
|
3116
|
-
* @param {'leading-slash'|'trailing-slash'} [reason]
|
|
3120
|
+
* @param {'leading-slash'|'trailing-slash'|'directory'} [reason]
|
|
3117
3121
|
*/
|
|
3118
3122
|
constructor(reason) {
|
|
3119
3123
|
let message = 'invalid filepath';
|
|
3120
3124
|
if (reason === 'leading-slash' || reason === 'trailing-slash') {
|
|
3121
3125
|
message = `"filepath" parameter should not include leading or trailing directory separators because these can cause problems on some platforms.`;
|
|
3126
|
+
} else if (reason === 'directory') {
|
|
3127
|
+
message = `"filepath" should not be a directory.`;
|
|
3122
3128
|
}
|
|
3123
3129
|
super(message);
|
|
3124
3130
|
this.code = this.name = InvalidFilepathError.code;
|
|
@@ -6906,8 +6912,8 @@ function filterCapabilities(server, client) {
|
|
|
6906
6912
|
|
|
6907
6913
|
const pkg = {
|
|
6908
6914
|
name: 'isomorphic-git',
|
|
6909
|
-
version: '1.
|
|
6910
|
-
agent: 'git/isomorphic-git@1.
|
|
6915
|
+
version: '1.15.0',
|
|
6916
|
+
agent: 'git/isomorphic-git@1.15.0',
|
|
6911
6917
|
};
|
|
6912
6918
|
|
|
6913
6919
|
class FIFO {
|
|
@@ -13483,6 +13489,162 @@ async function tag({
|
|
|
13483
13489
|
|
|
13484
13490
|
// @ts-check
|
|
13485
13491
|
|
|
13492
|
+
/**
|
|
13493
|
+
* Register file contents in the working tree or object database to the git index (aka staging area).
|
|
13494
|
+
*
|
|
13495
|
+
* @param {object} args
|
|
13496
|
+
* @param {FsClient} args.fs - a file system client
|
|
13497
|
+
* @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
|
|
13498
|
+
* @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
|
|
13499
|
+
* @param {string} args.filepath - File to act upon.
|
|
13500
|
+
* @param {string} [args.oid] - OID of the object in the object database to add to the index with the specified filepath.
|
|
13501
|
+
* @param {number} [args.mode = 100644] - The file mode to add the file to the index.
|
|
13502
|
+
* @param {boolean} [args.add] - Adds the specified file to the index if it does not yet exist in the index.
|
|
13503
|
+
* @param {boolean} [args.remove] - Remove the specified file from the index if it does not exist in the workspace anymore.
|
|
13504
|
+
* @param {boolean} [args.force] - Remove the specified file from the index, even if it still exists in the workspace.
|
|
13505
|
+
* @param {object} [args.cache] - a [cache](cache.md) object
|
|
13506
|
+
*
|
|
13507
|
+
* @returns {Promise<string | void>} Resolves successfully with the SHA-1 object id of the object written or updated in the index, or nothing if the file was removed.
|
|
13508
|
+
*
|
|
13509
|
+
* @example
|
|
13510
|
+
* await git.updateIndex({
|
|
13511
|
+
* fs,
|
|
13512
|
+
* dir: '/tutorial',
|
|
13513
|
+
* filepath: 'readme.md'
|
|
13514
|
+
* })
|
|
13515
|
+
*
|
|
13516
|
+
* @example
|
|
13517
|
+
* // Manually create a blob in the object database.
|
|
13518
|
+
* let oid = await git.writeBlob({
|
|
13519
|
+
* fs,
|
|
13520
|
+
* dir: '/tutorial',
|
|
13521
|
+
* blob: new Uint8Array([])
|
|
13522
|
+
* })
|
|
13523
|
+
*
|
|
13524
|
+
* // Write the object in the object database to the index.
|
|
13525
|
+
* await git.updateIndex({
|
|
13526
|
+
* fs,
|
|
13527
|
+
* dir: '/tutorial',
|
|
13528
|
+
* add: true,
|
|
13529
|
+
* filepath: 'readme.md',
|
|
13530
|
+
* oid
|
|
13531
|
+
* })
|
|
13532
|
+
*/
|
|
13533
|
+
async function updateIndex({
|
|
13534
|
+
fs: _fs,
|
|
13535
|
+
dir,
|
|
13536
|
+
gitdir = join(dir, '.git'),
|
|
13537
|
+
cache = {},
|
|
13538
|
+
filepath,
|
|
13539
|
+
oid,
|
|
13540
|
+
mode,
|
|
13541
|
+
add,
|
|
13542
|
+
remove,
|
|
13543
|
+
force,
|
|
13544
|
+
}) {
|
|
13545
|
+
try {
|
|
13546
|
+
assertParameter('fs', _fs);
|
|
13547
|
+
assertParameter('gitdir', gitdir);
|
|
13548
|
+
assertParameter('filepath', filepath);
|
|
13549
|
+
|
|
13550
|
+
const fs = new FileSystem(_fs);
|
|
13551
|
+
|
|
13552
|
+
if (remove) {
|
|
13553
|
+
return await GitIndexManager.acquire(
|
|
13554
|
+
{ fs, gitdir, cache },
|
|
13555
|
+
async function(index) {
|
|
13556
|
+
let fileStats;
|
|
13557
|
+
|
|
13558
|
+
if (!force) {
|
|
13559
|
+
// Check if the file is still present in the working directory
|
|
13560
|
+
fileStats = await fs.lstat(join(dir, filepath));
|
|
13561
|
+
|
|
13562
|
+
if (fileStats) {
|
|
13563
|
+
// Do nothing if we don't force and the file still exists in the workdir
|
|
13564
|
+
return
|
|
13565
|
+
}
|
|
13566
|
+
}
|
|
13567
|
+
|
|
13568
|
+
// Remove the file from the index if it's forced or the file does not exist
|
|
13569
|
+
index.delete({
|
|
13570
|
+
filepath,
|
|
13571
|
+
});
|
|
13572
|
+
}
|
|
13573
|
+
)
|
|
13574
|
+
}
|
|
13575
|
+
|
|
13576
|
+
// Test if it is a file and exists on disk if `remove` is not provided, only of no oid is provided
|
|
13577
|
+
let fileStats;
|
|
13578
|
+
|
|
13579
|
+
if (!oid) {
|
|
13580
|
+
fileStats = await fs.lstat(join(dir, filepath));
|
|
13581
|
+
|
|
13582
|
+
if (!fileStats) {
|
|
13583
|
+
throw new NotFoundError(
|
|
13584
|
+
`file at "${filepath}" on disk and "remove" not set`
|
|
13585
|
+
)
|
|
13586
|
+
}
|
|
13587
|
+
|
|
13588
|
+
if (fileStats.isDirectory()) {
|
|
13589
|
+
throw new InvalidFilepathError('directory')
|
|
13590
|
+
}
|
|
13591
|
+
}
|
|
13592
|
+
|
|
13593
|
+
return await GitIndexManager.acquire({ fs, gitdir, cache }, async function(
|
|
13594
|
+
index
|
|
13595
|
+
) {
|
|
13596
|
+
if (!add && !index.has({ filepath })) {
|
|
13597
|
+
// If the index does not contain the filepath yet and `add` is not set, we should throw
|
|
13598
|
+
throw new NotFoundError(
|
|
13599
|
+
`file at "${filepath}" in index and "add" not set`
|
|
13600
|
+
)
|
|
13601
|
+
}
|
|
13602
|
+
|
|
13603
|
+
// By default we use 0 for the stats of the index file
|
|
13604
|
+
let stats = {
|
|
13605
|
+
ctime: new Date(0),
|
|
13606
|
+
mtime: new Date(0),
|
|
13607
|
+
dev: 0,
|
|
13608
|
+
ino: 0,
|
|
13609
|
+
mode,
|
|
13610
|
+
uid: 0,
|
|
13611
|
+
gid: 0,
|
|
13612
|
+
size: 0,
|
|
13613
|
+
};
|
|
13614
|
+
|
|
13615
|
+
if (!oid) {
|
|
13616
|
+
stats = fileStats;
|
|
13617
|
+
|
|
13618
|
+
// Write the file to the object database
|
|
13619
|
+
const object = stats.isSymbolicLink()
|
|
13620
|
+
? await fs.readlink(join(dir, filepath))
|
|
13621
|
+
: await fs.read(join(dir, filepath));
|
|
13622
|
+
|
|
13623
|
+
oid = await _writeObject({
|
|
13624
|
+
fs,
|
|
13625
|
+
gitdir,
|
|
13626
|
+
type: 'blob',
|
|
13627
|
+
format: 'content',
|
|
13628
|
+
object,
|
|
13629
|
+
});
|
|
13630
|
+
}
|
|
13631
|
+
|
|
13632
|
+
index.insert({
|
|
13633
|
+
filepath,
|
|
13634
|
+
oid: oid,
|
|
13635
|
+
stats,
|
|
13636
|
+
});
|
|
13637
|
+
|
|
13638
|
+
return oid
|
|
13639
|
+
})
|
|
13640
|
+
} catch (err) {
|
|
13641
|
+
err.caller = 'git.updateIndex';
|
|
13642
|
+
throw err
|
|
13643
|
+
}
|
|
13644
|
+
}
|
|
13645
|
+
|
|
13646
|
+
// @ts-check
|
|
13647
|
+
|
|
13486
13648
|
/**
|
|
13487
13649
|
* Return the version number of isomorphic-git
|
|
13488
13650
|
*
|
|
@@ -14253,6 +14415,7 @@ var index = {
|
|
|
14253
14415
|
removeNote,
|
|
14254
14416
|
renameBranch,
|
|
14255
14417
|
resetIndex,
|
|
14418
|
+
updateIndex,
|
|
14256
14419
|
resolveRef,
|
|
14257
14420
|
status,
|
|
14258
14421
|
statusMatrix,
|
|
@@ -14268,4 +14431,4 @@ var index = {
|
|
|
14268
14431
|
};
|
|
14269
14432
|
|
|
14270
14433
|
export default index;
|
|
14271
|
-
export { Errors, STAGE, TREE, WORKDIR, 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, status, statusMatrix, tag, version, walk, writeBlob, writeCommit, writeObject, writeRef, writeTag, writeTree };
|
|
14434
|
+
export { Errors, STAGE, TREE, WORKDIR, 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, status, statusMatrix, tag, updateIndex, version, walk, writeBlob, writeCommit, writeObject, writeRef, writeTag, writeTree };
|
package/index.umd.min.d.ts
CHANGED
|
@@ -685,6 +685,7 @@ declare namespace index {
|
|
|
685
685
|
export { removeNote };
|
|
686
686
|
export { renameBranch };
|
|
687
687
|
export { resetIndex };
|
|
688
|
+
export { updateIndex };
|
|
688
689
|
export { resolveRef };
|
|
689
690
|
export { status };
|
|
690
691
|
export { statusMatrix };
|
|
@@ -3107,6 +3108,59 @@ export function tag({ fs: _fs, dir, gitdir, ref, object, force, }: {
|
|
|
3107
3108
|
object?: string;
|
|
3108
3109
|
force?: boolean;
|
|
3109
3110
|
}): Promise<void>;
|
|
3111
|
+
/**
|
|
3112
|
+
* Register file contents in the working tree or object database to the git index (aka staging area).
|
|
3113
|
+
*
|
|
3114
|
+
* @param {object} args
|
|
3115
|
+
* @param {FsClient} args.fs - a file system client
|
|
3116
|
+
* @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
|
|
3117
|
+
* @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
|
|
3118
|
+
* @param {string} args.filepath - File to act upon.
|
|
3119
|
+
* @param {string} [args.oid] - OID of the object in the object database to add to the index with the specified filepath.
|
|
3120
|
+
* @param {number} [args.mode = 100644] - The file mode to add the file to the index.
|
|
3121
|
+
* @param {boolean} [args.add] - Adds the specified file to the index if it does not yet exist in the index.
|
|
3122
|
+
* @param {boolean} [args.remove] - Remove the specified file from the index if it does not exist in the workspace anymore.
|
|
3123
|
+
* @param {boolean} [args.force] - Remove the specified file from the index, even if it still exists in the workspace.
|
|
3124
|
+
* @param {object} [args.cache] - a [cache](cache.md) object
|
|
3125
|
+
*
|
|
3126
|
+
* @returns {Promise<string | void>} Resolves successfully with the SHA-1 object id of the object written or updated in the index, or nothing if the file was removed.
|
|
3127
|
+
*
|
|
3128
|
+
* @example
|
|
3129
|
+
* await git.updateIndex({
|
|
3130
|
+
* fs,
|
|
3131
|
+
* dir: '/tutorial',
|
|
3132
|
+
* filepath: 'readme.md'
|
|
3133
|
+
* })
|
|
3134
|
+
*
|
|
3135
|
+
* @example
|
|
3136
|
+
* // Manually create a blob in the object database.
|
|
3137
|
+
* let oid = await git.writeBlob({
|
|
3138
|
+
* fs,
|
|
3139
|
+
* dir: '/tutorial',
|
|
3140
|
+
* blob: new Uint8Array([])
|
|
3141
|
+
* })
|
|
3142
|
+
*
|
|
3143
|
+
* // Write the object in the object database to the index.
|
|
3144
|
+
* await git.updateIndex({
|
|
3145
|
+
* fs,
|
|
3146
|
+
* dir: '/tutorial',
|
|
3147
|
+
* add: true,
|
|
3148
|
+
* filepath: 'readme.md',
|
|
3149
|
+
* oid
|
|
3150
|
+
* })
|
|
3151
|
+
*/
|
|
3152
|
+
export function updateIndex({ fs: _fs, dir, gitdir, cache, filepath, oid, mode, add, remove, force, }: {
|
|
3153
|
+
fs: CallbackFsClient | PromiseFsClient;
|
|
3154
|
+
dir: string;
|
|
3155
|
+
gitdir?: string;
|
|
3156
|
+
filepath: string;
|
|
3157
|
+
oid?: string;
|
|
3158
|
+
mode?: number;
|
|
3159
|
+
add?: boolean;
|
|
3160
|
+
remove?: boolean;
|
|
3161
|
+
force?: boolean;
|
|
3162
|
+
cache?: any;
|
|
3163
|
+
}): Promise<string | void>;
|
|
3110
3164
|
/**
|
|
3111
3165
|
* Return the version number of isomorphic-git
|
|
3112
3166
|
*
|
|
@@ -3735,13 +3789,13 @@ declare namespace InternalError {
|
|
|
3735
3789
|
}
|
|
3736
3790
|
declare class InvalidFilepathError extends BaseError {
|
|
3737
3791
|
/**
|
|
3738
|
-
* @param {'leading-slash'|'trailing-slash'} [reason]
|
|
3792
|
+
* @param {'leading-slash'|'trailing-slash'|'directory'} [reason]
|
|
3739
3793
|
*/
|
|
3740
|
-
constructor(reason?: "leading-slash" | "trailing-slash" | undefined);
|
|
3794
|
+
constructor(reason?: "leading-slash" | "trailing-slash" | "directory" | undefined);
|
|
3741
3795
|
code: "InvalidFilepathError";
|
|
3742
3796
|
name: "InvalidFilepathError";
|
|
3743
3797
|
data: {
|
|
3744
|
-
reason: "leading-slash" | "trailing-slash" | undefined;
|
|
3798
|
+
reason: "leading-slash" | "trailing-slash" | "directory" | undefined;
|
|
3745
3799
|
};
|
|
3746
3800
|
}
|
|
3747
3801
|
declare namespace InvalidFilepathError {
|