diff --git a/src/app/project.coffee b/src/app/project.coffee index 6ca62ab5e..cce48d8e3 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -118,13 +118,24 @@ class Project # Given a path, this makes it relative to the project directory. # - # filePath - The {String} name of the path to convert + # fullPath - The {String} path to convert. # # Returns a {String}. relativize: (fullPath) -> return fullPath unless fullPath.lastIndexOf(@getPath()) is 0 fullPath.replace(@getPath(), "").replace(/^\//, '') + # Is the given path inside this project? + # + # pathToCheck - the {String} path to check. + # + # Returns a {Boolean}. + contains: (pathToCheck) -> + if pathToCheck + if projectPath = @getPath() + return pathToCheck.indexOf(path.join(projectPath, path.sep)) is 0 + false + # Identifies if the project is using soft tabs. # # Returns a {Boolean}. diff --git a/src/packages/status-bar/lib/status-bar-view.coffee b/src/packages/status-bar/lib/status-bar-view.coffee index fc4907782..d9b38da02 100644 --- a/src/packages/status-bar/lib/status-bar-view.coffee +++ b/src/packages/status-bar/lib/status-bar-view.coffee @@ -84,18 +84,17 @@ class StatusBarView extends View @isModified = false updateBranchText: -> - path = @getActiveItemPath() @branchArea.hide() - return unless path + return unless project.contains(@getActiveItemPath()) head = git?.getShortHead() or '' @branchLabel.text(head) @branchArea.show() if head updateStatusText: -> - path = @getActiveItemPath() + itemPath = @getActiveItemPath() @gitStatusIcon.removeClass() - return unless path + return unless project.contains(itemPath) @gitStatusIcon.addClass('git-status octicons') return unless git? @@ -110,10 +109,10 @@ class StatusBarView extends View else @commitsBehind.hide() - status = git.statuses[path] + status = git.statuses[itemPath] if git.isStatusModified(status) @gitStatusIcon.addClass('modified-status-icon') - stats = git.getDiffStats(path) + stats = git.getDiffStats(itemPath) if stats.added and stats.deleted @gitStatusIcon.text("+#{stats.added},-#{stats.deleted}") else if stats.added @@ -128,7 +127,7 @@ class StatusBarView extends View @gitStatusIcon.text("+#{@buffer.getLineCount()}") else @gitStatusIcon.text('') - else if git.isPathIgnored(path) + else if git.isPathIgnored(itemPath) @gitStatusIcon.addClass('ignored-status-icon') @gitStatusIcon.text('') diff --git a/src/packages/status-bar/spec/status-bar-spec.coffee b/src/packages/status-bar/spec/status-bar-spec.coffee index aa9bb7de1..0cf8ec25a 100644 --- a/src/packages/status-bar/spec/status-bar-spec.coffee +++ b/src/packages/status-bar/spec/status-bar-spec.coffee @@ -124,7 +124,10 @@ describe "StatusBar", -> project.setPath('/tmp') rootView.open('/tmp/temp.txt') expect(statusBar.branchArea).toBeHidden() - expect(statusBar.branchLabel.text()).toBe '' + + it "doesn't display the current branch for a file outside the current project", -> + rootView.open('/tmp/atom-specs/not-in-project.txt') + expect(statusBar.branchArea).toBeHidden() describe "git status label", -> [repo, filePath, originalPathText, newPath, ignoredPath] = [] @@ -182,6 +185,10 @@ describe "StatusBar", -> rootView.open(newPath) expect(statusBar.gitStatusIcon).toHaveText('+1') + it "does not display for files not in the current project", -> + rootView.open('/tmp/atom-specs/not-in-project.txt') + expect(statusBar.gitStatusIcon).toBeHidden() + describe "grammar label", -> beforeEach -> atom.activatePackage('text-tmbundle', sync: true)