|
| 1 | +var assert = require("assert"); |
| 2 | +var path = require("path"); |
| 3 | +var local = path.join.bind(path, __dirname); |
| 4 | + |
| 5 | +describe("Revparse", function() { |
| 6 | + var NodeGit = require("../../"); |
| 7 | + var Repository = NodeGit.Repository; |
| 8 | + var Revparse = NodeGit.Revparse; |
| 9 | + |
| 10 | + var reposPath = local("../repos/workdir"); |
| 11 | + |
| 12 | + beforeEach(function() { |
| 13 | + var test = this; |
| 14 | + return Repository.open(reposPath) |
| 15 | + .then(function(repository) { |
| 16 | + test.repository = repository; |
| 17 | + return test.repository.getHeadCommit(); |
| 18 | + }) |
| 19 | + .then(function(commit) { |
| 20 | + test.commit = commit; |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + it("can revparse HEAD commit with single method", function() { |
| 25 | + var test = this; |
| 26 | + return Revparse.single(this.repository, "HEAD") |
| 27 | + .then(function(headCommit) { |
| 28 | + assert.ok(headCommit.isCommit()); |
| 29 | + assert.equal(headCommit.id().toString(), test.commit.id().toString()); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + it("will fail on invalid spec", function() { |
| 34 | + return Revparse.single(this.repository, "INVALID") |
| 35 | + .then(function() { |
| 36 | + |
| 37 | + }) |
| 38 | + .catch(function(error) { |
| 39 | + assert.ok(error instanceof Error); |
| 40 | + assert.equal(error.message, "Revspec 'INVALID' not found."); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + it("will fail without repo", function() { |
| 45 | + return Revparse.single("", "INVALID") |
| 46 | + .then(function() { |
| 47 | + |
| 48 | + }) |
| 49 | + .catch(function(error) { |
| 50 | + assert.ok(error instanceof Error); |
| 51 | + assert.equal(error.message, "Repository repo is required."); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it("will fail without spec", function() { |
| 56 | + return Revparse.single(this.repository) |
| 57 | + .then(function() { |
| 58 | + |
| 59 | + }) |
| 60 | + .catch(function(error) { |
| 61 | + assert.ok(error instanceof Error); |
| 62 | + assert.equal(error.message, "String spec is required."); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | +}); |
0 commit comments