({
fs,
cache,
onSign,
gitdir,
message,
author: _author,
committer: _committer,
signingKey,
amend = false,
dryRun = false,
noUpdateBranch = false,
ref,
parent,
tree,
})
| 44 | * @returns {Promise<string>} Resolves successfully with the SHA-1 object id of the newly created commit. |
| 45 | */ |
| 46 | export async function _commit({ |
| 47 | fs, |
| 48 | cache, |
| 49 | onSign, |
| 50 | gitdir, |
| 51 | message, |
| 52 | author: _author, |
| 53 | committer: _committer, |
| 54 | signingKey, |
| 55 | amend = false, |
| 56 | dryRun = false, |
| 57 | noUpdateBranch = false, |
| 58 | ref, |
| 59 | parent, |
| 60 | tree, |
| 61 | }) { |
| 62 | // Determine ref and the commit pointed to by ref, and if it is the initial commit |
| 63 | let initialCommit = false |
| 64 | let detachedHead = false |
| 65 | if (!ref) { |
| 66 | const headContent = await fs.read(`${gitdir}/HEAD`, { encoding: 'utf8' }) |
| 67 | detachedHead = !headContent.startsWith('ref:') |
| 68 | ref = await GitRefManager.resolve({ |
| 69 | fs, |
| 70 | gitdir, |
| 71 | ref: 'HEAD', |
| 72 | depth: 2, |
| 73 | }) |
| 74 | } |
| 75 | |
| 76 | let refOid, refCommit |
| 77 | try { |
| 78 | refOid = await GitRefManager.resolve({ |
| 79 | fs, |
| 80 | gitdir, |
| 81 | ref, |
| 82 | }) |
| 83 | refCommit = await readCommit({ fs, gitdir, oid: refOid, cache: {} }) |
| 84 | } catch { |
| 85 | // We assume that there's no commit and this is the initial commit |
| 86 | initialCommit = true |
| 87 | } |
| 88 | |
| 89 | if (amend && initialCommit) { |
| 90 | throw new NoCommitError(ref) |
| 91 | } |
| 92 | |
| 93 | // Determine author and committer information |
| 94 | const author = !amend |
| 95 | ? await normalizeAuthorObject({ fs, gitdir, author: _author }) |
| 96 | : await normalizeAuthorObject({ |
| 97 | fs, |
| 98 | gitdir, |
| 99 | author: _author, |
| 100 | commit: refCommit.commit, |
| 101 | }) |
| 102 | if (!author) throw new MissingNameError('author') |
| 103 |
no test coverage detected
searching dependent graphs…