Package Exports
- git-parse
- git-parse/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (git-parse) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Git-Parse
git-parseis a utility which generates an array of javascript objects representing the current branch of a local git repository's commit history.
Details
- Support NodeJS >= 14
Installation
npm install git-parseUsage
const { gitToJs } = require('git-parse');
const commitsPromise = gitToJs('path/to/repo/');
commitsPromise.then(commits => console.log(JSON.stringify(commits, null, 2)));Console output:
[
{
"hash": "7cedc121ee163d859dfdb9911e627d4b5933cc6d",
"authorName": "mpackard@wayfair.com",
"authorEmail": "mpackard@wayfair.com",
"date": "Wed, 10 Jan 2018 16:44:52 -0500",
"message": "initial setup",
"filesAdded":[
{ "path": "packages/raspberry-popsicle/index.js" },
{ "path": "packages/raspberry-popsicle/package-lock.json" },
{ "path": "packages/raspberry-popsicle/package.json" }
],
"filesDeleted": [],
"filesModified": [],
"filesRenamed": []
},
{
"hash": "226f032eb87ac1eb18b7212eeaf1356980a9ae03",
"authorName": "mpackard@wayfair.com",
"authorEmail": "mpackard@wayfair.com",
"date": "Wed, 10 Jan 2018 15:25:16 -0500",
"message": "add README",
"filesAdded": [
{ "path": "README.md" }
],
"filesDeleted": [],
"filesModified": [],
"filesRenamed": []
}
]API
.gitToJs(pathToRepo, [options])
Returns a promise which resolves with a list of objects describing git commits on the current branch. pathToRepo is a string. options is an optional object with one property, sinceCommit, which is a commit hash. If sinceCommit is present, gitToJs will return logs for commits after the commit specified.
const { gitToJs } = require('git-parse');
const commitsPromise = gitToJs('path/to/repo/');
commitsPromise.then(commits => console.log(JSON.stringify(commits, null, 2)));.checkOutCommit(pathToRepo, commitHash, [options])
Checks a repository out to a given commit. hash is the commit hash. Options is an optional object with one property, force. force adds --force to the underlying git checkout. Returns a promise.
.gitPull(pathToRepo)
Runs 'git pull' on the repository at the given path. Returns a promise.
.gitDiff(pathToRepo, commitHash1, [commitHash2], [file])
Returns a git diff given a path to the repo, a commit, an optional second commit, and an optional file path.
Returns a promise resolving with the diff as a string.
Development
Build
To generate a local distribution for the git-parse library run the following command:
yarn buildTo build the library in the background on file changes, use:
yarn build:watchCode Formatting
To automatically format the code using Prettier run:
yarn formator
yarn format:checkLinting
To lint the project using ESLint run:
yarn lintTests
To run the project tests using the Jest framework run:
yarn testType Checking
To check the project for type errors using Typescript run:
yarn tscUse --watch to run the type checker in the background:
yarn tsc --watchLicense
This project is licensed under the BSD-2-Clause license.