mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-25 14:26:29 +00:00
Test a windows-compatible git finder
This commit is contained in:
parent
b237ed5735
commit
8c09b634cd
22
lib/find_git.js
Normal file
22
lib/find_git.js
Normal 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;
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user