From c14aa3b86f4f00492cb84ec08848a16b7d8fb68b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 1 Mar 2013 18:42:41 -0800 Subject: [PATCH] Default status to 0 if undefined This keeps the status-changed event from triggering the first time the status is requested as it goes from undefined to 0 which should be treated as no change. --- spec/app/git-spec.coffee | 12 +++++------- src/app/git.coffee | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/spec/app/git-spec.coffee b/spec/app/git-spec.coffee index 27a72d694..36ca195e1 100644 --- a/spec/app/git-spec.coffee +++ b/spec/app/git-spec.coffee @@ -127,9 +127,10 @@ describe "Git", -> expect(repo.isPathModified(path2)).toBeTruthy() it "fires a status-changed event if the checkout completes successfully", -> + fs.write(path1, '') + repo.getPathStatus(path1) statusHandler = jasmine.createSpy('statusHandler') repo.on 'status-changed', statusHandler - fs.write(path1, '') repo.checkoutHead(path1) expect(statusHandler.callCount).toBe 1 expect(statusHandler.argsForCall[0][0..1]).toEqual [path1, 0] @@ -173,17 +174,14 @@ describe "Git", -> 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 + fs.write(path, '') status = repo.getPathStatus(path) expect(statusHandler.callCount).toBe 1 expect(statusHandler.argsForCall[0][0..1]).toEqual [path, status] - fs.write(path, '') + fs.write(path, 'abc') 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 + expect(statusHandler.callCount).toBe 1 describe ".refreshStatus()", -> [newPath, modifiedPath, cleanPath, originalModifiedPathText] = [] diff --git a/src/app/git.coffee b/src/app/git.coffee index d1f213c28..427017239 100644 --- a/src/app/git.coffee +++ b/src/app/git.coffee @@ -70,8 +70,8 @@ class Git @getRepo().getHead() ? '' getPathStatus: (path) -> - currentPathStatus = @statuses[path] - pathStatus = @getRepo().getStatus(@relativize(path)) + currentPathStatus = @statuses[path] ? 0 + pathStatus = @getRepo().getStatus(@relativize(path)) ? 0 if pathStatus > 0 @statuses[path] = pathStatus else