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()", ->
|
2012-10-27 03:03:11 +04:00
|
|
|
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 01:54:12 +04:00
|
|
|
describe ".isPathIgnored(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'))
|
2012-11-03 01:54:12 +04:00
|
|
|
expect(repo.isPathIgnored('a.txt')).toBeTruthy()
|
2012-10-27 03:24:47 +04:00
|
|
|
|
|
|
|
it "returns false for a non-ignored path", ->
|
|
|
|
repo = new Git(require.resolve('fixtures/git/ignore.git'))
|
2012-11-03 01:54:12 +04:00
|
|
|
expect(repo.isPathIgnored('b.txt')).toBeFalsy()
|
2012-11-03 00:24:38 +04:00
|
|
|
|
2012-11-03 01:54:12 +04:00
|
|
|
describe ".isPathModified(path)", ->
|
|
|
|
[repo, path, newPath, originalPathText] = []
|
2012-11-03 00:24:38 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
repo = new Git(require.resolve('fixtures/git/working-dir'))
|
|
|
|
path = require.resolve('fixtures/git/working-dir/file.txt')
|
|
|
|
newPath = fs.join(require.resolve('fixtures/git/working-dir'), 'new-path.txt')
|
2012-11-03 01:54:12 +04:00
|
|
|
originalPathText = fs.read(path)
|
2012-11-03 00:24:38 +04:00
|
|
|
|
|
|
|
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", ->
|
2012-11-03 01:54:12 +04:00
|
|
|
expect(repo.isPathModified(path)).toBeFalsy()
|
2012-11-03 00:24:38 +04:00
|
|
|
|
|
|
|
it "returns true if the path is modified", ->
|
|
|
|
fs.write(path, "change")
|
2012-11-03 01:54:12 +04:00
|
|
|
expect(repo.isPathModified(path)).toBeTruthy()
|
2012-11-03 00:24:38 +04:00
|
|
|
|
|
|
|
it "returns true if the path is deleted", ->
|
|
|
|
fs.remove(path)
|
2012-11-03 01:54:12 +04:00
|
|
|
expect(repo.isPathModified(path)).toBeTruthy()
|
|
|
|
|
|
|
|
it "returns false if the path is new", ->
|
|
|
|
expect(repo.isPathModified(newPath)).toBeFalsy()
|
|
|
|
|
|
|
|
describe ".isPathNew(path)", ->
|
|
|
|
[repo, path, newPath] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
repo = new Git(require.resolve('fixtures/git/working-dir'))
|
|
|
|
path = require.resolve('fixtures/git/working-dir/file.txt')
|
|
|
|
newPath = fs.join(require.resolve('fixtures/git/working-dir'), 'new-path.txt')
|
|
|
|
fs.write(newPath, "i'm new here")
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
fs.remove(newPath) if fs.exists(newPath)
|
|
|
|
|
|
|
|
describe "when the path is unstaged", ->
|
|
|
|
it "returns true if the path is new", ->
|
|
|
|
expect(repo.isPathNew(newPath)).toBeTruthy()
|
|
|
|
|
|
|
|
it "returns false if the path isn't new", ->
|
|
|
|
expect(repo.isPathNew(path)).toBeFalsy()
|