isomorphic-git 1.26.5 → 1.27.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/browser-tests.json +5 -6
- package/index.cjs +276 -152
- package/index.d.ts +21 -3
- package/index.js +276 -152
- package/index.umd.min.d.ts +21 -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/browser-tests.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
-
"
|
|
3
|
-
"Firefox
|
|
2
|
+
"Chrome Headless 79.0.3945.0 (Linux x86_64)",
|
|
3
|
+
"Firefox 127.0 (Ubuntu 0.0.0)",
|
|
4
4
|
"X Chrome 123.0.0.0 (Android 10)",
|
|
5
|
-
"Edge 79.0.309.65 (Windows 10)",
|
|
6
|
-
"Safari 13.1 (Mac OS 10.15.4)",
|
|
7
5
|
"Mobile Safari 13.0 (iOS 13.0)",
|
|
6
|
+
"Safari 13.1 (Mac OS 10.15.4)",
|
|
7
|
+
"Edge 79.0.309.65 (Windows 10)",
|
|
8
8
|
"Chrome Headless 79.0.3945.0 (Linux x86_64)",
|
|
9
|
-
"Chrome 123.0.0.0 (Android 10)"
|
|
10
|
-
"Edge 79.0.309.65 (Windows 10)"
|
|
9
|
+
"Chrome 123.0.0.0 (Android 10)"
|
|
11
10
|
]
|
package/index.cjs
CHANGED
|
@@ -3579,6 +3579,21 @@ class IndexResetError extends BaseError {
|
|
|
3579
3579
|
/** @type {'IndexResetError'} */
|
|
3580
3580
|
IndexResetError.code = 'IndexResetError';
|
|
3581
3581
|
|
|
3582
|
+
class NoCommitError extends BaseError {
|
|
3583
|
+
/**
|
|
3584
|
+
* @param {string} ref
|
|
3585
|
+
*/
|
|
3586
|
+
constructor(ref) {
|
|
3587
|
+
super(
|
|
3588
|
+
`"${ref}" does not point to any commit. You're maybe working on a repository with no commits yet. `
|
|
3589
|
+
);
|
|
3590
|
+
this.code = this.name = NoCommitError.code;
|
|
3591
|
+
this.data = { ref };
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
/** @type {'NoCommitError'} */
|
|
3595
|
+
NoCommitError.code = 'NoCommitError';
|
|
3596
|
+
|
|
3582
3597
|
|
|
3583
3598
|
|
|
3584
3599
|
var Errors = /*#__PURE__*/Object.freeze({
|
|
@@ -3613,7 +3628,8 @@ var Errors = /*#__PURE__*/Object.freeze({
|
|
|
3613
3628
|
UrlParseError: UrlParseError,
|
|
3614
3629
|
UserCanceledError: UserCanceledError,
|
|
3615
3630
|
UnmergedPathsError: UnmergedPathsError,
|
|
3616
|
-
IndexResetError: IndexResetError
|
|
3631
|
+
IndexResetError: IndexResetError,
|
|
3632
|
+
NoCommitError: NoCommitError
|
|
3617
3633
|
});
|
|
3618
3634
|
|
|
3619
3635
|
function formatAuthor({ name, email, timestamp, timezoneOffset }) {
|
|
@@ -5171,6 +5187,177 @@ async function addToIndex({
|
|
|
5171
5187
|
|
|
5172
5188
|
// @ts-check
|
|
5173
5189
|
|
|
5190
|
+
/**
|
|
5191
|
+
* @param {Object} args
|
|
5192
|
+
* @param {import('../models/FileSystem.js').FileSystem} args.fs
|
|
5193
|
+
* @param {string} args.gitdir
|
|
5194
|
+
* @param {string} args.path
|
|
5195
|
+
*
|
|
5196
|
+
* @returns {Promise<any>} Resolves with the config value
|
|
5197
|
+
*
|
|
5198
|
+
* @example
|
|
5199
|
+
* // Read config value
|
|
5200
|
+
* let value = await git.getConfig({
|
|
5201
|
+
* dir: '$input((/))',
|
|
5202
|
+
* path: '$input((user.name))'
|
|
5203
|
+
* })
|
|
5204
|
+
* console.log(value)
|
|
5205
|
+
*
|
|
5206
|
+
*/
|
|
5207
|
+
async function _getConfig({ fs, gitdir, path }) {
|
|
5208
|
+
const config = await GitConfigManager.get({ fs, gitdir });
|
|
5209
|
+
return config.get(path)
|
|
5210
|
+
}
|
|
5211
|
+
|
|
5212
|
+
// Like Object.assign but ignore properties with undefined values
|
|
5213
|
+
// ref: https://stackoverflow.com/q/39513815
|
|
5214
|
+
function assignDefined(target, ...sources) {
|
|
5215
|
+
for (const source of sources) {
|
|
5216
|
+
if (source) {
|
|
5217
|
+
for (const key of Object.keys(source)) {
|
|
5218
|
+
const val = source[key];
|
|
5219
|
+
if (val !== undefined) {
|
|
5220
|
+
target[key] = val;
|
|
5221
|
+
}
|
|
5222
|
+
}
|
|
5223
|
+
}
|
|
5224
|
+
}
|
|
5225
|
+
return target
|
|
5226
|
+
}
|
|
5227
|
+
|
|
5228
|
+
/**
|
|
5229
|
+
* Return author object by using properties following this priority:
|
|
5230
|
+
* (1) provided author object
|
|
5231
|
+
* -> (2) author of provided commit object
|
|
5232
|
+
* -> (3) Config and current date/time
|
|
5233
|
+
*
|
|
5234
|
+
* @param {Object} args
|
|
5235
|
+
* @param {FsClient} args.fs - a file system implementation
|
|
5236
|
+
* @param {string} [args.gitdir] - The [git directory](dir-vs-gitdir.md) path
|
|
5237
|
+
* @param {Object} [args.author] - The author object.
|
|
5238
|
+
* @param {CommitObject} [args.commit] - A commit object.
|
|
5239
|
+
*
|
|
5240
|
+
* @returns {Promise<void | {name: string, email: string, timestamp: number, timezoneOffset: number }>}
|
|
5241
|
+
*/
|
|
5242
|
+
async function normalizeAuthorObject({ fs, gitdir, author, commit }) {
|
|
5243
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
5244
|
+
|
|
5245
|
+
const defaultAuthor = {
|
|
5246
|
+
name: await _getConfig({ fs, gitdir, path: 'user.name' }),
|
|
5247
|
+
email: (await _getConfig({ fs, gitdir, path: 'user.email' })) || '', // author.email is allowed to be empty string
|
|
5248
|
+
timestamp,
|
|
5249
|
+
timezoneOffset: new Date(timestamp * 1000).getTimezoneOffset(),
|
|
5250
|
+
};
|
|
5251
|
+
|
|
5252
|
+
// Populate author object by using properties with this priority:
|
|
5253
|
+
// (1) provided author object
|
|
5254
|
+
// -> (2) author of provided commit object
|
|
5255
|
+
// -> (3) default author
|
|
5256
|
+
const normalizedAuthor = assignDefined(
|
|
5257
|
+
{},
|
|
5258
|
+
defaultAuthor,
|
|
5259
|
+
commit ? commit.author : undefined,
|
|
5260
|
+
author
|
|
5261
|
+
);
|
|
5262
|
+
|
|
5263
|
+
if (normalizedAuthor.name === undefined) {
|
|
5264
|
+
return undefined
|
|
5265
|
+
}
|
|
5266
|
+
|
|
5267
|
+
return normalizedAuthor
|
|
5268
|
+
}
|
|
5269
|
+
|
|
5270
|
+
/**
|
|
5271
|
+
* Return committer object by using properties with this priority:
|
|
5272
|
+
* (1) provided committer object
|
|
5273
|
+
* -> (2) provided author object
|
|
5274
|
+
* -> (3) committer of provided commit object
|
|
5275
|
+
* -> (4) Config and current date/time
|
|
5276
|
+
*
|
|
5277
|
+
* @param {Object} args
|
|
5278
|
+
* @param {FsClient} args.fs - a file system implementation
|
|
5279
|
+
* @param {string} [args.gitdir] - The [git directory](dir-vs-gitdir.md) path
|
|
5280
|
+
* @param {Object} [args.author] - The author object.
|
|
5281
|
+
* @param {Object} [args.committer] - The committer object.
|
|
5282
|
+
* @param {CommitObject} [args.commit] - A commit object.
|
|
5283
|
+
*
|
|
5284
|
+
* @returns {Promise<void | {name: string, email: string, timestamp: number, timezoneOffset: number }>}
|
|
5285
|
+
*/
|
|
5286
|
+
async function normalizeCommitterObject({
|
|
5287
|
+
fs,
|
|
5288
|
+
gitdir,
|
|
5289
|
+
author,
|
|
5290
|
+
committer,
|
|
5291
|
+
commit,
|
|
5292
|
+
}) {
|
|
5293
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
5294
|
+
|
|
5295
|
+
const defaultCommitter = {
|
|
5296
|
+
name: await _getConfig({ fs, gitdir, path: 'user.name' }),
|
|
5297
|
+
email: (await _getConfig({ fs, gitdir, path: 'user.email' })) || '', // committer.email is allowed to be empty string
|
|
5298
|
+
timestamp,
|
|
5299
|
+
timezoneOffset: new Date(timestamp * 1000).getTimezoneOffset(),
|
|
5300
|
+
};
|
|
5301
|
+
|
|
5302
|
+
const normalizedCommitter = assignDefined(
|
|
5303
|
+
{},
|
|
5304
|
+
defaultCommitter,
|
|
5305
|
+
commit ? commit.committer : undefined,
|
|
5306
|
+
author,
|
|
5307
|
+
committer
|
|
5308
|
+
);
|
|
5309
|
+
|
|
5310
|
+
if (normalizedCommitter.name === undefined) {
|
|
5311
|
+
return undefined
|
|
5312
|
+
}
|
|
5313
|
+
return normalizedCommitter
|
|
5314
|
+
}
|
|
5315
|
+
|
|
5316
|
+
async function resolveCommit({ fs, cache, gitdir, oid }) {
|
|
5317
|
+
const { type, object } = await _readObject({ fs, cache, gitdir, oid });
|
|
5318
|
+
// Resolve annotated tag objects to whatever
|
|
5319
|
+
if (type === 'tag') {
|
|
5320
|
+
oid = GitAnnotatedTag.from(object).parse().object;
|
|
5321
|
+
return resolveCommit({ fs, cache, gitdir, oid })
|
|
5322
|
+
}
|
|
5323
|
+
if (type !== 'commit') {
|
|
5324
|
+
throw new ObjectTypeError(oid, type, 'commit')
|
|
5325
|
+
}
|
|
5326
|
+
return { commit: GitCommit.from(object), oid }
|
|
5327
|
+
}
|
|
5328
|
+
|
|
5329
|
+
// @ts-check
|
|
5330
|
+
|
|
5331
|
+
/**
|
|
5332
|
+
* @param {object} args
|
|
5333
|
+
* @param {import('../models/FileSystem.js').FileSystem} args.fs
|
|
5334
|
+
* @param {any} args.cache
|
|
5335
|
+
* @param {string} args.gitdir
|
|
5336
|
+
* @param {string} args.oid
|
|
5337
|
+
*
|
|
5338
|
+
* @returns {Promise<ReadCommitResult>} Resolves successfully with a git commit object
|
|
5339
|
+
* @see ReadCommitResult
|
|
5340
|
+
* @see CommitObject
|
|
5341
|
+
*
|
|
5342
|
+
*/
|
|
5343
|
+
async function _readCommit({ fs, cache, gitdir, oid }) {
|
|
5344
|
+
const { commit, oid: commitOid } = await resolveCommit({
|
|
5345
|
+
fs,
|
|
5346
|
+
cache,
|
|
5347
|
+
gitdir,
|
|
5348
|
+
oid,
|
|
5349
|
+
});
|
|
5350
|
+
const result = {
|
|
5351
|
+
oid: commitOid,
|
|
5352
|
+
commit: commit.parse(),
|
|
5353
|
+
payload: commit.withoutSignature(),
|
|
5354
|
+
};
|
|
5355
|
+
// @ts-ignore
|
|
5356
|
+
return result
|
|
5357
|
+
}
|
|
5358
|
+
|
|
5359
|
+
// @ts-check
|
|
5360
|
+
|
|
5174
5361
|
/**
|
|
5175
5362
|
*
|
|
5176
5363
|
* @param {Object} args
|
|
@@ -5178,18 +5365,19 @@ async function addToIndex({
|
|
|
5178
5365
|
* @param {object} args.cache
|
|
5179
5366
|
* @param {SignCallback} [args.onSign]
|
|
5180
5367
|
* @param {string} args.gitdir
|
|
5181
|
-
* @param {string} args.message
|
|
5182
|
-
* @param {Object} args.author
|
|
5183
|
-
* @param {string} args.author.name
|
|
5184
|
-
* @param {string} args.author.email
|
|
5185
|
-
* @param {number} args.author.timestamp
|
|
5186
|
-
* @param {number} args.author.timezoneOffset
|
|
5187
|
-
* @param {Object} args.committer
|
|
5188
|
-
* @param {string} args.committer.name
|
|
5189
|
-
* @param {string} args.committer.email
|
|
5190
|
-
* @param {number} args.committer.timestamp
|
|
5191
|
-
* @param {number} args.committer.timezoneOffset
|
|
5368
|
+
* @param {string} [args.message]
|
|
5369
|
+
* @param {Object} [args.author]
|
|
5370
|
+
* @param {string} [args.author.name]
|
|
5371
|
+
* @param {string} [args.author.email]
|
|
5372
|
+
* @param {number} [args.author.timestamp]
|
|
5373
|
+
* @param {number} [args.author.timezoneOffset]
|
|
5374
|
+
* @param {Object} [args.committer]
|
|
5375
|
+
* @param {string} [args.committer.name]
|
|
5376
|
+
* @param {string} [args.committer.email]
|
|
5377
|
+
* @param {number} [args.committer.timestamp]
|
|
5378
|
+
* @param {number} [args.committer.timezoneOffset]
|
|
5192
5379
|
* @param {string} [args.signingKey]
|
|
5380
|
+
* @param {boolean} [args.amend = false]
|
|
5193
5381
|
* @param {boolean} [args.dryRun = false]
|
|
5194
5382
|
* @param {boolean} [args.noUpdateBranch = false]
|
|
5195
5383
|
* @param {string} [args.ref]
|
|
@@ -5204,15 +5392,18 @@ async function _commit({
|
|
|
5204
5392
|
onSign,
|
|
5205
5393
|
gitdir,
|
|
5206
5394
|
message,
|
|
5207
|
-
author,
|
|
5208
|
-
committer,
|
|
5395
|
+
author: _author,
|
|
5396
|
+
committer: _committer,
|
|
5209
5397
|
signingKey,
|
|
5398
|
+
amend = false,
|
|
5210
5399
|
dryRun = false,
|
|
5211
5400
|
noUpdateBranch = false,
|
|
5212
5401
|
ref,
|
|
5213
5402
|
parent,
|
|
5214
5403
|
tree,
|
|
5215
5404
|
}) {
|
|
5405
|
+
// Determine ref and the commit pointed to by ref, and if it is the initial commit
|
|
5406
|
+
let initialCommit = false;
|
|
5216
5407
|
if (!ref) {
|
|
5217
5408
|
ref = await GitRefManager.resolve({
|
|
5218
5409
|
fs,
|
|
@@ -5222,6 +5413,50 @@ async function _commit({
|
|
|
5222
5413
|
});
|
|
5223
5414
|
}
|
|
5224
5415
|
|
|
5416
|
+
let refOid, refCommit;
|
|
5417
|
+
try {
|
|
5418
|
+
refOid = await GitRefManager.resolve({
|
|
5419
|
+
fs,
|
|
5420
|
+
gitdir,
|
|
5421
|
+
ref,
|
|
5422
|
+
});
|
|
5423
|
+
refCommit = await _readCommit({ fs, gitdir, oid: refOid, cache: {} });
|
|
5424
|
+
} catch {
|
|
5425
|
+
// We assume that there's no commit and this is the initial commit
|
|
5426
|
+
initialCommit = true;
|
|
5427
|
+
}
|
|
5428
|
+
|
|
5429
|
+
if (amend && initialCommit) {
|
|
5430
|
+
throw new NoCommitError(ref)
|
|
5431
|
+
}
|
|
5432
|
+
|
|
5433
|
+
// Determine author and committer information
|
|
5434
|
+
const author = !amend
|
|
5435
|
+
? await normalizeAuthorObject({ fs, gitdir, author: _author })
|
|
5436
|
+
: await normalizeAuthorObject({
|
|
5437
|
+
fs,
|
|
5438
|
+
gitdir,
|
|
5439
|
+
author: _author,
|
|
5440
|
+
commit: refCommit.commit,
|
|
5441
|
+
});
|
|
5442
|
+
if (!author) throw new MissingNameError('author')
|
|
5443
|
+
|
|
5444
|
+
const committer = !amend
|
|
5445
|
+
? await normalizeCommitterObject({
|
|
5446
|
+
fs,
|
|
5447
|
+
gitdir,
|
|
5448
|
+
author,
|
|
5449
|
+
committer: _committer,
|
|
5450
|
+
})
|
|
5451
|
+
: await normalizeCommitterObject({
|
|
5452
|
+
fs,
|
|
5453
|
+
gitdir,
|
|
5454
|
+
author,
|
|
5455
|
+
committer: _committer,
|
|
5456
|
+
commit: refCommit.commit,
|
|
5457
|
+
});
|
|
5458
|
+
if (!committer) throw new MissingNameError('committer')
|
|
5459
|
+
|
|
5225
5460
|
return GitIndexManager.acquire(
|
|
5226
5461
|
{ fs, gitdir, cache, allowUnmerged: false },
|
|
5227
5462
|
async function(index) {
|
|
@@ -5230,18 +5465,13 @@ async function _commit({
|
|
|
5230
5465
|
if (!tree) {
|
|
5231
5466
|
tree = await constructTree({ fs, gitdir, inode, dryRun });
|
|
5232
5467
|
}
|
|
5468
|
+
|
|
5469
|
+
// Determine parents of this commit
|
|
5233
5470
|
if (!parent) {
|
|
5234
|
-
|
|
5235
|
-
parent = [
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
gitdir,
|
|
5239
|
-
ref,
|
|
5240
|
-
}),
|
|
5241
|
-
];
|
|
5242
|
-
} catch (err) {
|
|
5243
|
-
// Probably an initial commit
|
|
5244
|
-
parent = [];
|
|
5471
|
+
if (!amend) {
|
|
5472
|
+
parent = refOid ? [refOid] : [];
|
|
5473
|
+
} else {
|
|
5474
|
+
parent = refCommit.commit.parent;
|
|
5245
5475
|
}
|
|
5246
5476
|
} else {
|
|
5247
5477
|
// ensure that the parents are oids, not refs
|
|
@@ -5252,6 +5482,16 @@ async function _commit({
|
|
|
5252
5482
|
);
|
|
5253
5483
|
}
|
|
5254
5484
|
|
|
5485
|
+
// Determine message of this commit
|
|
5486
|
+
if (!message) {
|
|
5487
|
+
if (!amend) {
|
|
5488
|
+
throw new MissingParameterError('message')
|
|
5489
|
+
} else {
|
|
5490
|
+
message = refCommit.commit.message;
|
|
5491
|
+
}
|
|
5492
|
+
}
|
|
5493
|
+
|
|
5494
|
+
// Create and write new Commit object
|
|
5255
5495
|
let comm = GitCommit.from({
|
|
5256
5496
|
tree,
|
|
5257
5497
|
parent,
|
|
@@ -5551,72 +5791,6 @@ async function _addNote({
|
|
|
5551
5791
|
|
|
5552
5792
|
// @ts-check
|
|
5553
5793
|
|
|
5554
|
-
/**
|
|
5555
|
-
* @param {Object} args
|
|
5556
|
-
* @param {import('../models/FileSystem.js').FileSystem} args.fs
|
|
5557
|
-
* @param {string} args.gitdir
|
|
5558
|
-
* @param {string} args.path
|
|
5559
|
-
*
|
|
5560
|
-
* @returns {Promise<any>} Resolves with the config value
|
|
5561
|
-
*
|
|
5562
|
-
* @example
|
|
5563
|
-
* // Read config value
|
|
5564
|
-
* let value = await git.getConfig({
|
|
5565
|
-
* dir: '$input((/))',
|
|
5566
|
-
* path: '$input((user.name))'
|
|
5567
|
-
* })
|
|
5568
|
-
* console.log(value)
|
|
5569
|
-
*
|
|
5570
|
-
*/
|
|
5571
|
-
async function _getConfig({ fs, gitdir, path }) {
|
|
5572
|
-
const config = await GitConfigManager.get({ fs, gitdir });
|
|
5573
|
-
return config.get(path)
|
|
5574
|
-
}
|
|
5575
|
-
|
|
5576
|
-
/**
|
|
5577
|
-
*
|
|
5578
|
-
* @returns {Promise<void | {name: string, email: string, date: Date, timestamp: number, timezoneOffset: number }>}
|
|
5579
|
-
*/
|
|
5580
|
-
async function normalizeAuthorObject({ fs, gitdir, author = {} }) {
|
|
5581
|
-
let { name, email, timestamp, timezoneOffset } = author;
|
|
5582
|
-
name = name || (await _getConfig({ fs, gitdir, path: 'user.name' }));
|
|
5583
|
-
email = email || (await _getConfig({ fs, gitdir, path: 'user.email' })) || '';
|
|
5584
|
-
|
|
5585
|
-
if (name === undefined) {
|
|
5586
|
-
return undefined
|
|
5587
|
-
}
|
|
5588
|
-
|
|
5589
|
-
timestamp = timestamp != null ? timestamp : Math.floor(Date.now() / 1000);
|
|
5590
|
-
timezoneOffset =
|
|
5591
|
-
timezoneOffset != null
|
|
5592
|
-
? timezoneOffset
|
|
5593
|
-
: new Date(timestamp * 1000).getTimezoneOffset();
|
|
5594
|
-
|
|
5595
|
-
return { name, email, timestamp, timezoneOffset }
|
|
5596
|
-
}
|
|
5597
|
-
|
|
5598
|
-
/**
|
|
5599
|
-
*
|
|
5600
|
-
* @returns {Promise<void | {name: string, email: string, timestamp: number, timezoneOffset: number }>}
|
|
5601
|
-
*/
|
|
5602
|
-
async function normalizeCommitterObject({
|
|
5603
|
-
fs,
|
|
5604
|
-
gitdir,
|
|
5605
|
-
author,
|
|
5606
|
-
committer,
|
|
5607
|
-
}) {
|
|
5608
|
-
committer = Object.assign({}, committer || author);
|
|
5609
|
-
// Match committer's date to author's one, if omitted
|
|
5610
|
-
if (author) {
|
|
5611
|
-
committer.timestamp = committer.timestamp || author.timestamp;
|
|
5612
|
-
committer.timezoneOffset = committer.timezoneOffset || author.timezoneOffset;
|
|
5613
|
-
}
|
|
5614
|
-
committer = await normalizeAuthorObject({ fs, gitdir, author: committer });
|
|
5615
|
-
return committer
|
|
5616
|
-
}
|
|
5617
|
-
|
|
5618
|
-
// @ts-check
|
|
5619
|
-
|
|
5620
5794
|
/**
|
|
5621
5795
|
* Add or update an object note
|
|
5622
5796
|
*
|
|
@@ -7452,8 +7626,8 @@ function filterCapabilities(server, client) {
|
|
|
7452
7626
|
|
|
7453
7627
|
const pkg = {
|
|
7454
7628
|
name: 'isomorphic-git',
|
|
7455
|
-
version: '1.
|
|
7456
|
-
agent: 'git/isomorphic-git@1.
|
|
7629
|
+
version: '1.27.0',
|
|
7630
|
+
agent: 'git/isomorphic-git@1.27.0',
|
|
7457
7631
|
};
|
|
7458
7632
|
|
|
7459
7633
|
class FIFO {
|
|
@@ -8403,7 +8577,6 @@ async function clone({
|
|
|
8403
8577
|
}
|
|
8404
8578
|
|
|
8405
8579
|
// @ts-check
|
|
8406
|
-
|
|
8407
8580
|
/**
|
|
8408
8581
|
* Create a new commit
|
|
8409
8582
|
*
|
|
@@ -8412,7 +8585,7 @@ async function clone({
|
|
|
8412
8585
|
* @param {SignCallback} [args.onSign] - a PGP signing implementation
|
|
8413
8586
|
* @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
|
|
8414
8587
|
* @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
|
|
8415
|
-
* @param {string} args.message - The commit message to use.
|
|
8588
|
+
* @param {string} [args.message] - The commit message to use. Required, unless `amend === true`
|
|
8416
8589
|
* @param {Object} [args.author] - The details about the author.
|
|
8417
8590
|
* @param {string} [args.author.name] - Default is `user.name` config.
|
|
8418
8591
|
* @param {string} [args.author.email] - Default is `user.email` config.
|
|
@@ -8424,6 +8597,7 @@ async function clone({
|
|
|
8424
8597
|
* @param {number} [args.committer.timestamp=Math.floor(Date.now()/1000)] - Set the committer timestamp field. This is the integer number of seconds since the Unix epoch (1970-01-01 00:00:00).
|
|
8425
8598
|
* @param {number} [args.committer.timezoneOffset] - Set the committer timezone offset field. This is the difference, in minutes, from the current timezone to UTC. Default is `(new Date()).getTimezoneOffset()`.
|
|
8426
8599
|
* @param {string} [args.signingKey] - Sign the tag object using this private PGP key.
|
|
8600
|
+
* @param {boolean} [args.amend = false] - If true, replaces the last commit pointed to by `ref` with a new commit.
|
|
8427
8601
|
* @param {boolean} [args.dryRun = false] - If true, simulates making a commit so you can test whether it would succeed. Implies `noUpdateBranch`.
|
|
8428
8602
|
* @param {boolean} [args.noUpdateBranch = false] - If true, does not update the branch pointer after creating the commit.
|
|
8429
8603
|
* @param {string} [args.ref] - The fully expanded name of the branch to commit to. Default is the current branch pointed to by HEAD. (TODO: fix it so it can expand branch names without throwing if the branch doesn't exist yet.)
|
|
@@ -8452,9 +8626,10 @@ async function commit({
|
|
|
8452
8626
|
dir,
|
|
8453
8627
|
gitdir = join(dir, '.git'),
|
|
8454
8628
|
message,
|
|
8455
|
-
author
|
|
8456
|
-
committer
|
|
8629
|
+
author,
|
|
8630
|
+
committer,
|
|
8457
8631
|
signingKey,
|
|
8632
|
+
amend = false,
|
|
8458
8633
|
dryRun = false,
|
|
8459
8634
|
noUpdateBranch = false,
|
|
8460
8635
|
ref,
|
|
@@ -8464,23 +8639,14 @@ async function commit({
|
|
|
8464
8639
|
}) {
|
|
8465
8640
|
try {
|
|
8466
8641
|
assertParameter('fs', _fs);
|
|
8467
|
-
|
|
8642
|
+
if (!amend) {
|
|
8643
|
+
assertParameter('message', message);
|
|
8644
|
+
}
|
|
8468
8645
|
if (signingKey) {
|
|
8469
8646
|
assertParameter('onSign', onSign);
|
|
8470
8647
|
}
|
|
8471
8648
|
const fs = new FileSystem(_fs);
|
|
8472
8649
|
|
|
8473
|
-
const author = await normalizeAuthorObject({ fs, gitdir, author: _author });
|
|
8474
|
-
if (!author) throw new MissingNameError('author')
|
|
8475
|
-
|
|
8476
|
-
const committer = await normalizeCommitterObject({
|
|
8477
|
-
fs,
|
|
8478
|
-
gitdir,
|
|
8479
|
-
author,
|
|
8480
|
-
committer: _committer,
|
|
8481
|
-
});
|
|
8482
|
-
if (!committer) throw new MissingNameError('committer')
|
|
8483
|
-
|
|
8484
8650
|
return await _commit({
|
|
8485
8651
|
fs,
|
|
8486
8652
|
cache,
|
|
@@ -8490,6 +8656,7 @@ async function commit({
|
|
|
8490
8656
|
author,
|
|
8491
8657
|
committer,
|
|
8492
8658
|
signingKey,
|
|
8659
|
+
amend,
|
|
8493
8660
|
dryRun,
|
|
8494
8661
|
noUpdateBranch,
|
|
8495
8662
|
ref,
|
|
@@ -11215,49 +11382,6 @@ async function listTags({ fs, dir, gitdir = join(dir, '.git') }) {
|
|
|
11215
11382
|
}
|
|
11216
11383
|
}
|
|
11217
11384
|
|
|
11218
|
-
async function resolveCommit({ fs, cache, gitdir, oid }) {
|
|
11219
|
-
const { type, object } = await _readObject({ fs, cache, gitdir, oid });
|
|
11220
|
-
// Resolve annotated tag objects to whatever
|
|
11221
|
-
if (type === 'tag') {
|
|
11222
|
-
oid = GitAnnotatedTag.from(object).parse().object;
|
|
11223
|
-
return resolveCommit({ fs, cache, gitdir, oid })
|
|
11224
|
-
}
|
|
11225
|
-
if (type !== 'commit') {
|
|
11226
|
-
throw new ObjectTypeError(oid, type, 'commit')
|
|
11227
|
-
}
|
|
11228
|
-
return { commit: GitCommit.from(object), oid }
|
|
11229
|
-
}
|
|
11230
|
-
|
|
11231
|
-
// @ts-check
|
|
11232
|
-
|
|
11233
|
-
/**
|
|
11234
|
-
* @param {object} args
|
|
11235
|
-
* @param {import('../models/FileSystem.js').FileSystem} args.fs
|
|
11236
|
-
* @param {any} args.cache
|
|
11237
|
-
* @param {string} args.gitdir
|
|
11238
|
-
* @param {string} args.oid
|
|
11239
|
-
*
|
|
11240
|
-
* @returns {Promise<ReadCommitResult>} Resolves successfully with a git commit object
|
|
11241
|
-
* @see ReadCommitResult
|
|
11242
|
-
* @see CommitObject
|
|
11243
|
-
*
|
|
11244
|
-
*/
|
|
11245
|
-
async function _readCommit({ fs, cache, gitdir, oid }) {
|
|
11246
|
-
const { commit, oid: commitOid } = await resolveCommit({
|
|
11247
|
-
fs,
|
|
11248
|
-
cache,
|
|
11249
|
-
gitdir,
|
|
11250
|
-
oid,
|
|
11251
|
-
});
|
|
11252
|
-
const result = {
|
|
11253
|
-
oid: commitOid,
|
|
11254
|
-
commit: commit.parse(),
|
|
11255
|
-
payload: commit.withoutSignature(),
|
|
11256
|
-
};
|
|
11257
|
-
// @ts-ignore
|
|
11258
|
-
return result
|
|
11259
|
-
}
|
|
11260
|
-
|
|
11261
11385
|
function compareAge(a, b) {
|
|
11262
11386
|
return a.committer.timestamp - b.committer.timestamp
|
|
11263
11387
|
}
|
package/index.d.ts
CHANGED
|
@@ -789,6 +789,7 @@ export var Errors: Readonly<{
|
|
|
789
789
|
UserCanceledError: typeof UserCanceledError;
|
|
790
790
|
UnmergedPathsError: typeof UnmergedPathsError;
|
|
791
791
|
IndexResetError: typeof IndexResetError;
|
|
792
|
+
NoCommitError: typeof NoCommitError;
|
|
792
793
|
}>;
|
|
793
794
|
/**
|
|
794
795
|
* @returns {Walker}
|
|
@@ -1180,7 +1181,7 @@ export function clone({ fs, http, onProgress, onMessage, onAuth, onAuthSuccess,
|
|
|
1180
1181
|
* @param {SignCallback} [args.onSign] - a PGP signing implementation
|
|
1181
1182
|
* @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
|
|
1182
1183
|
* @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
|
|
1183
|
-
* @param {string} args.message - The commit message to use.
|
|
1184
|
+
* @param {string} [args.message] - The commit message to use. Required, unless `amend === true`
|
|
1184
1185
|
* @param {Object} [args.author] - The details about the author.
|
|
1185
1186
|
* @param {string} [args.author.name] - Default is `user.name` config.
|
|
1186
1187
|
* @param {string} [args.author.email] - Default is `user.email` config.
|
|
@@ -1192,6 +1193,7 @@ export function clone({ fs, http, onProgress, onMessage, onAuth, onAuthSuccess,
|
|
|
1192
1193
|
* @param {number} [args.committer.timestamp=Math.floor(Date.now()/1000)] - Set the committer timestamp field. This is the integer number of seconds since the Unix epoch (1970-01-01 00:00:00).
|
|
1193
1194
|
* @param {number} [args.committer.timezoneOffset] - Set the committer timezone offset field. This is the difference, in minutes, from the current timezone to UTC. Default is `(new Date()).getTimezoneOffset()`.
|
|
1194
1195
|
* @param {string} [args.signingKey] - Sign the tag object using this private PGP key.
|
|
1196
|
+
* @param {boolean} [args.amend = false] - If true, replaces the last commit pointed to by `ref` with a new commit.
|
|
1195
1197
|
* @param {boolean} [args.dryRun = false] - If true, simulates making a commit so you can test whether it would succeed. Implies `noUpdateBranch`.
|
|
1196
1198
|
* @param {boolean} [args.noUpdateBranch = false] - If true, does not update the branch pointer after creating the commit.
|
|
1197
1199
|
* @param {string} [args.ref] - The fully expanded name of the branch to commit to. Default is the current branch pointed to by HEAD. (TODO: fix it so it can expand branch names without throwing if the branch doesn't exist yet.)
|
|
@@ -1214,12 +1216,12 @@ export function clone({ fs, http, onProgress, onMessage, onAuth, onAuthSuccess,
|
|
|
1214
1216
|
* console.log(sha)
|
|
1215
1217
|
*
|
|
1216
1218
|
*/
|
|
1217
|
-
export function commit({ fs: _fs, onSign, dir, gitdir, message, author
|
|
1219
|
+
export function commit({ fs: _fs, onSign, dir, gitdir, message, author, committer, signingKey, amend, dryRun, noUpdateBranch, ref, parent, tree, cache, }: {
|
|
1218
1220
|
fs: CallbackFsClient | PromiseFsClient;
|
|
1219
1221
|
onSign?: SignCallback;
|
|
1220
1222
|
dir?: string;
|
|
1221
1223
|
gitdir?: string;
|
|
1222
|
-
message
|
|
1224
|
+
message?: string;
|
|
1223
1225
|
author?: {
|
|
1224
1226
|
name?: string;
|
|
1225
1227
|
email?: string;
|
|
@@ -1233,6 +1235,7 @@ export function commit({ fs: _fs, onSign, dir, gitdir, message, author: _author,
|
|
|
1233
1235
|
timezoneOffset?: number;
|
|
1234
1236
|
};
|
|
1235
1237
|
signingKey?: string;
|
|
1238
|
+
amend?: boolean;
|
|
1236
1239
|
dryRun?: boolean;
|
|
1237
1240
|
noUpdateBranch?: boolean;
|
|
1238
1241
|
ref?: string;
|
|
@@ -4303,6 +4306,21 @@ declare namespace IndexResetError {
|
|
|
4303
4306
|
const code_30: 'IndexResetError';
|
|
4304
4307
|
export { code_30 as code };
|
|
4305
4308
|
}
|
|
4309
|
+
declare class NoCommitError extends BaseError {
|
|
4310
|
+
/**
|
|
4311
|
+
* @param {string} ref
|
|
4312
|
+
*/
|
|
4313
|
+
constructor(ref: string);
|
|
4314
|
+
code: "NoCommitError";
|
|
4315
|
+
name: "NoCommitError";
|
|
4316
|
+
data: {
|
|
4317
|
+
ref: string;
|
|
4318
|
+
};
|
|
4319
|
+
}
|
|
4320
|
+
declare namespace NoCommitError {
|
|
4321
|
+
const code_31: 'NoCommitError';
|
|
4322
|
+
export { code_31 as code };
|
|
4323
|
+
}
|
|
4306
4324
|
/**
|
|
4307
4325
|
* @typedef {Object} GitProgressEvent
|
|
4308
4326
|
* @property {string} phase
|