Fix bug in Project::relativize

This commit is contained in:
Max Brunsfeld
2015-02-18 16:47:21 -08:00
parent d35b99285e
commit a9adfa6a76
2 changed files with 8 additions and 2 deletions

View File

@@ -332,10 +332,16 @@ describe "Project", ->
describe ".relativize(path)", ->
it "returns the path, relative to whichever root directory it is inside of", ->
atom.project.addPath(temp.mkdirSync("another-path"))
rootPath = atom.project.getPaths()[0]
childPath = path.join(rootPath, "some", "child", "directory")
expect(atom.project.relativize(childPath)).toBe path.join("some", "child", "directory")
rootPath = atom.project.getPaths()[1]
childPath = path.join(rootPath, "some", "child", "directory")
expect(atom.project.relativize(childPath)).toBe path.join("some", "child", "directory")
it "returns the given path if it is not in any of the root directories", ->
randomPath = path.join("some", "random", "path")
expect(atom.project.relativize(randomPath)).toBe randomPath

View File

@@ -241,8 +241,8 @@ class Project extends Model
relativize: (fullPath) ->
return fullPath if fullPath?.match(/[A-Za-z0-9+-.]+:\/\//) # leave path alone if it has a scheme
for rootDirectory in @rootDirectories
if (relativePath = rootDirectory.relativize(fullPath))?
return relativePath
relativePath = rootDirectory.relativize(fullPath)
return relativePath if relativePath isnt fullPath
fullPath
# Public: Determines whether the given path (real or symbolic) is inside the