diff --git a/src/git-repository-provider.coffee b/src/git-repository-provider.coffee index 850d30f22..3b4df5d2b 100644 --- a/src/git-repository-provider.coffee +++ b/src/git-repository-provider.coffee @@ -1,6 +1,17 @@ fs = require 'fs' +{Directory} = require 'pathwatcher' GitRepository = require './git-repository' +# Returns the .gitdir path in the agnostic Git symlink .git file given, or +# null if the path is not a valid gitfile. +# +# * `gitFile` {String} path of gitfile to parse +gitFileRegex = RegExp "^gitdir: (.+)" +pathFromGitFile = (gitFile) -> + try + gitFileBuff = fs.readFileSync(gitFile, 'utf8') + return gitFileBuff?.match(gitFileRegex)[1] + # Checks whether a valid `.git` directory is contained within the given # directory or one of its ancestors. If so, a Directory that corresponds to the # `.git` folder will be returned. Otherwise, returns `null`. @@ -11,6 +22,9 @@ findGitDirectorySync = (directory) -> # can return cached values rather than always returning new objects: # getParent(), getFile(), getSubdirectory(). gitDir = directory.getSubdirectory('.git') + gitDirPath = pathFromGitFile(gitDir.getPath?()) + if gitDirPath + gitDir = new Directory(directory.resolve(gitDirPath)) if gitDir.existsSync?() and isValidGitDirectorySync gitDir gitDir else if directory.isRoot()