Show commits ahead/behind upstream in status bar

This commit is contained in:
Kevin Sawicki
2013-03-01 14:01:43 -08:00
parent fd82f3f8a4
commit e3ebda7d30
5 changed files with 36 additions and 5 deletions

View File

@@ -27,9 +27,11 @@ class Git
ignore: 1 << 14
statuses: null
upstream: null
constructor: (path, options={}) ->
@statuses = {}
@upstream = {ahead: 0, behind: 0}
@repo = GitRepository.open(path)
refreshOnWindowFocus = options.refreshOnWindowFocus ? true
if refreshOnWindowFocus

View File

@@ -9,8 +9,10 @@ module.exports =
statuses = {}
for path, status of repo.getRepo().getStatuses()
statuses[fs.join(workingDirectoryPath, path)] = status
upstream = repo.getAheadBehindCounts() ? {ahead: 0, behind: 0}
repo.destroy()
else
upstream = {}
statuses = {}
callTaskMethod('statusesLoaded', statuses)
callTaskMethod('statusesLoaded', {statuses, upstream})

View File

@@ -9,8 +9,9 @@ class RepositoryStatusTask extends Task
started: ->
@callWorkerMethod('loadStatuses', @repo.getPath())
statusesLoaded: (statuses) ->
statusesLoaded: ({statuses, upstream}) ->
@done()
unless _.isEqual(statuses, @repo.statuses)
@repo.statuses = statuses
@repo.trigger 'statuses-changed'
statusesUnchanged = _.isEqual(statuses, @repo.statuses) and _.isEqual(upstream, @repo.upstream)
@repo.statuses = statuses
@repo.upstream = upstream
@repo.trigger 'statuses-changed' unless statusesUnchanged

View File

@@ -17,6 +17,8 @@ class StatusBarView extends View
@span class: 'git-branch', outlet: 'branchArea', =>
@span class: 'octicons branch-icon'
@span class: 'branch-label', outlet: 'branchLabel'
@span class: 'octicons commits-ahead-label', outlet: 'commitsAhead'
@span class: 'octicons commits-behind-label', outlet: 'commitsBehind'
@span class: 'git-status', outlet: 'gitStatusIcon'
@span class: 'file-info', =>
@span class: 'current-path', outlet: 'currentPath'
@@ -82,6 +84,16 @@ class StatusBarView extends View
@gitStatusIcon.addClass('git-status octicons')
return unless git?
if git.upstream.ahead > 0
@commitsAhead.text(git.upstream.ahead).show()
else
@commitsAhead.hide()
if git.upstream.behind > 0
@commitsBehind.text(git.upstream.behind).show()
else
@commitsBehind.hide()
status = git.statuses[path]
if git.isStatusModified(status)
@gitStatusIcon.addClass('modified-status-icon')