This repository has been archived by the owner on Feb 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lib): getting .git from parent dir (#74)
* fix(lib): getting .git from parent dir * docs(contributors): add myself to contributors * docs(contributors): fix myself to use code instead of bug
- Loading branch information
1 parent
a579a3d
commit e3a81f8
Showing
5 changed files
with
48 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var findParentDir = require('find-parent-dir'); | ||
|
||
module.exports = function getGitFolder() { | ||
var gitDirLocation = './.git'; | ||
if (!fs.existsSync(gitDirLocation)) { | ||
throw new Error('Cannot find file ' + gitDirLocation); | ||
} | ||
var dir = findParentDir.sync(process.cwd(), '.git'); | ||
if (!dir) throw new Error('Cannot find .git folder'); | ||
|
||
if (!fs.lstatSync(gitDirLocation).isDirectory()) { | ||
var unparsedText = '' + fs.readFileSync(gitDirLocation); | ||
gitDirLocation = unparsedText.substring('gitdir: '.length).trim(); | ||
} | ||
var gitDir = path.join(dir, '.git'); | ||
var stats = fs.lstatSync(gitDir); | ||
|
||
if (!stats.isDirectory()) { | ||
// Expect following format | ||
// git: pathToGit | ||
var pathToGit = fs | ||
.readFileSync(gitDir, 'utf-8') | ||
.split(':')[1] | ||
.trim(); | ||
gitDir = path.join(dir, pathToGit); | ||
|
||
if (!fs.existsSync(gitDirLocation)) { | ||
throw new Error('Cannot find file ' + gitDirLocation); | ||
if (!fs.existsSync(gitDir)) { | ||
throw new Error('Cannot find file ' + pathToGit); | ||
} | ||
} | ||
|
||
return gitDirLocation; | ||
return gitDir; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters