GithubHelp home page GithubHelp logo

git-blame's Introduction

git-blame

Shelling out to git blame in a streaming Node fashion.

build status

Usage

gitBlame(repoPath, options)

Example:

var gitBlame = require('git-blame');
var path = require('path');

var repoPath = path.resolve(process.env.REPO || (__dirname + '/.git'));
var file = process.env.FILE || 'package.json';
var rev = process.env.REV || 'HEAD';

gitBlame(repoPath, {
  file: file,
  rev: rev
}).on('data', function(type, data) {
  // type can be 'line' or 'commit'
  console.log(type, data);
}).on('error', function(err) {
  console.error(err.message);
  process.exit(1);
}).on('end', function() {
  console.log('±±±±±±±±±±±±±±±±±±');
  console.log("That's all, folks!");
});

Sample output:

$ REPO=../rails/.git FILE=install.rb node example.js
line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  originalLine: '1',
  finalLine: '1',
  content: 'version = ARGV.pop' }
commit { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  author:
   { name: 'David Heinemeier Hansson',
     mail: '[email protected]',
     timestamp: 1280178550,
     tz: '-0500' },
  committer:
   { name: 'David Heinemeier Hansson',
     mail: '[email protected]',
     timestamp: 1280178550,
     tz: '-0500' },
  summary: 'Add install script for testing gems locally',
  filename: 'install.rb' }
line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  originalLine: '2',
  finalLine: '2',
  content: '' }
line { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  originalLine: '3',
  finalLine: '3',
  content: 'if version.nil?' }
commit { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  author:
   { name: 'Tim Raymond',
     mail: '[email protected]',
     timestamp: 1357243730,
     tz: '-0500' },
  committer:
   { name: 'Tim Raymond',
     mail: '[email protected]',
     timestamp: 1357244064,
     tz: '-0500' },
  summary: 'Adding a usage message to install.rb script',
  previous:
   { hash: 'a89660947bd5faeef2a741f71f913c352da50cd3',
     filename: 'install.rb' },
  filename: 'install.rb' }
line { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  originalLine: '4',
  finalLine: '4',
  content: '  puts "Usage: ruby install.rb version"' }
line { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  originalLine: '5',
  finalLine: '5',
  content: '  exit(64)' }
line { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  originalLine: '6',
  finalLine: '6',
  content: 'end' }
line { hash: '66258c0e48ed5cf26641a3096272a272611a783c',
  originalLine: '7',
  finalLine: '7',
  content: '' }
line { hash: 'f1637bf2bb00490203503fbd943b73406e043d1d',
  originalLine: '3',
  finalLine: '8',
  content: '%w( activesupport activemodel activerecord actionpack actionmailer railties ).each do |framework|' }
commit { hash: 'f1637bf2bb00490203503fbd943b73406e043d1d',
  author:
   { name: 'Prem Sichanugrist',
     mail: '[email protected]',
     timestamp: 1305488076,
     tz: '-0400' },
  committer:
   { name: 'Prem Sichanugrist',
     mail: '[email protected]',
     timestamp: 1331664944,
     tz: '-0400' },
  summary: 'Remove Active Resource source files from the repository',
  previous:
   { hash: 'a85714a673d2e06b923bd4eba443a3849d332cce',
     filename: 'install.rb' },
  filename: 'install.rb' }
line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  originalLine: '4',
  finalLine: '9',
  content: '  puts "Installing #{framework}..."' }
line { hash: '2eb89627d844dec2a4ba420ca903bb139b860e43',
  originalLine: '10',
  finalLine: '10',
  content: '  `cd #{framework} && gem build #{framework}.gemspec && gem install #{framework}-#{version}.gem --no-ri --no-rdoc && rm #{framework}-#{version}.gem`' }
commit { hash: '2eb89627d844dec2a4ba420ca903bb139b860e43',
  author:
   { name: 'Rafael Mendonça França',
     mail: '[email protected]',
     timestamp: 1361803866,
     tz: '-0300' },
  committer:
   { name: 'Rafael Mendonça França',
     mail: '[email protected]',
     timestamp: 1361803909,
     tz: '-0300' },
  summary: 'Do not use --local option when installing the gems',
  previous:
   { hash: 'c0bc9ce38c6528916f9dd440984a386511e4297d',
     filename: 'install.rb' },
  filename: 'install.rb' }
line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  originalLine: '6',
  finalLine: '11',
  content: 'end' }
line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  originalLine: '7',
  finalLine: '12',
  content: '' }
line { hash: '2eb89627d844dec2a4ba420ca903bb139b860e43',
  originalLine: '13',
  finalLine: '13',
  content: 'puts "Installing rails..."' }
line { hash: 'f79f9a74a4b593e8c36d14c43a030b9a12c69255',
  originalLine: '9',
  finalLine: '14',
  content: '`gem build rails.gemspec`' }
line { hash: '2eb89627d844dec2a4ba420ca903bb139b860e43',
  originalLine: '15',
  finalLine: '15',
  content: '`gem install rails-#{version}.gem --no-ri --no-rdoc `' }
line { hash: '856f13ab053f6b5dfa58d6e6c726d43cc5e73d00',
  originalLine: '11',
  finalLine: '16',
  content: '`rm rails-#{version}.gem`' }
±±±±±±±±±±±±±±±±±±
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

npm test

Used by

License

MIT

git-blame's People

Contributors

alessioalex avatar carloscz avatar sertion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gucong3000

git-blame's Issues

weird issue when having more than 500 git blame at once

hi, i m trying to get blame data of multiple files at once but the plugin is throwing an exception

Unhandled rejection TypeError: Cannot read property 'on' of undefined
    at readStreamIfy (/Users/***/workspace/angular-cli/test-repo/node_modules/spawn-to-readstream/index.js:23:12)
    at module.exports (/Users/***/workspace/angular-cli/test-repo/node_modules/git-spawned-stream/index.js:17:10)
    at blame (/Users/***/workspace/angular-cli/test-repo/node_modules/git-blame/index.js:29:26)
    at Promise (/Users/***/workspace/angular-cli/test-repo/server/routes/api.js:255:18)
    at Promise._execute (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/debuggability.js:300:9)
    at Promise._resolveFromExecutor (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/promise.js:79:10)
    at getBlameData (/Users/***/workspace/angular-cli/test-repo/server/routes/api.js:246:10)
    at Promise.each (/Users/***/workspace/angular-cli/test-repo/server/routes/api.js:131:9)
    at tryCatcher (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/util.js:16:23)
    at Object.gotValue (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/reduce.js:155:18)
    at Object.gotAccum (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/reduce.js:144:25)
    at Object.tryCatcher (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/***/workspace/angular-cli/test-repo/node_modules/bluebird/js/release/promise.js:693:18)

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: spawn git EAGAIN
    at exports._errnoException (util.js:1022:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:359:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.