项目作者: alessioalex

项目描述 :
Shelling out to git blame in a streaming Node fashion.
高级语言: JavaScript
项目地址: git://github.com/alessioalex/git-blame.git
创建时间: 2014-05-25T16:07:58Z
项目社区:https://github.com/alessioalex/git-blame

开源协议:

下载


git-blame

Shelling out to git blame in a streaming Node fashion.

build status

Usage

  1. gitBlame(repoPath, options)

Example:

  1. var gitBlame = require('git-blame');
  2. var path = require('path');
  3. var repoPath = path.resolve(process.env.REPO || (__dirname + '/.git'));
  4. var file = process.env.FILE || 'package.json';
  5. var rev = process.env.REV || 'HEAD';
  6. gitBlame(repoPath, {
  7. file: file,
  8. rev: rev
  9. }).on('data', function(type, data) {
  10. // type can be 'line' or 'commit'
  11. console.log(type, data);
  12. }).on('error', function(err) {
  13. console.error(err.message);
  14. process.exit(1);
  15. }).on('end', function() {
  16. console.log('±±±±±±±±±±±±±±±±±±');
  17. console.log("That's all, folks!");
  18. });

Sample output:

  1. $ REPO=../rails/.git FILE=install.rb node example.js
  2. line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  3. originalLine: '1',
  4. finalLine: '1',
  5. content: 'version = ARGV.pop' }
  6. commit { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  7. author:
  8. { name: 'David Heinemeier Hansson',
  9. mail: 'david@loudthinking.com',
  10. timestamp: 1280178550,
  11. tz: '-0500' },
  12. committer:
  13. { name: 'David Heinemeier Hansson',
  14. mail: 'david@loudthinking.com',
  15. timestamp: 1280178550,
  16. tz: '-0500' },
  17. summary: 'Add install script for testing gems locally',
  18. filename: 'install.rb' }
  19. line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  20. originalLine: '2',
  21. finalLine: '2',
  22. content: '' }
  23. line { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  24. originalLine: '3',
  25. finalLine: '3',
  26. content: 'if version.nil?' }
  27. commit { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  28. author:
  29. { name: 'Tim Raymond',
  30. mail: 'xtjraymondx@gmail.com',
  31. timestamp: 1357243730,
  32. tz: '-0500' },
  33. committer:
  34. { name: 'Tim Raymond',
  35. mail: 'xtjraymondx@gmail.com',
  36. timestamp: 1357244064,
  37. tz: '-0500' },
  38. summary: 'Adding a usage message to install.rb script',
  39. previous:
  40. { hash: 'a89660947bd5faeef2a741f71f913c352da50cd3',
  41. filename: 'install.rb' },
  42. filename: 'install.rb' }
  43. line { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  44. originalLine: '4',
  45. finalLine: '4',
  46. content: ' puts "Usage: ruby install.rb version"' }
  47. line { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  48. originalLine: '5',
  49. finalLine: '5',
  50. content: ' exit(64)' }
  51. line { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  52. originalLine: '6',
  53. finalLine: '6',
  54. content: 'end' }
  55. line { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  56. originalLine: '7',
  57. finalLine: '7',
  58. content: '' }
  59. line { hash: 'f1637bf2bb00490203503fbd943b73406e043d1d',
  60. originalLine: '3',
  61. finalLine: '8',
  62. content: '%w( activesupport activemodel activerecord actionpack actionmailer railties ).each do |framework|' }
  63. commit { hash: 'f1637bf2bb00490203503fbd943b73406e043d1d',
  64. author:
  65. { name: 'Prem Sichanugrist',
  66. mail: 's@sikachu.com',
  67. timestamp: 1305488076,
  68. tz: '-0400' },
  69. committer:
  70. { name: 'Prem Sichanugrist',
  71. mail: 's@sikachu.com',
  72. timestamp: 1331664944,
  73. tz: '-0400' },
  74. summary: 'Remove Active Resource source files from the repository',
  75. previous:
  76. { hash: 'a85714a673d2e06b923bd4eba443a3849d332cce',
  77. filename: 'install.rb' },
  78. filename: 'install.rb' }
  79. line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  80. originalLine: '4',
  81. finalLine: '9',
  82. content: ' puts "Installing #{framework}..."' }
  83. line { hash: '2eb89627d844dec2a4ba420ca903bb139b860e43',
  84. originalLine: '10',
  85. finalLine: '10',
  86. content: ' `cd #{framework} && gem build #{framework}.gemspec && gem install #{framework}-#{version}.gem --no-ri --no-rdoc && rm #{framework}-#{version}.gem`' }
  87. commit { hash: '2eb89627d844dec2a4ba420ca903bb139b860e43',
  88. author:
  89. { name: 'Rafael Mendonça França',
  90. mail: 'rafaelmfranca@gmail.com',
  91. timestamp: 1361803866,
  92. tz: '-0300' },
  93. committer:
  94. { name: 'Rafael Mendonça França',
  95. mail: 'rafaelmfranca@gmail.com',
  96. timestamp: 1361803909,
  97. tz: '-0300' },
  98. summary: 'Do not use --local option when installing the gems',
  99. previous:
  100. { hash: 'c0bc9ce38c6528916f9dd440984a386511e4297d',
  101. filename: 'install.rb' },
  102. filename: 'install.rb' }
  103. line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  104. originalLine: '6',
  105. finalLine: '11',
  106. content: 'end' }
  107. line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  108. originalLine: '7',
  109. finalLine: '12',
  110. content: '' }
  111. line { hash: '2eb89627d844dec2a4ba420ca903bb139b860e43',
  112. originalLine: '13',
  113. finalLine: '13',
  114. content: 'puts "Installing rails..."' }
  115. line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  116. originalLine: '9',
  117. finalLine: '14',
  118. content: '`gem build rails.gemspec`' }
  119. line { hash: '2eb89627d844dec2a4ba420ca903bb139b860e43',
  120. originalLine: '15',
  121. finalLine: '15',
  122. content: '`gem install rails-#{version}.gem --no-ri --no-rdoc `' }
  123. line { hash: '856f13ab053f6b5dfa58d6e6c726d43cc5e73d00',
  124. originalLine: '11',
  125. finalLine: '16',
  126. content: '`rm rails-#{version}.gem`' }
  127. ±±±±±±±±±±±±±±±±±±
  128. That's all, folks!

Options

The options should be an object.

rev (Boolean or String)

<rev> from git blame. If empty it will default to HEAD. If false and workTree is set it will use the work tree.

workTree (String)

--work-tree from git. If empty no work tree will be used. Use full path.

ignoreWhitespace (Boolean)

-w from git blame.

limitLines (String)

-L from git blame.

detectMoved (Boolean or Number)

-M from git blame. Requiered for detectCopy.

detectCopy (Boolean or Number)

-C from git blame.

detectCopyMode (String)

Possible options:

  • any - Look in all files and at all times
  • created - Look in files changed in the commit creating the file
  • default - Look in the same commit

If left empty it will default to default.

file (String)

<file> in git blame.

gitCommand

This is an optional 3rd parameter besides the repo path and options.
It’s the path to the git binary to use (use the one in PATH by default).

Tests

  1. npm test

Used by

License

MIT