Code coverage report for lib/git/find_git.js

Statements: 100% (9 / 9)      Branches: 100% (2 / 2)      Functions: 100% (1 / 1)      Lines: 100% (9 / 9)      Ignored: none     

All files » lib/git/ » find_git.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23    27 27               27 3 3 8 8 3         27  
'use strict';
 
var path = require('path');
var fs = require('fs');
 
/**
 * Given a full path to a single file, iterate upwards through the filesystem
 * to find a directory with a .git file indicating that it is a git repository
 * @param {string} filename any file within a repository
 * @returns {string} repository path
 */
function findGit(filename) {
  var paths = filename.split(path.sep);
  for (var i = paths.length; i > 0; i--) {
    var p = path.resolve(paths.slice(0, i).join(path.sep) + path.sep + '.git');
    if (fs.existsSync(p)) {
      return p;
    }
  }
}
 
module.exports = findGit;