Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Working dir should relativize to an empty string #45

Merged
merged 1 commit into from
Jun 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/git-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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', ->
Expand Down
18 changes: 14 additions & 4 deletions src/git.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down