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 | npm install gitlog --save
|
11 |
|
12 | ## Usage
|
13 |
|
14 | ```js
|
15 | var gitlog = require('gitlog')
|
16 | , options =
|
17 | { repo: __dirname + '/test-repo-folder'
|
18 | , number: 20
|
19 | , author: 'Dom Harrington'
|
20 | , fields:
|
21 | [ 'hash'
|
22 | , 'abbrevHash'
|
23 | , 'subject'
|
24 | , 'authorName'
|
25 | , 'authorDateRel'
|
26 | ]
|
27 | }
|
28 |
|
29 | gitlog(options, function(error, commits) {
|
30 | // Commits is an array of commits in the repo
|
31 | console.log(commits)
|
32 | })
|
33 | ```
|
34 |
|
35 | ## Options
|
36 |
|
37 | See [git log](http://git-scm.com/docs/git-log)
|
38 |
|
39 | ### repo
|
40 | The location of the repo, required field.
|
41 |
|
42 | ### number
|
43 | The number of commits to return, defaults to 10.
|
44 |
|
45 | ### since/after
|
46 | Show commits more recent than a specific date.
|
47 |
|
48 | ### until/before
|
49 | Show commits older than a specific date.
|
50 |
|
51 | ### author/committer
|
52 | Limit the commits output to ones with author/committer header lines that match the specified pattern.
|
53 |
|
54 | ### nameStatus
|
55 | Below fields was returned from the log:
|
56 |
|
57 | - files - changed files names (array)
|
58 | - status - changed files status (array)
|
59 |
|
60 | This option is enabled by default.
|
61 |
|
62 | ### optional fields
|
63 | An array of fields to return from the log, here are the possible options:
|
64 |
|
65 | - hash - the long hash of the commit e.g. 7dd0b07625203f69cd55d779d873f1adcffaa84a
|
66 | - abbrevHash - the abbreviated commit hash e.g. 7dd0b07
|
67 | - treeHash - the tree hash of the commit
|
68 | - abbrevTreeHash - the abbreviated commit hash
|
69 | - parentHashes - the parent hashes
|
70 | - abbrevParentHashes - the abbreviated parent hashes
|
71 | - authorName - author name of the commit
|
72 | - authorEmail - author email of the commit
|
73 | - authorDate - author date of the commit
|
74 | - authorDateRel - relative author date of the commit
|
75 | - committerName - committer name
|
76 | - committerEmail - committer email
|
77 | - committerDate - committer date
|
78 | - committerDateRel - relative committer date
|
79 | - subject - commit message (first line)
|
80 | - body - full commit message
|
81 |
|
82 |
|
83 | Defaults to 'abbrevHash', 'hash', 'subject' and 'authorName'.
|
84 |
|
85 | ## How it works
|
86 |
|
87 | 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.
|
88 |
|
89 | ## Example
|
90 | ```javascript
|
91 | { hash: '6a7ef5e3b3d9c77743140443c8f9e792b0715721',
|
92 | abbrevHash: '6a7ef5e',
|
93 | treeHash: 'f1bf51b15b48a00c33727f364afef695029864c0',
|
94 | abbrevTreeHash: 'f1bf51b',
|
95 | parentHashes: 'cfe06dbdb8d0a193640977e016a04678f8f3b04f',
|
96 | abbrevParentHashes: 'cfe06dbdb8d0a193640977e016a04678f8f3b04f',
|
97 | authorName: 'Dom Harrington',
|
98 | authorEmail: 'dom@harringtonxxxxx',
|
99 | authorDate: '2015-04-09 09:39:23 +0100',
|
100 | authorDateRel: '6 days ago',
|
101 | committerName: 'Dom Harrington',
|
102 | committerEmail: 'dom@harringtonxxxxx',
|
103 | committerDate: 'Thu Apr 9 09:39:23 2015 +0100',
|
104 | committerDateRel: '6 days ago',
|
105 | subject: '1.0.0',
|
106 | status: [ 'M' ],
|
107 | files: [ 'package.json' ] }
|
108 | ```
|