isomorphic-git 1.26.4 → 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 +6 -4
- package/index.cjs +283 -154
- package/index.d.ts +22 -4
- package/index.js +283 -154
- package/index.umd.min.d.ts +22 -4
- 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/index.js
CHANGED
|
@@ -3573,6 +3573,21 @@ class IndexResetError extends BaseError {
|
|
|
3573
3573
|
/** @type {'IndexResetError'} */
|
|
3574
3574
|
IndexResetError.code = 'IndexResetError';
|
|
3575
3575
|
|
|
3576
|
+
class NoCommitError extends BaseError {
|
|
3577
|
+
/**
|
|
3578
|
+
* @param {string} ref
|
|
3579
|
+
*/
|
|
3580
|
+
constructor(ref) {
|
|
3581
|
+
super(
|
|
3582
|
+
`"${ref}" does not point to any commit. You're maybe working on a repository with no commits yet. `
|
|
3583
|
+
);
|
|
3584
|
+
this.code = this.name = NoCommitError.code;
|
|
3585
|
+
this.data = { ref };
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
/** @type {'NoCommitError'} */
|
|
3589
|
+
NoCommitError.code = 'NoCommitError';
|
|
3590
|
+
|
|
3576
3591
|
|
|
3577
3592
|
|
|
3578
3593
|
var Errors = /*#__PURE__*/Object.freeze({
|
|
@@ -3607,7 +3622,8 @@ var Errors = /*#__PURE__*/Object.freeze({
|
|
|
3607
3622
|
UrlParseError: UrlParseError,
|
|
3608
3623
|
UserCanceledError: UserCanceledError,
|
|
3609
3624
|
UnmergedPathsError: UnmergedPathsError,
|
|
3610
|
-
IndexResetError: IndexResetError
|
|
3625
|
+
IndexResetError: IndexResetError,
|
|
3626
|
+
NoCommitError: NoCommitError
|
|
3611
3627
|
});
|
|
3612
3628
|
|
|
3613
3629
|
function formatAuthor({ name, email, timestamp, timezoneOffset }) {
|
|
@@ -5165,6 +5181,177 @@ async function addToIndex({
|
|
|
5165
5181
|
|
|
5166
5182
|
// @ts-check
|
|
5167
5183
|
|
|
5184
|
+
/**
|
|
5185
|
+
* @param {Object} args
|
|
5186
|
+
* @param {import('../models/FileSystem.js').FileSystem} args.fs
|
|
5187
|
+
* @param {string} args.gitdir
|
|
5188
|
+
* @param {string} args.path
|
|
5189
|
+
*
|
|
5190
|
+
* @returns {Promise<any>} Resolves with the config value
|
|
5191
|
+
*
|
|
5192
|
+
* @example
|
|
5193
|
+
* // Read config value
|
|
5194
|
+
* let value = await git.getConfig({
|
|
5195
|
+
* dir: '$input((/))',
|
|
5196
|
+
* path: '$input((user.name))'
|
|
5197
|
+
* })
|
|
5198
|
+
* console.log(value)
|
|
5199
|
+
*
|
|
5200
|
+
*/
|
|
5201
|
+
async function _getConfig({ fs, gitdir, path }) {
|
|
5202
|
+
const config = await GitConfigManager.get({ fs, gitdir });
|
|
5203
|
+
return config.get(path)
|
|
5204
|
+
}
|
|
5205
|
+
|
|
5206
|
+
// Like Object.assign but ignore properties with undefined values
|
|
5207
|
+
// ref: https://stackoverflow.com/q/39513815
|
|
5208
|
+
function assignDefined(target, ...sources) {
|
|
5209
|
+
for (const source of sources) {
|
|
5210
|
+
if (source) {
|
|
5211
|
+
for (const key of Object.keys(source)) {
|
|
5212
|
+
const val = source[key];
|
|
5213
|
+
if (val !== undefined) {
|
|
5214
|
+
target[key] = val;
|
|
5215
|
+
}
|
|
5216
|
+
}
|
|
5217
|
+
}
|
|
5218
|
+
}
|
|
5219
|
+
return target
|
|
5220
|
+
}
|
|
5221
|
+
|
|
5222
|
+
/**
|
|
5223
|
+
* Return author object by using properties following this priority:
|
|
5224
|
+
* (1) provided author object
|
|
5225
|
+
* -> (2) author of provided commit object
|
|
5226
|
+
* -> (3) Config and current date/time
|
|
5227
|
+
*
|
|
5228
|
+
* @param {Object} args
|
|
5229
|
+
* @param {FsClient} args.fs - a file system implementation
|
|
5230
|
+
* @param {string} [args.gitdir] - The [git directory](dir-vs-gitdir.md) path
|
|
5231
|
+
* @param {Object} [args.author] - The author object.
|
|
5232
|
+
* @param {CommitObject} [args.commit] - A commit object.
|
|
5233
|
+
*
|
|
5234
|
+
* @returns {Promise<void | {name: string, email: string, timestamp: number, timezoneOffset: number }>}
|
|
5235
|
+
*/
|
|
5236
|
+
async function normalizeAuthorObject({ fs, gitdir, author, commit }) {
|
|
5237
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
5238
|
+
|
|
5239
|
+
const defaultAuthor = {
|
|
5240
|
+
name: await _getConfig({ fs, gitdir, path: 'user.name' }),
|
|
5241
|
+
email: (await _getConfig({ fs, gitdir, path: 'user.email' })) || '', // author.email is allowed to be empty string
|
|
5242
|
+
timestamp,
|
|
5243
|
+
timezoneOffset: new Date(timestamp * 1000).getTimezoneOffset(),
|
|
5244
|
+
};
|
|
5245
|
+
|
|
5246
|
+
// Populate author object by using properties with this priority:
|
|
5247
|
+
// (1) provided author object
|
|
5248
|
+
// -> (2) author of provided commit object
|
|
5249
|
+
// -> (3) default author
|
|
5250
|
+
const normalizedAuthor = assignDefined(
|
|
5251
|
+
{},
|
|
5252
|
+
defaultAuthor,
|
|
5253
|
+
commit ? commit.author : undefined,
|
|
5254
|
+
author
|
|
5255
|
+
);
|
|
5256
|
+
|
|
5257
|
+
if (normalizedAuthor.name === undefined) {
|
|
5258
|
+
return undefined
|
|
5259
|
+
}
|
|
5260
|
+
|
|
5261
|
+
return normalizedAuthor
|
|
5262
|
+
}
|
|
5263
|
+
|
|
5264
|
+
/**
|
|
5265
|
+
* Return committer object by using properties with this priority:
|
|
5266
|
+
* (1) provided committer object
|
|
5267
|
+
* -> (2) provided author object
|
|
5268
|
+
* -> (3) committer of provided commit object
|
|
5269
|
+
* -> (4) Config and current date/time
|
|
5270
|
+
*
|
|
5271
|
+
* @param {Object} args
|
|
5272
|
+
* @param {FsClient} args.fs - a file system implementation
|
|
5273
|
+
* @param {string} [args.gitdir] - The [git directory](dir-vs-gitdir.md) path
|
|
5274
|
+
* @param {Object} [args.author] - The author object.
|
|
5275
|
+
* @param {Object} [args.committer] - The committer object.
|
|
5276
|
+
* @param {CommitObject} [args.commit] - A commit object.
|
|
5277
|
+
*
|
|
5278
|
+
* @returns {Promise<void | {name: string, email: string, timestamp: number, timezoneOffset: number }>}
|
|
5279
|
+
*/
|
|
5280
|
+
async function normalizeCommitterObject({
|
|
5281
|
+
fs,
|
|
5282
|
+
gitdir,
|
|
5283
|
+
author,
|
|
5284
|
+
committer,
|
|
5285
|
+
commit,
|
|
5286
|
+
}) {
|
|
5287
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
5288
|
+
|
|
5289
|
+
const defaultCommitter = {
|
|
5290
|
+
name: await _getConfig({ fs, gitdir, path: 'user.name' }),
|
|
5291
|
+
email: (await _getConfig({ fs, gitdir, path: 'user.email' })) || '', // committer.email is allowed to be empty string
|
|
5292
|
+
timestamp,
|
|
5293
|
+
timezoneOffset: new Date(timestamp * 1000).getTimezoneOffset(),
|
|
5294
|
+
};
|
|
5295
|
+
|
|
5296
|
+
const normalizedCommitter = assignDefined(
|
|
5297
|
+
{},
|
|
5298
|
+
defaultCommitter,
|
|
5299
|
+
commit ? commit.committer : undefined,
|
|
5300
|
+
author,
|
|
5301
|
+
committer
|
|
5302
|
+
);
|
|
5303
|
+
|
|
5304
|
+
if (normalizedCommitter.name === undefined) {
|
|
5305
|
+
return undefined
|
|
5306
|
+
}
|
|
5307
|
+
return normalizedCommitter
|
|
5308
|
+
}
|
|
5309
|
+
|
|
5310
|
+
async function resolveCommit({ fs, cache, gitdir, oid }) {
|
|
5311
|
+
const { type, object } = await _readObject({ fs, cache, gitdir, oid });
|
|
5312
|
+
// Resolve annotated tag objects to whatever
|
|
5313
|
+
if (type === 'tag') {
|
|
5314
|
+
oid = GitAnnotatedTag.from(object).parse().object;
|
|
5315
|
+
return resolveCommit({ fs, cache, gitdir, oid })
|
|
5316
|
+
}
|
|
5317
|
+
if (type !== 'commit') {
|
|
5318
|
+
throw new ObjectTypeError(oid, type, 'commit')
|
|
5319
|
+
}
|
|
5320
|
+
return { commit: GitCommit.from(object), oid }
|
|
5321
|
+
}
|
|
5322
|
+
|
|
5323
|
+
// @ts-check
|
|
5324
|
+
|
|
5325
|
+
/**
|
|
5326
|
+
* @param {object} args
|
|
5327
|
+
* @param {import('../models/FileSystem.js').FileSystem} args.fs
|
|
5328
|
+
* @param {any} args.cache
|
|
5329
|
+
* @param {string} args.gitdir
|
|
5330
|
+
* @param {string} args.oid
|
|
5331
|
+
*
|
|
5332
|
+
* @returns {Promise<ReadCommitResult>} Resolves successfully with a git commit object
|
|
5333
|
+
* @see ReadCommitResult
|
|
5334
|
+
* @see CommitObject
|
|
5335
|
+
*
|
|
5336
|
+
*/
|
|
5337
|
+
async function _readCommit({ fs, cache, gitdir, oid }) {
|
|
5338
|
+
const { commit, oid: commitOid } = await resolveCommit({
|
|
5339
|
+
fs,
|
|
5340
|
+
cache,
|
|
5341
|
+
gitdir,
|
|
5342
|
+
oid,
|
|
5343
|
+
});
|
|
5344
|
+
const result = {
|
|
5345
|
+
oid: commitOid,
|
|
5346
|
+
commit: commit.parse(),
|
|
5347
|
+
payload: commit.withoutSignature(),
|
|
5348
|
+
};
|
|
5349
|
+
// @ts-ignore
|
|
5350
|
+
return result
|
|
5351
|
+
}
|
|
5352
|
+
|
|
5353
|
+
// @ts-check
|
|
5354
|
+
|
|
5168
5355
|
/**
|
|
5169
5356
|
*
|
|
5170
5357
|
* @param {Object} args
|
|
@@ -5172,18 +5359,19 @@ async function addToIndex({
|
|
|
5172
5359
|
* @param {object} args.cache
|
|
5173
5360
|
* @param {SignCallback} [args.onSign]
|
|
5174
5361
|
* @param {string} args.gitdir
|
|
5175
|
-
* @param {string} args.message
|
|
5176
|
-
* @param {Object} args.author
|
|
5177
|
-
* @param {string} args.author.name
|
|
5178
|
-
* @param {string} args.author.email
|
|
5179
|
-
* @param {number} args.author.timestamp
|
|
5180
|
-
* @param {number} args.author.timezoneOffset
|
|
5181
|
-
* @param {Object} args.committer
|
|
5182
|
-
* @param {string} args.committer.name
|
|
5183
|
-
* @param {string} args.committer.email
|
|
5184
|
-
* @param {number} args.committer.timestamp
|
|
5185
|
-
* @param {number} args.committer.timezoneOffset
|
|
5362
|
+
* @param {string} [args.message]
|
|
5363
|
+
* @param {Object} [args.author]
|
|
5364
|
+
* @param {string} [args.author.name]
|
|
5365
|
+
* @param {string} [args.author.email]
|
|
5366
|
+
* @param {number} [args.author.timestamp]
|
|
5367
|
+
* @param {number} [args.author.timezoneOffset]
|
|
5368
|
+
* @param {Object} [args.committer]
|
|
5369
|
+
* @param {string} [args.committer.name]
|
|
5370
|
+
* @param {string} [args.committer.email]
|
|
5371
|
+
* @param {number} [args.committer.timestamp]
|
|
5372
|
+
* @param {number} [args.committer.timezoneOffset]
|
|
5186
5373
|
* @param {string} [args.signingKey]
|
|
5374
|
+
* @param {boolean} [args.amend = false]
|
|
5187
5375
|
* @param {boolean} [args.dryRun = false]
|
|
5188
5376
|
* @param {boolean} [args.noUpdateBranch = false]
|
|
5189
5377
|
* @param {string} [args.ref]
|
|
@@ -5198,15 +5386,18 @@ async function _commit({
|
|
|
5198
5386
|
onSign,
|
|
5199
5387
|
gitdir,
|
|
5200
5388
|
message,
|
|
5201
|
-
author,
|
|
5202
|
-
committer,
|
|
5389
|
+
author: _author,
|
|
5390
|
+
committer: _committer,
|
|
5203
5391
|
signingKey,
|
|
5392
|
+
amend = false,
|
|
5204
5393
|
dryRun = false,
|
|
5205
5394
|
noUpdateBranch = false,
|
|
5206
5395
|
ref,
|
|
5207
5396
|
parent,
|
|
5208
5397
|
tree,
|
|
5209
5398
|
}) {
|
|
5399
|
+
// Determine ref and the commit pointed to by ref, and if it is the initial commit
|
|
5400
|
+
let initialCommit = false;
|
|
5210
5401
|
if (!ref) {
|
|
5211
5402
|
ref = await GitRefManager.resolve({
|
|
5212
5403
|
fs,
|
|
@@ -5216,6 +5407,50 @@ async function _commit({
|
|
|
5216
5407
|
});
|
|
5217
5408
|
}
|
|
5218
5409
|
|
|
5410
|
+
let refOid, refCommit;
|
|
5411
|
+
try {
|
|
5412
|
+
refOid = await GitRefManager.resolve({
|
|
5413
|
+
fs,
|
|
5414
|
+
gitdir,
|
|
5415
|
+
ref,
|
|
5416
|
+
});
|
|
5417
|
+
refCommit = await _readCommit({ fs, gitdir, oid: refOid, cache: {} });
|
|
5418
|
+
} catch {
|
|
5419
|
+
// We assume that there's no commit and this is the initial commit
|
|
5420
|
+
initialCommit = true;
|
|
5421
|
+
}
|
|
5422
|
+
|
|
5423
|
+
if (amend && initialCommit) {
|
|
5424
|
+
throw new NoCommitError(ref)
|
|
5425
|
+
}
|
|
5426
|
+
|
|
5427
|
+
// Determine author and committer information
|
|
5428
|
+
const author = !amend
|
|
5429
|
+
? await normalizeAuthorObject({ fs, gitdir, author: _author })
|
|
5430
|
+
: await normalizeAuthorObject({
|
|
5431
|
+
fs,
|
|
5432
|
+
gitdir,
|
|
5433
|
+
author: _author,
|
|
5434
|
+
commit: refCommit.commit,
|
|
5435
|
+
});
|
|
5436
|
+
if (!author) throw new MissingNameError('author')
|
|
5437
|
+
|
|
5438
|
+
const committer = !amend
|
|
5439
|
+
? await normalizeCommitterObject({
|
|
5440
|
+
fs,
|
|
5441
|
+
gitdir,
|
|
5442
|
+
author,
|
|
5443
|
+
committer: _committer,
|
|
5444
|
+
})
|
|
5445
|
+
: await normalizeCommitterObject({
|
|
5446
|
+
fs,
|
|
5447
|
+
gitdir,
|
|
5448
|
+
author,
|
|
5449
|
+
committer: _committer,
|
|
5450
|
+
commit: refCommit.commit,
|
|
5451
|
+
});
|
|
5452
|
+
if (!committer) throw new MissingNameError('committer')
|
|
5453
|
+
|
|
5219
5454
|
return GitIndexManager.acquire(
|
|
5220
5455
|
{ fs, gitdir, cache, allowUnmerged: false },
|
|
5221
5456
|
async function(index) {
|
|
@@ -5224,18 +5459,13 @@ async function _commit({
|
|
|
5224
5459
|
if (!tree) {
|
|
5225
5460
|
tree = await constructTree({ fs, gitdir, inode, dryRun });
|
|
5226
5461
|
}
|
|
5462
|
+
|
|
5463
|
+
// Determine parents of this commit
|
|
5227
5464
|
if (!parent) {
|
|
5228
|
-
|
|
5229
|
-
parent = [
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
gitdir,
|
|
5233
|
-
ref,
|
|
5234
|
-
}),
|
|
5235
|
-
];
|
|
5236
|
-
} catch (err) {
|
|
5237
|
-
// Probably an initial commit
|
|
5238
|
-
parent = [];
|
|
5465
|
+
if (!amend) {
|
|
5466
|
+
parent = refOid ? [refOid] : [];
|
|
5467
|
+
} else {
|
|
5468
|
+
parent = refCommit.commit.parent;
|
|
5239
5469
|
}
|
|
5240
5470
|
} else {
|
|
5241
5471
|
// ensure that the parents are oids, not refs
|
|
@@ -5246,6 +5476,16 @@ async function _commit({
|
|
|
5246
5476
|
);
|
|
5247
5477
|
}
|
|
5248
5478
|
|
|
5479
|
+
// Determine message of this commit
|
|
5480
|
+
if (!message) {
|
|
5481
|
+
if (!amend) {
|
|
5482
|
+
throw new MissingParameterError('message')
|
|
5483
|
+
} else {
|
|
5484
|
+
message = refCommit.commit.message;
|
|
5485
|
+
}
|
|
5486
|
+
}
|
|
5487
|
+
|
|
5488
|
+
// Create and write new Commit object
|
|
5249
5489
|
let comm = GitCommit.from({
|
|
5250
5490
|
tree,
|
|
5251
5491
|
parent,
|
|
@@ -5545,72 +5785,6 @@ async function _addNote({
|
|
|
5545
5785
|
|
|
5546
5786
|
// @ts-check
|
|
5547
5787
|
|
|
5548
|
-
/**
|
|
5549
|
-
* @param {Object} args
|
|
5550
|
-
* @param {import('../models/FileSystem.js').FileSystem} args.fs
|
|
5551
|
-
* @param {string} args.gitdir
|
|
5552
|
-
* @param {string} args.path
|
|
5553
|
-
*
|
|
5554
|
-
* @returns {Promise<any>} Resolves with the config value
|
|
5555
|
-
*
|
|
5556
|
-
* @example
|
|
5557
|
-
* // Read config value
|
|
5558
|
-
* let value = await git.getConfig({
|
|
5559
|
-
* dir: '$input((/))',
|
|
5560
|
-
* path: '$input((user.name))'
|
|
5561
|
-
* })
|
|
5562
|
-
* console.log(value)
|
|
5563
|
-
*
|
|
5564
|
-
*/
|
|
5565
|
-
async function _getConfig({ fs, gitdir, path }) {
|
|
5566
|
-
const config = await GitConfigManager.get({ fs, gitdir });
|
|
5567
|
-
return config.get(path)
|
|
5568
|
-
}
|
|
5569
|
-
|
|
5570
|
-
/**
|
|
5571
|
-
*
|
|
5572
|
-
* @returns {Promise<void | {name: string, email: string, date: Date, timestamp: number, timezoneOffset: number }>}
|
|
5573
|
-
*/
|
|
5574
|
-
async function normalizeAuthorObject({ fs, gitdir, author = {} }) {
|
|
5575
|
-
let { name, email, timestamp, timezoneOffset } = author;
|
|
5576
|
-
name = name || (await _getConfig({ fs, gitdir, path: 'user.name' }));
|
|
5577
|
-
email = email || (await _getConfig({ fs, gitdir, path: 'user.email' })) || '';
|
|
5578
|
-
|
|
5579
|
-
if (name === undefined) {
|
|
5580
|
-
return undefined
|
|
5581
|
-
}
|
|
5582
|
-
|
|
5583
|
-
timestamp = timestamp != null ? timestamp : Math.floor(Date.now() / 1000);
|
|
5584
|
-
timezoneOffset =
|
|
5585
|
-
timezoneOffset != null
|
|
5586
|
-
? timezoneOffset
|
|
5587
|
-
: new Date(timestamp * 1000).getTimezoneOffset();
|
|
5588
|
-
|
|
5589
|
-
return { name, email, timestamp, timezoneOffset }
|
|
5590
|
-
}
|
|
5591
|
-
|
|
5592
|
-
/**
|
|
5593
|
-
*
|
|
5594
|
-
* @returns {Promise<void | {name: string, email: string, timestamp: number, timezoneOffset: number }>}
|
|
5595
|
-
*/
|
|
5596
|
-
async function normalizeCommitterObject({
|
|
5597
|
-
fs,
|
|
5598
|
-
gitdir,
|
|
5599
|
-
author,
|
|
5600
|
-
committer,
|
|
5601
|
-
}) {
|
|
5602
|
-
committer = Object.assign({}, committer || author);
|
|
5603
|
-
// Match committer's date to author's one, if omitted
|
|
5604
|
-
if (author) {
|
|
5605
|
-
committer.timestamp = committer.timestamp || author.timestamp;
|
|
5606
|
-
committer.timezoneOffset = committer.timezoneOffset || author.timezoneOffset;
|
|
5607
|
-
}
|
|
5608
|
-
committer = await normalizeAuthorObject({ fs, gitdir, author: committer });
|
|
5609
|
-
return committer
|
|
5610
|
-
}
|
|
5611
|
-
|
|
5612
|
-
// @ts-check
|
|
5613
|
-
|
|
5614
5788
|
/**
|
|
5615
5789
|
* Add or update an object note
|
|
5616
5790
|
*
|
|
@@ -7446,8 +7620,8 @@ function filterCapabilities(server, client) {
|
|
|
7446
7620
|
|
|
7447
7621
|
const pkg = {
|
|
7448
7622
|
name: 'isomorphic-git',
|
|
7449
|
-
version: '1.
|
|
7450
|
-
agent: 'git/isomorphic-git@1.
|
|
7623
|
+
version: '1.27.0',
|
|
7624
|
+
agent: 'git/isomorphic-git@1.27.0',
|
|
7451
7625
|
};
|
|
7452
7626
|
|
|
7453
7627
|
class FIFO {
|
|
@@ -8397,7 +8571,6 @@ async function clone({
|
|
|
8397
8571
|
}
|
|
8398
8572
|
|
|
8399
8573
|
// @ts-check
|
|
8400
|
-
|
|
8401
8574
|
/**
|
|
8402
8575
|
* Create a new commit
|
|
8403
8576
|
*
|
|
@@ -8406,7 +8579,7 @@ async function clone({
|
|
|
8406
8579
|
* @param {SignCallback} [args.onSign] - a PGP signing implementation
|
|
8407
8580
|
* @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
|
|
8408
8581
|
* @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
|
|
8409
|
-
* @param {string} args.message - The commit message to use.
|
|
8582
|
+
* @param {string} [args.message] - The commit message to use. Required, unless `amend === true`
|
|
8410
8583
|
* @param {Object} [args.author] - The details about the author.
|
|
8411
8584
|
* @param {string} [args.author.name] - Default is `user.name` config.
|
|
8412
8585
|
* @param {string} [args.author.email] - Default is `user.email` config.
|
|
@@ -8418,6 +8591,7 @@ async function clone({
|
|
|
8418
8591
|
* @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).
|
|
8419
8592
|
* @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()`.
|
|
8420
8593
|
* @param {string} [args.signingKey] - Sign the tag object using this private PGP key.
|
|
8594
|
+
* @param {boolean} [args.amend = false] - If true, replaces the last commit pointed to by `ref` with a new commit.
|
|
8421
8595
|
* @param {boolean} [args.dryRun = false] - If true, simulates making a commit so you can test whether it would succeed. Implies `noUpdateBranch`.
|
|
8422
8596
|
* @param {boolean} [args.noUpdateBranch = false] - If true, does not update the branch pointer after creating the commit.
|
|
8423
8597
|
* @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.)
|
|
@@ -8446,9 +8620,10 @@ async function commit({
|
|
|
8446
8620
|
dir,
|
|
8447
8621
|
gitdir = join(dir, '.git'),
|
|
8448
8622
|
message,
|
|
8449
|
-
author
|
|
8450
|
-
committer
|
|
8623
|
+
author,
|
|
8624
|
+
committer,
|
|
8451
8625
|
signingKey,
|
|
8626
|
+
amend = false,
|
|
8452
8627
|
dryRun = false,
|
|
8453
8628
|
noUpdateBranch = false,
|
|
8454
8629
|
ref,
|
|
@@ -8458,23 +8633,14 @@ async function commit({
|
|
|
8458
8633
|
}) {
|
|
8459
8634
|
try {
|
|
8460
8635
|
assertParameter('fs', _fs);
|
|
8461
|
-
|
|
8636
|
+
if (!amend) {
|
|
8637
|
+
assertParameter('message', message);
|
|
8638
|
+
}
|
|
8462
8639
|
if (signingKey) {
|
|
8463
8640
|
assertParameter('onSign', onSign);
|
|
8464
8641
|
}
|
|
8465
8642
|
const fs = new FileSystem(_fs);
|
|
8466
8643
|
|
|
8467
|
-
const author = await normalizeAuthorObject({ fs, gitdir, author: _author });
|
|
8468
|
-
if (!author) throw new MissingNameError('author')
|
|
8469
|
-
|
|
8470
|
-
const committer = await normalizeCommitterObject({
|
|
8471
|
-
fs,
|
|
8472
|
-
gitdir,
|
|
8473
|
-
author,
|
|
8474
|
-
committer: _committer,
|
|
8475
|
-
});
|
|
8476
|
-
if (!committer) throw new MissingNameError('committer')
|
|
8477
|
-
|
|
8478
8644
|
return await _commit({
|
|
8479
8645
|
fs,
|
|
8480
8646
|
cache,
|
|
@@ -8484,6 +8650,7 @@ async function commit({
|
|
|
8484
8650
|
author,
|
|
8485
8651
|
committer,
|
|
8486
8652
|
signingKey,
|
|
8653
|
+
amend,
|
|
8487
8654
|
dryRun,
|
|
8488
8655
|
noUpdateBranch,
|
|
8489
8656
|
ref,
|
|
@@ -11209,49 +11376,6 @@ async function listTags({ fs, dir, gitdir = join(dir, '.git') }) {
|
|
|
11209
11376
|
}
|
|
11210
11377
|
}
|
|
11211
11378
|
|
|
11212
|
-
async function resolveCommit({ fs, cache, gitdir, oid }) {
|
|
11213
|
-
const { type, object } = await _readObject({ fs, cache, gitdir, oid });
|
|
11214
|
-
// Resolve annotated tag objects to whatever
|
|
11215
|
-
if (type === 'tag') {
|
|
11216
|
-
oid = GitAnnotatedTag.from(object).parse().object;
|
|
11217
|
-
return resolveCommit({ fs, cache, gitdir, oid })
|
|
11218
|
-
}
|
|
11219
|
-
if (type !== 'commit') {
|
|
11220
|
-
throw new ObjectTypeError(oid, type, 'commit')
|
|
11221
|
-
}
|
|
11222
|
-
return { commit: GitCommit.from(object), oid }
|
|
11223
|
-
}
|
|
11224
|
-
|
|
11225
|
-
// @ts-check
|
|
11226
|
-
|
|
11227
|
-
/**
|
|
11228
|
-
* @param {object} args
|
|
11229
|
-
* @param {import('../models/FileSystem.js').FileSystem} args.fs
|
|
11230
|
-
* @param {any} args.cache
|
|
11231
|
-
* @param {string} args.gitdir
|
|
11232
|
-
* @param {string} args.oid
|
|
11233
|
-
*
|
|
11234
|
-
* @returns {Promise<ReadCommitResult>} Resolves successfully with a git commit object
|
|
11235
|
-
* @see ReadCommitResult
|
|
11236
|
-
* @see CommitObject
|
|
11237
|
-
*
|
|
11238
|
-
*/
|
|
11239
|
-
async function _readCommit({ fs, cache, gitdir, oid }) {
|
|
11240
|
-
const { commit, oid: commitOid } = await resolveCommit({
|
|
11241
|
-
fs,
|
|
11242
|
-
cache,
|
|
11243
|
-
gitdir,
|
|
11244
|
-
oid,
|
|
11245
|
-
});
|
|
11246
|
-
const result = {
|
|
11247
|
-
oid: commitOid,
|
|
11248
|
-
commit: commit.parse(),
|
|
11249
|
-
payload: commit.withoutSignature(),
|
|
11250
|
-
};
|
|
11251
|
-
// @ts-ignore
|
|
11252
|
-
return result
|
|
11253
|
-
}
|
|
11254
|
-
|
|
11255
11379
|
function compareAge(a, b) {
|
|
11256
11380
|
return a.committer.timestamp - b.committer.timestamp
|
|
11257
11381
|
}
|
|
@@ -12467,7 +12591,12 @@ async function _push({
|
|
|
12467
12591
|
}
|
|
12468
12592
|
|
|
12469
12593
|
// Update the local copy of the remote ref
|
|
12470
|
-
if (
|
|
12594
|
+
if (
|
|
12595
|
+
remote &&
|
|
12596
|
+
result.ok &&
|
|
12597
|
+
result.refs[fullRemoteRef].ok &&
|
|
12598
|
+
!fullRef.startsWith('refs/tags')
|
|
12599
|
+
) {
|
|
12471
12600
|
// TODO: I think this should actually be using a refspec transform rather than assuming 'refs/remotes/{remote}'
|
|
12472
12601
|
const ref = `refs/remotes/${remote}/${fullRemoteRef.replace(
|
|
12473
12602
|
'refs/heads',
|
|
@@ -12514,7 +12643,7 @@ async function _push({
|
|
|
12514
12643
|
* @param {PrePushCallback} [args.onPrePush] - optional pre-push hook callback
|
|
12515
12644
|
* @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
|
|
12516
12645
|
* @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
|
|
12517
|
-
* @param {string} [args.ref] - Which branch to push. By default this is the currently checked out branch.
|
|
12646
|
+
* @param {string} [args.ref] - Which branch or tag to push. By default this is the currently checked out branch.
|
|
12518
12647
|
* @param {string} [args.url] - The URL of the remote repository. The default is the value set in the git config for that remote.
|
|
12519
12648
|
* @param {string} [args.remote] - If URL is not specified, determines which remote to use.
|
|
12520
12649
|
* @param {string} [args.remoteRef] - The name of the receiving branch on the remote. By default this is the configured remote tracking branch.
|
package/index.umd.min.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;
|
|
@@ -2463,7 +2466,7 @@ export function pull({ fs: _fs, http, onProgress, onMessage, onAuth, onAuthSucce
|
|
|
2463
2466
|
* @param {PrePushCallback} [args.onPrePush] - optional pre-push hook callback
|
|
2464
2467
|
* @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
|
|
2465
2468
|
* @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
|
|
2466
|
-
* @param {string} [args.ref] - Which branch to push. By default this is the currently checked out branch.
|
|
2469
|
+
* @param {string} [args.ref] - Which branch or tag to push. By default this is the currently checked out branch.
|
|
2467
2470
|
* @param {string} [args.url] - The URL of the remote repository. The default is the value set in the git config for that remote.
|
|
2468
2471
|
* @param {string} [args.remote] - If URL is not specified, determines which remote to use.
|
|
2469
2472
|
* @param {string} [args.remoteRef] - The name of the receiving branch on the remote. By default this is the configured remote tracking branch.
|
|
@@ -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
|