From 68b61d71c6e66944bbcdc398654b6690b0a10ae2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 27 Feb 2013 15:36:08 -0800 Subject: [PATCH] Trigger event when path status changes --- spec/app/git-spec.coffee | 26 ++++++++++++++++++++++++++ src/app/git.coffee | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/spec/app/git-spec.coffee b/spec/app/git-spec.coffee index 2a9522d3a..2697e9723 100644 --- a/spec/app/git-spec.coffee +++ b/spec/app/git-spec.coffee @@ -148,6 +148,32 @@ describe "Git", -> fs.write(path, "#{originalPathText} edited line") expect(repo.getDiffStats(path)).toEqual {added: 1, deleted: 1} + describe ".getPathStatus(path)", -> + [path, originalPathText] = [] + + beforeEach -> + repo = new Git(require.resolve('fixtures/git/working-dir')) + path = require.resolve('fixtures/git/working-dir/file.txt') + originalPathText = fs.read(path) + + afterEach -> + fs.write(path, originalPathText) + + it "trigger a status-changed event when the new status differs from the last cached one", -> + statusHandler = jasmine.createSpy("statusHandler") + repo.on 'status-changed', statusHandler + status = repo.getPathStatus(path) + expect(statusHandler.callCount).toBe 1 + expect(statusHandler.argsForCall[0][0..1]).toEqual [path, status] + + fs.write(path, '') + status = repo.getPathStatus(path) + expect(statusHandler.callCount).toBe 2 + expect(statusHandler.argsForCall[1][0..1]).toEqual [path, status] + + repo.getPathStatus(path) + expect(statusHandler.callCount).toBe 2 + describe ".refreshStatus()", -> [newPath, modifiedPath, cleanPath, originalModifiedPathText] = [] diff --git a/src/app/git.coffee b/src/app/git.coffee index 5284b7e5a..8e24a4b97 100644 --- a/src/app/git.coffee +++ b/src/app/git.coffee @@ -59,7 +59,12 @@ class Git @getRepo().getHead() ? '' getPathStatus: (path) -> + currentPathStatus = @statuses[path] pathStatus = @getRepo().getStatus(@relativize(path)) + @statuses[path] = pathStatus + if currentPathStatus isnt pathStatus + @trigger 'status-changed', path, pathStatus + pathStatus isPathIgnored: (path) -> @getRepo().isIgnored(@relativize(path))