Show Git status indicators on directories

Closes #301
This commit is contained in:
Kevin Sawicki 2013-02-27 19:36:21 -08:00
parent 587a6552ea
commit 77a5f4775a
5 changed files with 51 additions and 9 deletions

View File

@ -126,5 +126,12 @@ class Git
@statusTask = new RepositoryStatusTask(this)
@statusTask.start()
getDirectoryStatus: (directoryPath) ->
directoryPath = "#{directoryPath}/"
directoryStatus = 0
for path, status of @statuses
directoryStatus |= status if path.indexOf(directoryPath) is 0
directoryStatus
_.extend Git.prototype, Subscriber
_.extend Git.prototype, EventEmitter

View File

@ -26,12 +26,31 @@ class DirectoryView extends View
if git?
path = @directory.getPath()
if parent
@directoryName.addClass('ignored') if git.isPathIgnored(path)
iconClass = 'submodule-icon' if git.isSubmodule(path)
if git.isSubmodule(path)
iconClass = 'submodule-icon'
else
@subscribe git, 'status-changed', (path, status) =>
@updateStatus() if path.substring("#{@getPath()}/") is 0
@subscribe git, 'statuses-changed', =>
@updateStatus()
@updateStatus()
else
iconClass = 'repository-icon' if path is git.getWorkingDirectory()
@directoryName.addClass(iconClass)
updateStatus: ->
@removeClass('ignored modified new')
path = @directory.getPath()
if git.isPathIgnored(path)
@addClass('ignored')
else
status = git.getDirectoryStatus(path)
if git.isStatusModified(status)
@addClass('modified')
else if git.isStatusNew(status)
@addClass('new')
getPath: ->
@directory.path

View File

@ -927,31 +927,48 @@ describe "TreeView", ->
expect(treeView.find('.file:contains(tree-view.js)').length).toBe 1
describe "Git status decorations", ->
[ignoreFile, modifiedFile, originalFileContent] = []
[ignoreFile, newFile, modifiedFile, originalFileContent] = []
beforeEach ->
config.set "core.hideGitIgnoredFiles", false
ignoreFile = fs.join(require.resolve('fixtures/tree-view'), '.gitignore')
fs.write(ignoreFile, 'tree-view.js')
git.getPathStatus(ignoreFile)
modifiedFile = fs.join(require.resolve('fixtures/tree-view'), 'tree-view.txt')
newFile = fs.join(require.resolve('fixtures/tree-view/dir2'), 'new2')
fs.write(newFile, '')
git.getPathStatus(newFile)
modifiedFile = fs.join(require.resolve('fixtures/tree-view/dir1'), 'file1')
originalFileContent = fs.read(modifiedFile)
fs.write modifiedFile, 'ch ch changes'
git.getPathStatus(modifiedFile)
treeView.updateRoot()
treeView.root.entries.find('.directory:contains(dir1)').view().expand()
treeView.root.entries.find('.directory:contains(dir2)').view().expand()
afterEach ->
fs.remove(ignoreFile) if fs.exists(ignoreFile)
fs.remove(newFile) if fs.exists(newFile)
fs.write modifiedFile, originalFileContent
describe "when a file is modified", ->
it "adds a custom style", ->
expect(treeView.find('.file:contains(tree-view.txt)')).toHaveClass 'modified'
expect(treeView.find('.file:contains(file1)')).toHaveClass 'modified'
describe "when a directory if modified", ->
it "adds a custom style", ->
expect(treeView.find('.directory:contains(dir1)')).toHaveClass 'modified'
describe "when a file is new", ->
it "adds a custom style", ->
expect(treeView.find('.file:contains(.gitignore)')).toHaveClass 'new'
describe "when a directory is new", ->
it "adds a custom style", ->
expect(treeView.find('.directory:contains(dir2)')).toHaveClass 'new'
describe "when a file is ignored", ->
it "adds a custom style", ->
expect(treeView.find('.file:contains(tree-view.js)')).toHaveClass 'ignored'

View File

@ -29,7 +29,7 @@
text-shadow: 0 -1px 0 #7E4521;
}
.tree-view .directory .header {
.tree-view .directory {
color: #bebebe;
}

View File

@ -34,7 +34,7 @@
text-shadow: 0 1px 0 #000;
}
.tree-view .directory .header {
.tree-view .directory {
color: #262626;
}
@ -46,7 +46,6 @@
color: #7e8692;
}
.tree-view .entry:hover,
.tree-view .directory .header:hover .name,
.tree-view .directory .header:hover .disclosure-arrow {
@ -83,4 +82,4 @@
.tree-view-dialog .prompt {
color: #333;
}
}