isPathNew

This commit is contained in:
Daniel Hengeveld
2015-10-15 18:26:20 +02:00
parent 62310e6f41
commit 7679ff93d3
2 changed files with 34 additions and 9 deletions

View File

@@ -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] = []

View File

@@ -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)
})