isPathModified

This commit is contained in:
Daniel Hengeveld
2015-10-15 18:10:32 +02:00
parent bc3e8f02ad
commit 62310e6f41
2 changed files with 59 additions and 13 deletions

View File

@@ -1,15 +1,19 @@
temp = require 'temp'
GitRepositoryAsync = require '../src/git-repository-async'
fs = require 'fs-plus'
os = require 'os'
path = require 'path'
Task = require '../src/task'
Project = require '../src/project'
# Clean up when the process exits
temp.track()
copyRepository = ->
workingDirPath = temp.mkdirSync('atom-working-dir')
fs.copySync(path.join(__dirname, 'fixtures', 'git', 'working-dir'), workingDirPath)
fs.renameSync(path.join(workingDirPath, 'git.git'), path.join(workingDirPath, '.git'))
workingDirPath
fs.realpathSync(workingDirPath)
openFixture = (fixture)->
GitRepositoryAsync.open(path.join(__dirname, 'fixtures', 'git', fixture))
@@ -82,29 +86,55 @@ fdescribe "GitRepositoryAsync", ->
expect(onSuccess.mostRecentCall.args[0]).toBeFalsy()
xdescribe ".isPathModified(path)", ->
[repo, filePath, newPath] = []
describe ".isPathModified(path)", ->
[repo, filePath, newPath, emptyPath] = []
beforeEach ->
workingDirPath = copyRepository()
repo = new GitRepository(workingDirPath)
repo = new GitRepositoryAsync.open(workingDirPath)
filePath = path.join(workingDirPath, 'a.txt')
newPath = path.join(workingDirPath, 'new-path.txt')
fs.writeFileSync(newPath, "i'm new here")
emptyPath = path.join(workingDirPath, 'empty-path.txt')
xdescribe "when the path is unstaged", ->
it "returns false if the path has not been modified", ->
expect(repo.isPathModified(filePath)).toBeFalsy()
describe "when the path is unstaged", ->
it "resolves false if the path has not been modified", ->
onSuccess = jasmine.createSpy('onSuccess')
waitsForPromise ->
repo.isPathModified(filePath).then(onSuccess)
runs ->
expect(onSuccess.mostRecentCall.args[0]).toBeFalsy()
it "returns true if the path is modified", ->
it "resolves true if the path is modified", ->
fs.writeFileSync(filePath, "change")
expect(repo.isPathModified(filePath)).toBeTruthy()
onSuccess = jasmine.createSpy('onSuccess')
waitsForPromise ->
repo.isPathModified(filePath).then(onSuccess)
runs ->
expect(onSuccess.mostRecentCall.args[0]).toBeTruthy()
it "returns true if the path is deleted", ->
it "resolves true if the path is deleted", ->
fs.removeSync(filePath)
expect(repo.isPathModified(filePath)).toBeTruthy()
onSuccess = jasmine.createSpy('onSuccess')
waitsForPromise ->
repo.isPathModified(filePath).then(onSuccess)
runs ->
expect(onSuccess.mostRecentCall.args[0]).toBeTruthy()
it "returns false if the path is new", ->
expect(repo.isPathModified(newPath)).toBeFalsy()
it "resolves false if the path is new", ->
onSuccess = jasmine.createSpy('onSuccess')
waitsForPromise ->
repo.isPathModified(newPath).then(onSuccess)
runs ->
expect(onSuccess.mostRecentCall.args[0]).toBeFalsy()
it "resolves false if the path is invalid", ->
onSuccess = jasmine.createSpy('onSuccess')
waitsForPromise ->
repo.isPathModified(emptyPath).then(onSuccess)
runs ->
expect(onSuccess.mostRecentCall.args[0]).toBeFalsy()
xdescribe ".isPathNew(path)", ->
[filePath, newPath] = []

View File

@@ -1,6 +1,7 @@
"use babel";
const Git = require('nodegit')
const path = require('path')
module.exports = class GitRepositoryAsync {
static open(path) {
@@ -35,4 +36,19 @@ module.exports = class GitRepositoryAsync {
return Promise.resolve(Git.Ignore.pathIsIgnored(repo, _path))
})
}
isPathModified(_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()}));
ret = statuses.filter((status)=> {
return _path == path.join(basePath, status.path()) && (status.isModified() || status.isDeleted())
}).length > 0
return Promise.resolve(ret)
})
}
}