Created
May 5, 2019 11:45
-
-
Save korzio/51250cf9b26820d1d372bb0922c4d4dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 nodegit.Repository.open(path.resolve(directoryName, '.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 = nodegit.Signature.now("Scott Chacon", "schacon@gmail.com") | |
const committer = nodegit.Signature.now("Scott A Chacon", "scott@github.com") | |
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