|
1 |
| -# Git-Parse |
| 1 | +Git-Parse |
| 2 | +========= |
2 | 3 |
|
3 |
| -`git-parse` is a utility which generates an array of javascript objects representing the current branch of a local git repository's commit history. |
| 4 | +[](https://www.npmjs.com/package/git-parse) |
| 5 | +[](https://www.npmjs.org/package/git-parse) |
| 6 | +[](https://bundlephobia.com/result?p=git-parse) |
4 | 7 |
|
5 |
| -## Getting Started |
| 8 | +> `git-parse` is a utility which generates an array of javascript objects representing the current branch of a local git repository's commit history. |
6 | 9 |
|
7 |
| -### Prerequisites |
| 10 | +### Details |
8 | 11 |
|
9 |
| -``` |
10 |
| -nodejs version 14 or higher |
11 |
| -``` |
| 12 | +- Support NodeJS >= 14 |
12 | 13 |
|
13 | 14 | ### Installation
|
14 | 15 |
|
15 |
| -``` |
16 |
| -npm i git-parse |
| 16 | +```bash |
| 17 | +npm install git-parse |
17 | 18 | ```
|
18 | 19 |
|
19 | 20 | ### Usage
|
20 | 21 |
|
21 |
| -``` |
| 22 | +```js |
22 | 23 | const { gitToJs } = require('git-parse');
|
23 | 24 |
|
24 | 25 | const commitsPromise = gitToJs('path/to/repo/');
|
25 | 26 |
|
26 | 27 | commitsPromise.then(commits => console.log(JSON.stringify(commits, null, 2)));
|
27 |
| -
|
28 | 28 | ```
|
29 | 29 |
|
30 |
| -**Console Output:** |
31 |
| - |
32 |
| -``` |
33 |
| -[ |
34 |
| - { |
35 |
| - "hash":"7cedc121ee163d859dfdb9911e627d4b5933cc6d", |
36 |
| - |
37 |
| - "authorEmail":"[email protected]", |
38 |
| - "date":"Wed, 10 Jan 2018 16:44:52 -0500", |
39 |
| - "message":"initial setup", |
40 |
| - "filesAdded":[ |
41 |
| - { "path":"packages/raspberry-popsicle/index.js" }, |
42 |
| - { "path":"packages/raspberry-popsicle/package-lock.json" }, |
43 |
| - { "path":"packages/raspberry-popsicle/package.json" } |
44 |
| - ], |
45 |
| - "filesDeleted":[ ], |
46 |
| - "filesModified":[ ], |
47 |
| - "filesRenamed":[ ] |
48 |
| - }, |
49 |
| - { |
50 |
| - "hash": "226f032eb87ac1eb18b7212eeaf1356980a9ae03", |
51 |
| - "authorName": "[email protected]", |
52 |
| - "authorEmail": "[email protected]", |
53 |
| - "date": "Wed, 10 Jan 2018 15:25:16 -0500", |
54 |
| - "message": "add README", |
55 |
| - "filesAdded": [ |
56 |
| - { "path": "README.md" } |
57 |
| - ], |
58 |
| - "filesDeleted": [], |
59 |
| - "filesModified": [], |
60 |
| - "filesRenamed": [] |
61 |
| - } |
62 |
| -] |
63 |
| -``` |
| 30 | +<details> |
| 31 | + <summary><b>Console output:</b></summary> |
| 32 | + |
| 33 | + ```json |
| 34 | + [ |
| 35 | + { |
| 36 | + "hash": "7cedc121ee163d859dfdb9911e627d4b5933cc6d", |
| 37 | + "authorName": "[email protected]", |
| 38 | + "authorEmail": "[email protected]", |
| 39 | + "date": "Wed, 10 Jan 2018 16:44:52 -0500", |
| 40 | + "message": "initial setup", |
| 41 | + "filesAdded":[ |
| 42 | + { "path": "packages/raspberry-popsicle/index.js" }, |
| 43 | + { "path": "packages/raspberry-popsicle/package-lock.json" }, |
| 44 | + { "path": "packages/raspberry-popsicle/package.json" } |
| 45 | + ], |
| 46 | + "filesDeleted": [], |
| 47 | + "filesModified": [], |
| 48 | + "filesRenamed": [] |
| 49 | + }, |
| 50 | + { |
| 51 | + "hash": "226f032eb87ac1eb18b7212eeaf1356980a9ae03", |
| 52 | + "authorName": "[email protected]", |
| 53 | + "authorEmail": "[email protected]", |
| 54 | + "date": "Wed, 10 Jan 2018 15:25:16 -0500", |
| 55 | + "message": "add README", |
| 56 | + "filesAdded": [ |
| 57 | + { "path": "README.md" } |
| 58 | + ], |
| 59 | + "filesDeleted": [], |
| 60 | + "filesModified": [], |
| 61 | + "filesRenamed": [] |
| 62 | + } |
| 63 | + ] |
| 64 | + ``` |
| 65 | +</details> |
64 | 66 |
|
65 | 67 | ## API
|
66 | 68 |
|
67 |
| -### gitToJs(pathToRepo, [options]) |
| 69 | +### .gitToJs(pathToRepo, [options]) |
68 | 70 |
|
69 | 71 | 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.
|
70 | 72 |
|
71 |
| -``` |
| 73 | +```js |
72 | 74 | const { gitToJs } = require('git-parse');
|
73 | 75 |
|
74 | 76 | const commitsPromise = gitToJs('path/to/repo/');
|
75 | 77 |
|
76 | 78 | commitsPromise.then(commits => console.log(JSON.stringify(commits, null, 2)));
|
77 | 79 | ```
|
78 | 80 |
|
79 |
| -### checkOutCommit(pathToRepo, commitHash, [options]) |
| 81 | +### .checkOutCommit(pathToRepo, commitHash, [options]) |
80 | 82 |
|
81 | 83 | 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](https://git-scm.com/docs/git-checkout#git-checkout--f). Returns a promise.
|
82 | 84 |
|
83 |
| -### gitPull(pathToRepo) |
| 85 | +### .gitPull(pathToRepo) |
84 | 86 |
|
85 | 87 | Runs 'git pull' on the repository at the given path. Returns a promise.
|
86 | 88 |
|
87 |
| -### gitDiff(pathToRepo, commitHash1, [commitHash2], [file]) |
| 89 | +### .gitDiff(pathToRepo, commitHash1, [commitHash2], [file]) |
88 | 90 |
|
89 | 91 | Returns a git diff given a path to the repo, a commit, an optional second commit, and an optional file path.
|
90 | 92 |
|
|
0 commit comments