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