From e3ebda7d300b1adac037cf4007923b00fdd6525c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 1 Mar 2013 14:01:43 -0800 Subject: [PATCH] Show commits ahead/behind upstream in status bar --- src/app/git.coffee | 2 ++ src/app/repository-status-handler.coffee | 4 +++- src/app/repository-status-task.coffee | 9 +++++---- src/packages/status-bar/lib/status-bar-view.coffee | 12 ++++++++++++ static/status-bar.css | 14 ++++++++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/app/git.coffee b/src/app/git.coffee index e8fa7463b..1a9420cb7 100644 --- a/src/app/git.coffee +++ b/src/app/git.coffee @@ -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 diff --git a/src/app/repository-status-handler.coffee b/src/app/repository-status-handler.coffee index bd2d2fe70..b01cdf437 100644 --- a/src/app/repository-status-handler.coffee +++ b/src/app/repository-status-handler.coffee @@ -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}) diff --git a/src/app/repository-status-task.coffee b/src/app/repository-status-task.coffee index b7535e38a..0e5f746a5 100644 --- a/src/app/repository-status-task.coffee +++ b/src/app/repository-status-task.coffee @@ -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 diff --git a/src/packages/status-bar/lib/status-bar-view.coffee b/src/packages/status-bar/lib/status-bar-view.coffee index 15a8be49a..cf287e518 100644 --- a/src/packages/status-bar/lib/status-bar-view.coffee +++ b/src/packages/status-bar/lib/status-bar-view.coffee @@ -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') diff --git a/static/status-bar.css b/static/status-bar.css index 4cc898c41..d7822f50c 100644 --- a/static/status-bar.css +++ b/static/status-bar.css @@ -55,3 +55,17 @@ .status-bar .new-status-icon:before { content: "\f26b"; } + +.status-bar .commits-behind-label:before { + margin-top: -3px; + margin-left: 3px; + margin-right: 1px; + content: "\f03f"; +} + +.status-bar .commits-ahead-label:before { + margin-top: -3px; + margin-left: 3px; + margin-right: 1px; + content: "\f03d"; +}