Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 4 files changed
  • 0 comments
  • 1 contributor

Showing 4 changed files with 102 additions and 36 deletions. Show diff stats Hide diff stats

  1. +52 9 README.md
  2. +29 9 example/simple.js
  3. +20 17 index.js
  4. +1 1  package.json
61 README.md
Source Rendered
@@ -5,26 +5,69 @@ access git revision state in node
5 5 # Example
6 6
7 7 ``` js
8   -var revision = require('git-rev')
  8 +var git = require('git-rev')
9 9
10   -revision.short(function (str) {
11   - console.log('revision short', str)
  10 +git.short(function (str) {
  11 + console.log('short', str)
  12 + // => aefdd94
12 13 })
13 14
14   -revision.long(function (str) {
15   - console.log('revision long', str)
  15 +git.long(function (str) {
  16 + console.log('long', str)
  17 + // => aefdd946ea65c88f8aa003e46474d57ed5b291d1
16 18 })
17 19
18   -revision.branch(function (str) {
19   - console.log('revision branch', str)
  20 +git.branch(function (str) {
  21 + console.log('branch', str)
  22 + // => master
20 23 })
21 24
22   -revision.tag(function (str) {
23   - console.log('revision tag', str)
  25 +git.tag(function (str) {
  26 + console.log('tag', str)
  27 + // => 0.1.0
24 28 })
25 29
26 30 ```
27 31
  32 +# Methods
  33 +
  34 +``` js
  35 +var git = require('git-rev')
  36 +```
  37 +
  38 +## .log(function (array) { ... })
  39 +return the git log of `process.cwd()` as an array
  40 +
  41 +``` js
  42 +git.log(function (array) {
  43 + console.log('log', array)
  44 + // [ [ 'aefdd946ea65c88f8aa003e46474d57ed5b291d1',
  45 + // 'add description',
  46 + // '7 hours ago',
  47 + // 'Thomas Blobaum' ],
  48 + // [ '1eb9a6c8633a5a47a47487f17b17ae545d0e26a8',
  49 + // 'first',
  50 + // '7 hours ago',
  51 + // 'Thomas Blobaum' ],
  52 + // [ '7f85b750b908d28bfeb13ad6dba47d9d604508f9',
  53 + // 'first commit',
  54 + // '2 days ago',
  55 + // 'Thomas Blobaum' ] ]
  56 +})
  57 +```
  58 +
  59 +## .short(function (commit) { ... })
  60 +return the result of `git rev-parse --short HEAD`
  61 +
  62 +## .long(function (commit) { ... })
  63 +return the result of `git rev-parse HEAD`
  64 +
  65 +## .tag(function (tag) { ... })
  66 +return the current tag
  67 +
  68 +## .branch(function (branch) { ... })
  69 +return the current branch
  70 +
28 71 # Install
29 72
30 73 `npm install git-rev`
38 example/simple.js
... ... @@ -1,17 +1,37 @@
1   -var revision = require('../')
  1 +var git = require('../')
2 2
3   -revision.short(function (str) {
4   - console.log('revision short', str)
  3 +git.short(function (str) {
  4 + console.log('short', str)
  5 + // => aefdd94
5 6 })
6 7
7   -revision.long(function (str) {
8   - console.log('revision long', str)
  8 +git.long(function (str) {
  9 + console.log('long', str)
  10 + // => aefdd946ea65c88f8aa003e46474d57ed5b291d1
9 11 })
10 12
11   -revision.branch(function (str) {
12   - console.log('revision branch', str)
  13 +git.branch(function (str) {
  14 + console.log('branch', str)
  15 + // => master
13 16 })
14 17
15   -revision.tag(function (str) {
16   - console.log('revision tag', str)
  18 +git.tag(function (str) {
  19 + console.log('tag', str)
  20 + // => 0.1.0
  21 +})
  22 +
  23 +git.log(function (array) {
  24 + console.log('log', array)
  25 + // [ [ 'aefdd946ea65c88f8aa003e46474d57ed5b291d1',
  26 + // 'add description',
  27 + // '7 hours ago',
  28 + // 'Thomas Blobaum' ],
  29 + // [ '1eb9a6c8633a5a47a47487f17b17ae545d0e26a8',
  30 + // 'first',
  31 + // '7 hours ago',
  32 + // 'Thomas Blobaum' ],
  33 + // [ '7f85b750b908d28bfeb13ad6dba47d9d604508f9',
  34 + // 'first commit',
  35 + // '2 days ago',
  36 + // 'Thomas Blobaum' ] ]
17 37 })
37 index.js
@@ -2,24 +2,27 @@ var exec = require('child_process').exec
2 2
3 3 function _command (cmd, cb) {
4 4 exec(cmd, function (err, stdout, stderr) {
5   - cb(stdout.split('\n')[0])
  5 + cb(stdout.split('\n').join(''))
6 6 })
7 7 }
8 8
9   -function short (cb) {
10   - _command('git rev-parse --short HEAD', cb)
  9 +module.exports = {
  10 + short : function (cb) {
  11 + _command('git rev-parse --short HEAD', cb)
  12 + }
  13 + , long : function (cb) {
  14 + _command('git rev-parse HEAD', cb)
  15 + }
  16 + , branch : function (cb) {
  17 + _command('git rev-parse --abbrev-ref HEAD', cb)
  18 + }
  19 + , tag : function (cb) {
  20 + _command('git describe --always --tag', cb)
  21 + }
  22 + , log : function (cb) {
  23 + _command('git log --no-color --pretty=format:\'[ "%H", "%s", "%cr", "%an" ],\' --abbrev-commit', function (str) {
  24 + str = str.substr(0, str.length-1)
  25 + cb(JSON.parse('[' + str + ']'))
  26 + })
  27 + }
11 28 }
12   -
13   -function long (cb) {
14   - _command('git rev-parse HEAD', cb)
15   -}
16   -
17   -function branch (cb) {
18   - _command('git rev-parse --abbrev-ref HEAD', cb)
19   -}
20   -
21   -function tag (cb) {
22   - _command('git describe --always --tag', cb)
23   -}
24   -
25   -module.exports = { short : short, long : long, branch : branch, tag : tag }
2  package.json
... ... @@ -1,6 +1,6 @@
1 1 {
2 2 "name" : "git-rev",
3   - "version" : "0.1.0",
  3 + "version" : "0.2.0",
4 4 "description" : "get the current git commit hash, tag or branch in node",
5 5 "main" : "index.js",
6 6 "bin" : {},

No commit comments for this range

Something went wrong with that request. Please try again.