From 61a610cbfc7b075c3f046ab8ccd14192a0d5b3cc Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Fri, 5 Jun 2015 12:33:56 -0700 Subject: [PATCH] Working dir should relativize to an empty string --- spec/git-spec.coffee | 1 + src/git.coffee | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/spec/git-spec.coffee b/spec/git-spec.coffee index 69770e14..1c001efe 100644 --- a/spec/git-spec.coffee +++ b/spec/git-spec.coffee @@ -606,6 +606,7 @@ describe "git", -> expect(repo.relativize(null)).toBe null expect(repo.relativize()).toBeUndefined() expect(repo.relativize('')).toBe '' + expect(repo.relativize(workingDirectory)).toBe '' describe 'when the opened path is a symlink', -> it 'relativizes against both the linked path and the real path', -> diff --git a/src/git.coffee b/src/git.coffee index 447014c4..d1927a19 100644 --- a/src/git.coffee +++ b/src/git.coffee @@ -128,18 +128,28 @@ Repository::relativize = (path) -> workingDirectory = workingDirectory.toLowerCase() if lowerCasePath.indexOf("#{workingDirectory}/") is 0 return path.substring(workingDirectory.length + 1) + else if lowerCasePath is workingDirectory + return '' if @openedWorkingDirectory workingDirectory = @openedWorkingDirectory.toLowerCase() if lowerCasePath.indexOf("#{workingDirectory}/") is 0 return path.substring(workingDirectory.length + 1) + else if lowerCasePath is workingDirectory + return '' else workingDirectory = @getWorkingDirectory() - if workingDirectory and path.indexOf("#{workingDirectory}/") is 0 - return path.substring(workingDirectory.length + 1) + if workingDirectory + if path.indexOf("#{workingDirectory}/") is 0 + return path.substring(workingDirectory.length + 1) + else if path is workingDirectory + return '' - if @openedWorkingDirectory and path.indexOf("#{@openedWorkingDirectory}/") is 0 - return path.substring(@openedWorkingDirectory.length + 1) + if @openedWorkingDirectory + if path.indexOf("#{@openedWorkingDirectory}/") is 0 + return path.substring(@openedWorkingDirectory.length + 1) + else if path is @openedWorkingDirectory + return '' path