2012-02-15 15:51:45 +01:00
|
|
|
should = require 'should'
|
|
|
|
fixtures = require './fixtures'
|
|
|
|
git = require '../src'
|
|
|
|
Tree = require '../src/tree'
|
|
|
|
Blob = require '../src/blob'
|
|
|
|
Submodule = require '../src/submodule'
|
|
|
|
|
|
|
|
describe "Tree", ->
|
|
|
|
describe "#contents", ->
|
|
|
|
describe "simple", ->
|
|
|
|
repo = fixtures.branched
|
|
|
|
tree = repo.tree()
|
|
|
|
contents = null
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
before (done) ->
|
|
|
|
tree.contents (err, _contents) ->
|
|
|
|
contents = _contents
|
|
|
|
done err
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "is an Array", ->
|
|
|
|
contents.should.be.an.instanceof Array
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "contains a Blob", ->
|
|
|
|
contents[0].should.be.an.instanceof Blob
|
|
|
|
contents[0].name.should.eql "README.md"
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "contains a Tree", ->
|
|
|
|
contents[1].should.be.an.instanceof Tree
|
|
|
|
contents[1].name.should.eql "some"
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
describe "with submodules", ->
|
|
|
|
repo = fixtures.submodule
|
|
|
|
tree = repo.tree()
|
|
|
|
contents = null
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
before (done) ->
|
|
|
|
tree.contents (err, _contents) ->
|
|
|
|
contents = _contents
|
|
|
|
done err
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "contains a Submodule", (done) ->
|
|
|
|
contents[2].should.be.an.instanceof Submodule
|
|
|
|
contents[2].name.should.eql "spoon-knife"
|
|
|
|
contents[2].url (err, url) ->
|
|
|
|
url.should.eql "git://github.com/octocat/Spoon-Knife.git"
|
|
|
|
done err
|
2014-06-20 02:08:29 +02:00
|
|
|
|
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
describe "#blobs", ->
|
|
|
|
repo = fixtures.branched
|
|
|
|
tree = repo.tree()
|
|
|
|
blobs = null
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
before (done) ->
|
|
|
|
tree.blobs (err, _blobs) ->
|
|
|
|
blobs = _blobs
|
|
|
|
done err
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "has only 1 item", ->
|
|
|
|
blobs.should.have.lengthOf 1
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "contains a Blob", ->
|
|
|
|
blobs[0].should.be.an.instanceof Blob
|
|
|
|
blobs[0].name.should.eql "README.md"
|
2014-06-20 02:08:29 +02:00
|
|
|
|
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
describe "#trees", ->
|
|
|
|
repo = fixtures.branched
|
|
|
|
tree = repo.tree()
|
|
|
|
trees = null
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
before (done) ->
|
|
|
|
tree.trees (err, _trees) ->
|
|
|
|
trees = _trees
|
|
|
|
done err
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "has only 1 item", ->
|
|
|
|
trees.should.have.lengthOf 1
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "contains a Tree", ->
|
|
|
|
trees[0].should.be.an.instanceof Tree
|
|
|
|
trees[0].name.should.eql "some"
|
2014-06-20 02:08:29 +02:00
|
|
|
|
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
describe "#find", ->
|
|
|
|
repo = fixtures.branched
|
|
|
|
tree = repo.tree()
|
|
|
|
describe "find a file", ->
|
|
|
|
blob = null
|
|
|
|
before (done) ->
|
|
|
|
tree.find "README.md", (err, _blob) ->
|
|
|
|
blob = _blob
|
|
|
|
done err
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "finds the Blob", ->
|
|
|
|
blob.should.be.an.instanceof Blob
|
|
|
|
blob.name.should.eql "README.md"
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
describe "find a directory", ->
|
|
|
|
subtree = null
|
|
|
|
before (done) ->
|
|
|
|
tree.find "some", (err, _tree) ->
|
|
|
|
subtree = _tree
|
|
|
|
done err
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "finds the Tree", ->
|
|
|
|
subtree.should.be.an.instanceof Tree
|
|
|
|
subtree.name.should.eql "some"
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-09-15 11:59:24 +02:00
|
|
|
describe "find inside a directory", ->
|
|
|
|
blob = null
|
|
|
|
before (done) ->
|
|
|
|
tree.find "some/hi.txt", (err, _blob) ->
|
|
|
|
blob = _blob
|
|
|
|
done err
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-09-15 11:59:24 +02:00
|
|
|
it "finds the Blob", ->
|
|
|
|
blob.should.be.an.instanceof Blob
|
|
|
|
blob.name.should.eql "hi.txt"
|
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
describe "find a nonexistant file", ->
|
|
|
|
subtree = null
|
|
|
|
before (done) ->
|
|
|
|
tree.find "nonexistant", (err, _tree) ->
|
|
|
|
subtree = _tree
|
|
|
|
done err
|
2014-06-20 02:08:29 +02:00
|
|
|
|
2012-02-15 15:51:45 +01:00
|
|
|
it "is null", ->
|
|
|
|
should.not.exist subtree
|
|
|
|
|