Skip to content

Instantly share code, notes, and snippets.

@korzio korzio/commit.ts
Created May 5, 2019

What would you like to do?
import {Hook} from '@oclif/config'
import * as nodegit from 'nodegit'
import * as path from 'path'
const hook: Hook<'commit'> = async function ({id, file: fileName}) {
const directoryName = process.cwd()
const repo = await, '.git'))
const index = await repo.refreshIndex()
await index.addByPath(fileName)
await index.write()
const oid = await index.writeTree()
const head = await nodegit.Reference.nameToId(repo, "HEAD")
const parent = await repo.getCommit(head)
const author ="Scott Chacon", "")
const committer ="Scott A Chacon", "")
const commitId = await repo.createCommit("HEAD", author, committer, `${id} note ${fileName}`, oid, [parent])
console.log("New Commit: ", commitId)
export default hook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.