1 | # node-gitlog
|
2 |
|
3 | Git log parser for Node.JS
|
4 |
|
5 | [![build status](https://api.travis-ci.org/domharrington/node-gitlog.svg)](http://travis-ci.org/domharrington/node-gitlog)
|
6 | [![dependency status](https://david-dm.org/domharrington/node-gitlog.svg)](https://david-dm.org/domharrington/node-gitlog)
|
7 |
|
8 | ## Installation
|
9 |
|
10 | ```sh
|
11 | npm install gitlog --save
|
12 | ```
|
13 |
|
14 | ## Usage
|
15 |
|
16 | ```js
|
17 | const gitlog = require("gitlog").default;
|
18 |
|
19 | const options = {
|
20 | repo: __dirname + "/test-repo-folder",
|
21 | number: 20,
|
22 | author: "Dom Harrington",
|
23 | fields: ["hash", "abbrevHash", "subject", "authorName", "authorDateRel"],
|
24 | execOptions: { maxBuffer: 1000 * 1024 },
|
25 | };
|
26 |
|
27 | // Synchronous
|
28 | const commits = gitlog(options);
|
29 | console.log(commits);
|
30 |
|
31 | // Asynchronous (with Callback)
|
32 | gitlog(options, function (error, commits) {
|
33 | // Commits is an array of commits in the repo
|
34 | console.log(commits);
|
35 | });
|
36 |
|
37 | const { gitlogPromise } = require("gitlog");
|
38 |
|
39 | // Asynchronous (with Promise)
|
40 | gitlogPromise(options)
|
41 | .then((commits) => console.log(commits))
|
42 | .catch((err) => console.log(err));
|
43 | ```
|
44 |
|
45 | `gitlog` comes with full typescript support!
|
46 |
|
47 | ```ts
|
48 | import gitlog, { GitlogOptions } from "gitlog";
|
49 |
|
50 | // Option 1: Just use the function, returned commit type has specified fields
|
51 | gitlog({
|
52 | repo: "foo",
|
53 | fields: ["subject", "authorName", "authorDate"],
|
54 | });
|
55 |
|
56 | // Option 2: Use Options type to create options
|
57 | const options: GitlogOptions<"subject" | "authorName" | "authorDate"> = {
|
58 | repo: "foo",
|
59 | fields: ["subject", "authorName", "authorDate"],
|
60 | };
|
61 |
|
62 | gitlog(options);
|
63 |
|
64 | // Option 3: Typescript Magic
|
65 | const options = {
|
66 | repo: "foo",
|
67 | fields: ["subject", "authorName", "authorDate"] as const,
|
68 | };
|
69 |
|
70 | gitlog(options);
|
71 |
|
72 | // NOT SUPPORTED: Without "as const" gitlog can't create a good return type
|
73 | const options = {
|
74 | repo: "foo",
|
75 | fields: ["subject", "authorName", "authorDate"],
|
76 | };
|
77 |
|
78 | gitlog(options);
|
79 | ```
|
80 |
|
81 | ## Options
|
82 |
|
83 | See [git log](http://git-scm.com/docs/git-log)
|
84 |
|
85 | ### repo
|
86 |
|
87 | The location of the repo, required field.
|
88 |
|
89 | ### number
|
90 |
|
91 | The number of commits to return, defaults to 10.
|
92 |
|
93 | ### since/after
|
94 |
|
95 | Show commits more recent than a specific date.
|
96 |
|
97 | ### until/before
|
98 |
|
99 | Show commits older than a specific date.
|
100 |
|
101 | ### author/committer
|
102 |
|
103 | Limit the commits output to ones with author/committer header lines that match the specified pattern.
|
104 |
|
105 | ### nameStatus
|
106 |
|
107 | Below fields was returned from the log:
|
108 |
|
109 | - files - changed files names (array)
|
110 | - status - changed files status (array)
|
111 |
|
112 | This option is enabled by default.
|
113 |
|
114 | ### findCopiesHarder
|
115 |
|
116 | Much more likely to set status codes to 'C' if files are exact copies of each other.
|
117 |
|
118 | This option is disabled by default.
|
119 |
|
120 | ### includeMergeCommitFiles
|
121 |
|
122 | Pass the `-m` option to includes files in a merge commit.
|
123 |
|
124 | This option is disabled by default.
|
125 |
|
126 | ### all
|
127 |
|
128 | Find commits on all branches instead of just on the current one.
|
129 |
|
130 | This option is disabled by default.
|
131 |
|
132 | ### branch ([revision range](https://git-scm.com/docs/git-log#git-log-ltrevisionrangegt))
|
133 |
|
134 | Show only commits in the specified branch or revision range.
|
135 |
|
136 | By default uses the current branch and defaults to `HEAD` (i.e. the whole history leading to the current commit).
|
137 |
|
138 | ### fileLineRange
|
139 |
|
140 | Optional field for getting only the commits that affected a specific line range of a given file.
|
141 |
|
142 | ### file
|
143 |
|
144 | Optional file filter for the `git log` command
|
145 |
|
146 | ### execOptions
|
147 |
|
148 | Type: `Object`
|
149 |
|
150 | Specify some options to be passed to the [.exec()](http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback) method:
|
151 |
|
152 | - `cwd` String _Current working directory of the child process_
|
153 | - `env` Object _Environment key-value pairs_
|
154 | - `setsid` Boolean
|
155 | - `encoding` String _(Default: 'utf8')_
|
156 | - `timeout` Number _(Default: 0)_
|
157 | - `maxBuffer` Number _(Default: 200\*1024)_
|
158 | - `killSignal` String _(Default: 'SIGTERM')_
|
159 |
|
160 | ### optional fields
|
161 |
|
162 | An array of fields to return from the log, here are the possible options:
|
163 |
|
164 | - `hash` - the long hash of the commit e.g. 7dd0b07625203f69cd55d779d873f1adcffaa84a
|
165 | - `abbrevHash` - the abbreviated commit hash e.g. 7dd0b07
|
166 | - `treeHash` - the tree hash of the commit
|
167 | - `abbrevTreeHash` - the abbreviated commit hash
|
168 | - `parentHashes` - the parent hashes
|
169 | - `abbrevParentHashes` - the abbreviated parent hashes
|
170 | - `authorName` - author name of the commit
|
171 | - `authorEmail` - author email of the commit
|
172 | - `authorDate` - author date of the commit
|
173 | - `authorDateRel` - relative author date of the commit
|
174 | - `committerName` - committer name
|
175 | - `committerEmail` - committer email
|
176 | - `committerDate` - committer date
|
177 | - `committerDateRel` - relative committer date
|
178 | - `subject` - commit message (first line)
|
179 | - `body` - commit body
|
180 | - `rawBody` - raw body (subject + body)
|
181 | - `tag` - raw tag information of commit
|
182 |
|
183 | Defaults to 'abbrevHash', 'hash', 'subject' and 'authorName'.
|
184 |
|
185 | ## How it works
|
186 |
|
187 | This module works by executing a child process (using `child_process.exec()`) to the `git` executable, then parsing the stdout into commits. This is done using the `--pretty` command line option which allows you to provide a custom formatter to `git log`. To enable easy parsing the format is delimited by a tab (`\t`) character.
|
188 |
|
189 | ## Example
|
190 |
|
191 | The following is an example of what a parsed commit might look like.
|
192 |
|
193 | ```json
|
194 | {
|
195 | "hash": "6a7ef5e3b3d9c77743140443c8f9e792b0715721",
|
196 | "abbrevHash": "6a7ef5e",
|
197 | "treeHash": "f1bf51b15b48a00c33727f364afef695029864c0",
|
198 | "abbrevTreeHash": "f1bf51b",
|
199 | "parentHashes": "cfe06dbdb8d0a193640977e016a04678f8f3b04f",
|
200 | "abbrevParentHashes": "cfe06dbdb8d0a193640977e016a04678f8f3b04f",
|
201 | "authorName": "Dom Harrington",
|
202 | "authorEmail": "dom@harringtonxxxxx",
|
203 | "authorDate": "2015-04-09 09:39:23 +0100",
|
204 | "authorDateRel": "6 days ago",
|
205 | "committerName": "Dom Harrington",
|
206 | "committerEmail": "dom@harringtonxxxxx",
|
207 | "committerDate": "Thu Apr 9 09:39:23 2015 +0100",
|
208 | "committerDateRel": "6 days ago",
|
209 | "subject": "1.0.0",
|
210 | "status": ["M"],
|
211 | "files": ["package.json"]
|
212 | }
|
213 | ```
|
214 |
|
215 | ## Contributors β¨
|
216 |
|
217 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
218 |
|
219 |
|
220 |
|
221 |
|
222 | <table>
|
223 | <tr>
|
224 | <td align="center"><a href="https://github.com/domharrington"><img src="https://avatars0.githubusercontent.com/u/848223?v=4?s=100" width="100px;" alt=""/><br /><sub><b>domharrington</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=domharrington" title="Code">π»</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=domharrington" title="Documentation">π</a> <a href="#example-domharrington" title="Examples">π‘</a> <a href="#ideas-domharrington" title="Ideas, Planning, & Feedback">π€</a></td>
|
225 | <td align="center"><a href="http://hipstersmoothie.com"><img src="https://avatars3.githubusercontent.com/u/1192452?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Andrew Lisowski</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=hipstersmoothie" title="Code">π»</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=hipstersmoothie" title="Documentation">π</a> <a href="#infra-hipstersmoothie" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#maintenance-hipstersmoothie" title="Maintenance">π§</a></td>
|
226 | <td align="center"><a href="http://metaodi.ch"><img src="https://avatars1.githubusercontent.com/u/538415?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stefan Oderbolz</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/issues?q=author%3Ametaodi" title="Bug reports">π</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=metaodi" title="Code">π»</a></td>
|
227 | <td align="center"><a href="https://github.com/palortoff"><img src="https://avatars1.githubusercontent.com/u/10258543?v=4?s=100" width="100px;" alt=""/><br /><sub><b>palortoff</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/issues?q=author%3Apalortoff" title="Bug reports">π</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=palortoff" title="Code">π»</a></td>
|
228 | <td align="center"><a href="https://malys.github.io/"><img src="https://avatars1.githubusercontent.com/u/463016?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Malys</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/issues?q=author%3Amalys" title="Bug reports">π</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=malys" title="Code">π»</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=malys" title="Documentation">π</a></td>
|
229 | <td align="center"><a href="http://CodeGymSleep.com/"><img src="https://avatars3.githubusercontent.com/u/6986032?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mike Mellor</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=mikemellor11" title="Code">π»</a></td>
|
230 | <td align="center"><a href="https://github.com/hmedney"><img src="https://avatars3.githubusercontent.com/u/1221751?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hunter Medney</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=hmedney" title="Code">π»</a></td>
|
231 | </tr>
|
232 | <tr>
|
233 | <td align="center"><a href="https://github.com/Gilwyad"><img src="https://avatars3.githubusercontent.com/u/1919041?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Peter Baranyi</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=Gilwyad" title="Code">π»</a> <a href="https://github.com/domharrington/node-gitlog/issues?q=author%3AGilwyad" title="Bug reports">π</a></td>
|
234 | <td align="center"><a href="https://twitter.com/B_Blackwo"><img src="https://avatars0.githubusercontent.com/u/7598058?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Benjamin Blackwood</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=BBlackwo" title="Documentation">π</a></td>
|
235 | <td align="center"><a href="https://github.com/Asheboy"><img src="https://avatars1.githubusercontent.com/u/1822529?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ash Summers</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=Asheboy" title="Code">π»</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=Asheboy" title="Tests">β οΈ</a></td>
|
236 | <td align="center"><a href="https://github.com/007design"><img src="https://avatars0.githubusercontent.com/u/1998403?v=4?s=100" width="100px;" alt=""/><br /><sub><b>007design</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=007design" title="Code">π»</a></td>
|
237 | <td align="center"><a href="https://github.com/tobaccoplaybook"><img src="https://avatars2.githubusercontent.com/u/21124900?v=4?s=100" width="100px;" alt=""/><br /><sub><b>tobaccoplaybook</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=tobaccoplaybook" title="Code">π»</a></td>
|
238 | <td align="center"><a href="http://nicola.io"><img src="https://avatars1.githubusercontent.com/u/1424850?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nicola</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=nicola" title="Code">π»</a></td>
|
239 | <td align="center"><a href="http://bluelovers.net"><img src="https://avatars0.githubusercontent.com/u/167966?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bluelovers</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=bluelovers" title="Code">π»</a></td>
|
240 | </tr>
|
241 | <tr>
|
242 | <td align="center"><a href="https://github.com/afram"><img src="https://avatars0.githubusercontent.com/u/2238230?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Marwan Butrous</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=afram" title="Code">π»</a></td>
|
243 | <td align="center"><a href="https://github.com/FishOrBear"><img src="https://avatars0.githubusercontent.com/u/19372111?v=4?s=100" width="100px;" alt=""/><br /><sub><b>FishOrBear</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=FishOrBear" title="Code">π»</a></td>
|
244 | <td align="center"><a href="https://github.com/Asjidkalam"><img src="https://avatars1.githubusercontent.com/u/16708391?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Asjid Kalam</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=Asjidkalam" title="Code">π»</a></td>
|
245 | <td align="center"><a href="https://418sec.com/"><img src="https://avatars0.githubusercontent.com/u/55323451?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jamie Slome</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=JamieSlome" title="Code">π»</a></td>
|
246 | <td align="center"><a href="https://huntr.dev/"><img src="https://avatars0.githubusercontent.com/u/61279246?v=4?s=100" width="100px;" alt=""/><br /><sub><b>huntr-helper</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=huntr-helper" title="Code">π»</a></td>
|
247 | <td align="center"><a href="https://salmonmode.github.io/"><img src="https://avatars3.githubusercontent.com/u/13908130?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Chris NeJame</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=SalmonMode" title="Documentation">π</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=SalmonMode" title="Tests">β οΈ</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=SalmonMode" title="Code">π»</a></td>
|
248 | <td align="center"><a href="https://github.com/ron-checkmarx"><img src="https://avatars2.githubusercontent.com/u/67099202?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ron</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=ron-checkmarx" title="Tests">β οΈ</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=ron-checkmarx" title="Code">π»</a></td>
|
249 | </tr>
|
250 | <tr>
|
251 | <td align="center"><a href="https://www.linkedin.com/in/juanignaciogarzon/"><img src="https://avatars.githubusercontent.com/u/9467722?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Juan Ignacio GarzΓ³n</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=jigarzon" title="Documentation">π</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=jigarzon" title="Code">π»</a></td>
|
252 | <td align="center"><a href="https://github.com/vlovich"><img src="https://avatars.githubusercontent.com/u/201287?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vitali Lovich</b></sub></a><br /><a href="https://github.com/domharrington/node-gitlog/commits?author=vlovich" title="Tests">β οΈ</a> <a href="https://github.com/domharrington/node-gitlog/commits?author=vlovich" title="Code">π»</a></td>
|
253 | </tr>
|
254 | </table>
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|