diff --git a/spec/git-repository-async-spec.coffee b/spec/git-repository-async-spec.coffee index 180988d83..0eba6a4f4 100644 --- a/spec/git-repository-async-spec.coffee +++ b/spec/git-repository-async-spec.coffee @@ -91,7 +91,7 @@ fdescribe "GitRepositoryAsync", -> beforeEach -> workingDirPath = copyRepository() - repo = new GitRepositoryAsync.open(workingDirPath) + repo = GitRepositoryAsync.open(workingDirPath) filePath = path.join(workingDirPath, 'a.txt') newPath = path.join(workingDirPath, 'new-path.txt') fs.writeFileSync(newPath, "i'm new here") @@ -136,22 +136,31 @@ fdescribe "GitRepositoryAsync", -> runs -> expect(onSuccess.mostRecentCall.args[0]).toBeFalsy() - xdescribe ".isPathNew(path)", -> + describe ".isPathNew(path)", -> [filePath, newPath] = [] beforeEach -> workingDirPath = copyRepository() - repo = new GitRepository(workingDirPath) + repo = GitRepositoryAsync.open(workingDirPath) filePath = path.join(workingDirPath, 'a.txt') newPath = path.join(workingDirPath, 'new-path.txt') fs.writeFileSync(newPath, "i'm new here") - xdescribe "when the path is unstaged", -> + describe "when the path is unstaged", -> it "returns true if the path is new", -> - expect(repo.isPathNew(newPath)).toBeTruthy() + onSuccess = jasmine.createSpy('onSuccess') + waitsForPromise -> + repo.isPathNew(newPath).then(onSuccess) + runs -> + expect(onSuccess.mostRecentCall.args[0]).toBeTruthy() it "returns false if the path isn't new", -> - expect(repo.isPathNew(filePath)).toBeFalsy() + onSuccess = jasmine.createSpy('onSuccess') + waitsForPromise -> + repo.isPathModified(newPath).then(onSuccess) + runs -> + expect(onSuccess.mostRecentCall.args[0]).toBeFalsy() + xdescribe ".checkoutHead(path)", -> [filePath] = [] diff --git a/src/git-repository-async.js b/src/git-repository-async.js index 445e88ccb..6a07c93b3 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -37,16 +37,32 @@ module.exports = class GitRepositoryAsync { }) } - isPathModified(_path) { + _filterStatusesByPath(_path) { // Surely I'm missing a built-in way to do this var basePath = null return this.repoPromise.then( (repo) => { basePath = repo.workdir() return repo.getStatus() }).then( (statuses) => { - console.log(statuses.map(function(x){return x.path()})); + return statuses.filter(function (status) { + return _path == path.join(basePath, status.path()) + }) + }) + } + + isPathModified(_path) { + return this._filterStatusesByPath(_path).then(function(statuses) { ret = statuses.filter((status)=> { - return _path == path.join(basePath, status.path()) && (status.isModified() || status.isDeleted()) + return status.isModified() || status.isDeleted() + }).length > 0 + return Promise.resolve(ret) + }) + } + + isPathNew(_path) { + return this._filterStatusesByPath(_path).then(function(statuses) { + ret = statuses.filter((status)=> { + return status.isNew() }).length > 0 return Promise.resolve(ret) })