From a4565011fb12a98ee5f9a26a6d1b62ec0b4a2290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20=C5=BDia=C4=8Dik?= Date: Tue, 19 Apr 2016 21:14:13 +0200 Subject: [PATCH] Added simple stash support --- lib/git-control-view.coffee | 8 ++++++++ lib/git.coffee | 12 +++++++++++- lib/views/menu-view.coffee | 2 ++ spec/git-control-view-spec.coffee | 24 ++++++++++++++++++++++-- styles/icons.less | 8 ++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/lib/git-control-view.coffee b/lib/git-control-view.coffee index 5122a81..03f2fc7 100644 --- a/lib/git-control-view.coffee +++ b/lib/git-control-view.coffee @@ -209,6 +209,14 @@ class GitControlView extends View git.pullup().then => @update(true) return + stashSaveMenuClick: -> + git.stashSave().then => @update(true) + return + + stashPopMenuClick: -> + git.stashPop().then => @update(true) + return + pushMenuClick: -> git.getBranches().then (branches) => @pushDialog.activate(branches.remote) return diff --git a/lib/git.coffee b/lib/git.coffee index dde5ac2..5c67032 100644 --- a/lib/git.coffee +++ b/lib/git.coffee @@ -99,7 +99,7 @@ callGit = (cmd, parser, nodatalog) -> logcb e.stdout, true logcb e.message, true return - + module.exports = isInitialised: -> return cwd @@ -223,5 +223,15 @@ module.exports = atomRefresh() return parseDefault(true) + stashSave: -> + return callGit "stash save", (data) -> + atomRefresh() + return parseDefault(data) + + stashPop: -> + return callGit "stash pop", (data) -> + atomRefresh() + return parseDefault(data) + status: -> return callGit 'status --porcelain --untracked-files=all', parseStatus diff --git a/lib/views/menu-view.coffee b/lib/views/menu-view.coffee index 37b3475..0eda80b 100644 --- a/lib/views/menu-view.coffee +++ b/lib/views/menu-view.coffee @@ -12,6 +12,8 @@ items = [ { id: 'push', menu: 'Push', icon: 'push', type: 'downstream'} { id: 'merge', menu: 'Merge', icon: 'merge', type: 'active'} { id: 'branch', menu: 'Branch', icon: 'branch', type: 'active'} + { id: 'stashSave', menu: 'Stash Save', icon: 'stash-save', type: 'file merging'} + { id: 'stashPop', menu: 'Stash Pop', icon: 'stash-pop', type: 'active'} #{ id: 'tag', menu: 'Tag', icon: 'tag'} { id: 'flow', menu: 'GitFlow', icon: 'flow', type: 'active', showConfig: 'git-control.showGitFlowButton'} ] diff --git a/spec/git-control-view-spec.coffee b/spec/git-control-view-spec.coffee index f0ebc77..8bc24d8 100644 --- a/spec/git-control-view-spec.coffee +++ b/spec/git-control-view-spec.coffee @@ -1,5 +1,25 @@ +git = require '../lib/git' GitControlView = require '../lib/git-control-view' describe "GitControlView", -> - it "has one valid test", -> - expect("life").toBe "easy" + updateSpy = null + stashSaveSpy = null + stashPopSpy = null + gitControlView = null + + beforeEach -> + gitControlView = new GitControlView() + updateSpy = spyOn(gitControlView, 'update') + fakePromise = then : (f) -> f() + stashSaveSpy = spyOn(git, 'stashSave').andReturn(fakePromise) + stashPopSpy = spyOn(git, 'stashPop').andReturn(fakePromise) + + it "calls git stashSave on Stash Save", -> + gitControlView.stashSaveMenuClick() + expect(stashSaveSpy).toHaveBeenCalled() + expect(updateSpy).toHaveBeenCalled() + + it "calls git stashPop on Stash Pop", -> + gitControlView.stashPopMenuClick() + expect(stashPopSpy).toHaveBeenCalled() + expect(updateSpy).toHaveBeenCalled() diff --git a/styles/icons.less b/styles/icons.less index efe0351..e0f2d11 100644 --- a/styles/icons.less +++ b/styles/icons.less @@ -119,6 +119,14 @@ content: '\f053' } + &.stash-save:before { + content: '\f036' + } + + &.stash-pop:before { + content: '\f032' + } + &.sync:before { content: '\f087' }