Test a windows-compatible git finder

This commit is contained in:
Tom MacWright 2015-08-14 18:04:29 -04:00
parent b237ed5735
commit 8c09b634cd
2 changed files with 23 additions and 12 deletions

22
lib/find_git.js Normal file
View File

@ -0,0 +1,22 @@
'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
* @returns {string} repository path
*/
function findGit(filename) {
var paths = filename.split(path.sep);
for (var i = paths.length - 1; 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;

View File

@ -3,19 +3,8 @@
var through2 = require('through2');
var exec = require('child_process').exec;
var path = require('path');
var fs = require('fs');
var urlFromGit = require('github-url-from-git');
function findGit(filename, relative) {
relative = relative || '.git';
var newPath = path.resolve(filename, relative);
if (fs.existsSync(newPath)) {
return newPath;
} else if (newPath === '/') {
return null;
}
return findGit(filename, '../' + relative);
}
var findGit = require('../lib/find_git');
function makeGetBase() {
var base, root;