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 | , execOptions:
|
28 | { maxBuffer: 1000 x 1024
|
29 | }
|
30 | }
|
31 |
|
32 | gitlog(options, function(error, commits) {
|
33 | // Commits is an array of commits in the repo
|
34 | console.log(commits)
|
35 | })
|
36 | ```
|
37 |
|
38 | ## Options
|
39 |
|
40 | See [git log](http://git-scm.com/docs/git-log)
|
41 |
|
42 | ### repo
|
43 | The location of the repo, required field.
|
44 |
|
45 | ### number
|
46 | The number of commits to return, defaults to 10.
|
47 |
|
48 | ### since/after
|
49 | Show commits more recent than a specific date.
|
50 |
|
51 | ### until/before
|
52 | Show commits older than a specific date.
|
53 |
|
54 | ### author/committer
|
55 | Limit the commits output to ones with author/committer header lines that match the specified pattern.
|
56 |
|
57 | ### nameStatus
|
58 | Below fields was returned from the log:
|
59 |
|
60 | - files - changed files names (array)
|
61 | - status - changed files status (array)
|
62 |
|
63 | This option is enabled by default.
|
64 |
|
65 | ### findCopiesHarder
|
66 | Much more likely to set status codes to 'C' if files are exact copies of each other.
|
67 |
|
68 | This option is disabled by default.
|
69 |
|
70 | ### execOptions
|
71 |
|
72 | Type: `Object`
|
73 |
|
74 | 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:
|
75 |
|
76 | - `cwd` String *Current working directory of the child process*
|
77 | - `env` Object *Environment key-value pairs*
|
78 | - `setsid` Boolean
|
79 | - `encoding` String *(Default: 'utf8')*
|
80 | - `timeout` Number *(Default: 0)*
|
81 | - `maxBuffer` Number *(Default: 200\*1024)*
|
82 | - `killSignal` String *(Default: 'SIGTERM')*
|
83 |
|
84 | ### optional fields
|
85 | An array of fields to return from the log, here are the possible options:
|
86 |
|
87 | - hash - the long hash of the commit e.g. 7dd0b07625203f69cd55d779d873f1adcffaa84a
|
88 | - abbrevHash - the abbreviated commit hash e.g. 7dd0b07
|
89 | - treeHash - the tree hash of the commit
|
90 | - abbrevTreeHash - the abbreviated commit hash
|
91 | - parentHashes - the parent hashes
|
92 | - abbrevParentHashes - the abbreviated parent hashes
|
93 | - authorName - author name of the commit
|
94 | - authorEmail - author email of the commit
|
95 | - authorDate - author date of the commit
|
96 | - authorDateRel - relative author date of the commit
|
97 | - committerName - committer name
|
98 | - committerEmail - committer email
|
99 | - committerDate - committer date
|
100 | - committerDateRel - relative committer date
|
101 | - subject - commit message (first line)
|
102 | - body - full commit message
|
103 |
|
104 | Defaults to 'abbrevHash', 'hash', 'subject' and 'authorName'.
|
105 |
|
106 | ## How it works
|
107 |
|
108 | 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.
|
109 |
|
110 | ## Example
|
111 | ```javascript
|
112 | { hash: '6a7ef5e3b3d9c77743140443c8f9e792b0715721',
|
113 | abbrevHash: '6a7ef5e',
|
114 | treeHash: 'f1bf51b15b48a00c33727f364afef695029864c0',
|
115 | abbrevTreeHash: 'f1bf51b',
|
116 | parentHashes: 'cfe06dbdb8d0a193640977e016a04678f8f3b04f',
|
117 | abbrevParentHashes: 'cfe06dbdb8d0a193640977e016a04678f8f3b04f',
|
118 | authorName: 'Dom Harrington',
|
119 | authorEmail: 'dom@harringtonxxxxx',
|
120 | authorDate: '2015-04-09 09:39:23 +0100',
|
121 | authorDateRel: '6 days ago',
|
122 | committerName: 'Dom Harrington',
|
123 | committerEmail: 'dom@harringtonxxxxx',
|
124 | committerDate: 'Thu Apr 9 09:39:23 2015 +0100',
|
125 | committerDateRel: '6 days ago',
|
126 | subject: '1.0.0',
|
127 | status: [ 'M' ],
|
128 | files: [ 'package.json' ] }
|
129 | ```
|