pulsar/spec/app/git-spec.coffee

73 lines
2.6 KiB
CoffeeScript
Raw Normal View History

2012-10-26 01:52:25 +04:00
Git = require 'git'
2012-10-27 20:37:28 +04:00
fs = require 'fs'
2012-10-26 01:52:25 +04:00
describe "Git", ->
2012-10-27 20:37:28 +04:00
beforeEach ->
fs.remove('/tmp/.git') if fs.isDirectory('/tmp/.git')
2012-11-03 00:24:38 +04:00
describe ".getPath()", ->
it "returns the repository path for a .git directory path", ->
2012-10-26 02:20:12 +04:00
repo = new Git(require.resolve('fixtures/git/master.git/HEAD'))
expect(repo.getPath()).toBe require.resolve('fixtures/git/master.git') + '/'
it "returns the repository path for a repository path", ->
repo = new Git(require.resolve('fixtures/git/master.git'))
expect(repo.getPath()).toBe require.resolve('fixtures/git/master.git') + '/'
2012-11-03 00:24:38 +04:00
describe ".getHead()", ->
2012-10-27 20:37:28 +04:00
it "returns null for a non-repository", ->
repo = new Git('/tmp/nogit.txt')
2012-10-26 01:52:25 +04:00
expect(repo.getHead()).toBeNull
it "returns a branch name for a non-empty repository", ->
repo = new Git(require.resolve('fixtures/git/master.git'))
expect(repo.getHead()).toBe 'refs/heads/master'
2012-11-03 00:24:38 +04:00
describe ".getShortHead()", ->
2012-10-27 20:37:28 +04:00
it "returns null for a non-repository", ->
repo = new Git('/tmp/nogit.txt')
2012-10-26 01:52:25 +04:00
expect(repo.getShortHead()).toBeNull
it "returns a branch name for a non-empty repository", ->
repo = new Git(require.resolve('fixtures/git/master.git'))
2012-10-26 01:58:13 +04:00
expect(repo.getShortHead()).toBe 'master'
2012-10-27 03:24:47 +04:00
2012-11-03 00:24:38 +04:00
describe ".isIgnored(path)", ->
2012-10-27 03:24:47 +04:00
it "returns true for an ignored path", ->
repo = new Git(require.resolve('fixtures/git/ignore.git'))
expect(repo.isIgnored('a.txt')).toBeTruthy()
it "returns false for a non-ignored path", ->
repo = new Git(require.resolve('fixtures/git/ignore.git'))
2012-10-27 20:14:09 +04:00
expect(repo.isIgnored('b.txt')).toBeFalsy()
2012-11-03 00:24:38 +04:00
describe ".isModified(path)", ->
[repo, path, originalPathText, newPath] = []
beforeEach ->
repo = new Git(require.resolve('fixtures/git/working-dir'))
path = require.resolve('fixtures/git/working-dir/file.txt')
originalPathText = fs.read(path)
newPath = fs.join(require.resolve('fixtures/git/working-dir'), 'new-path.txt')
fs.write(newPath, "i'm new here")
afterEach ->
fs.write(path, originalPathText)
fs.remove(newPath) if fs.exists(newPath)
describe "when the path is unstaged", ->
it "returns false if the path has not been modified", ->
expect(repo.isModified(path)).toBeFalsy()
it "returns true if the path is new", ->
expect(repo.isModified(newPath)).toBeTruthy()
it "returns true if the path is modified", ->
fs.write(path, "change")
expect(repo.isModified(path)).toBeTruthy()
it "returns true if the path is deleted", ->
fs.remove(path)
expect(repo.isModified(path)).toBeTruthy()