From 0c839a91fb0bbae547647aaec94916eefbe71a1a Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Sat, 9 Jan 2016 11:40:09 -0800 Subject: [PATCH] Keep track of openedPath when relativizing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit .. otherwise if the repo root is a symlink, paths won’t relativize to it and git statuses won’t be updated/shown. --- src/git-repository-async.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/git-repository-async.js b/src/git-repository-async.js index 9bc5c5999..b87ac648d 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -161,7 +161,16 @@ export default class GitRepositoryAsync { // Returns a {Promise} which resolves to the relative {String} path. relativizeToWorkingDirectory (_path) { return this.getRepo() - .then(repo => this.relativize(_path, repo.workdir())) + .then((repo) => { + const workingDirectory = repo.workdir() + let openedWorkingDirectory = null + const opened = this.openedPath.replace(/\/\.git$/, '') + if (path.relative(opened, workingDirectory) != '') { + openedWorkingDirectory = opened + } + return this.relativize(_path, workingDirectory, openedWorkingDirectory) + } + ) } // Public: Makes a path relative to the repository's working directory. @@ -170,13 +179,7 @@ export default class GitRepositoryAsync { // * `workingDirectory` The {String} working directory path. // // Returns the relative {String} path. - relativize (_path, workingDirectory) { - // Cargo-culted from git-utils. The original implementation also handles - // this.openedWorkingDirectory, which is set by git-utils when the - // repository is opened. Those branches of the if tree aren't included here - // yet, but if we determine we still need that here it should be simple to - // port. - // + relativize (_path, workingDirectory, openedWorkingDirectory) { // The original implementation also handled null workingDirectory as it // pulled it from a sync function that could return null. We require it // to be passed here. @@ -188,6 +191,9 @@ export default class GitRepositoryAsync { // prefix. Standardize by stripping that out. _path = _path.replace(/^\/private\//, '/') workingDirectory = workingDirectory.replace(/^\/private\//, '/') + if (openedWorkingDirectory) { + openedWorkingDirectory = openedWorkingDirectory.replace(/^\/private\//, '/') + } if (process.platform === 'win32') { _path = _path.replace(/\\/g, '/') @@ -197,10 +203,12 @@ export default class GitRepositoryAsync { } } - if (!/\/$/.test(workingDirectory)) { - workingDirectory = `${workingDirectory}/` + if (openedWorkingDirectory) { + workingDirectory = openedWorkingDirectory } + workingDirectory = workingDirectory.replace(/\/$/, '') + const originalPath = _path if (this.isCaseInsensitive) { _path = _path.toLowerCase() @@ -208,7 +216,7 @@ export default class GitRepositoryAsync { } if (_path.indexOf(workingDirectory) === 0) { - return originalPath.substring(workingDirectory.length) + return originalPath.substring(workingDirectory.length + 1) } else if (_path === workingDirectory) { return '' }