Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
/testing.js
/out
/test.git
/test/.reposCache
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
"devDependencies": {
"nodeunit": "",
"rimraf": "1.0.x",
"ejs": "0.8.x"
"ejs": "0.8.x",
"ncp": "~0.4.2"
},
"scripts": {
"install": "node install.js",
"test": "cd test && nodeunit *.js",
"test": "cd test && nodeunit nodegit.js",
"gen": "node gen.js"
}
}
2 changes: 1 addition & 1 deletion test/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var git = require('../'),
exports.content = function(test) {
var testOid = git.Oid.fromString('111dd657329797f6165f52f5085f61ac976dcf04');
test.expect(1);
git.Repo.open(path.resolve('../.git'), function(err, repo) {
git.Repo.open(path.resolve('repos/workdir/.git'), function(err, repo) {
repo.getBlob(testOid, function(err, blob) {
test.equals(blob.toString().slice(0, 7), "@import");
test.done();
Expand Down
32 changes: 16 additions & 16 deletions test/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6';

exports.message = function(test) {
test.expect(2);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var message = commit.message();
test.equals(error, null, 'There should be no error');
Expand All @@ -18,7 +18,7 @@ exports.message = function(test) {

exports.sha = function(test) {
test.expect(2);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var sha = commit.sha();
test.equals(error, null, 'There should be no error');
Expand All @@ -30,7 +30,7 @@ exports.sha = function(test) {

exports.time = function(test) {
test.expect(2);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var time = commit.timeMs();
test.equals(error, null, 'There should be no error');
Expand All @@ -42,7 +42,7 @@ exports.time = function(test) {

exports.date = function(test) {
test.expect(2);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var date = commit.date();
test.equals(error, null, 'There should be no error');
Expand All @@ -54,7 +54,7 @@ exports.date = function(test) {

exports.offset = function(test) {
test.expect(2);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var offset = commit.offset();
test.equals(error, null, 'There should be no error');
Expand All @@ -66,7 +66,7 @@ exports.offset = function(test) {

exports.author = function(test) {
test.expect(2);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var author = commit.author();
test.equals(error, null, 'There should be no error');
Expand All @@ -78,7 +78,7 @@ exports.author = function(test) {

exports.authorName = function(test) {
test.expect(1);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var author = commit.author();
var name = author.name();
Expand All @@ -90,7 +90,7 @@ exports.authorName = function(test) {

exports.authorEmail = function(test) {
test.expect(1);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var author = commit.author();
var email = author.email();
Expand All @@ -102,7 +102,7 @@ exports.authorEmail = function(test) {

exports.committerName = function(test) {
test.expect(1);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var committer = commit.committer();
var name = committer.name();
Expand All @@ -114,7 +114,7 @@ exports.committerName = function(test) {

exports.committerEmail = function(test) {
test.expect(1);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
var committer = commit.committer();
var email = committer.email();
Expand All @@ -129,7 +129,7 @@ exports.committerEmail = function(test) {
*/
exports.improperCommitId = function(test) {
test.expect(1);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit('not a proper commit sha', function(error, commit) {
test.notEqual(error, null, 'Error should occur');
test.done();
Expand All @@ -142,7 +142,7 @@ exports.improperCommitId = function(test) {
*/
exports.history = function(test) {
test.expect(4);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
test.equals(null, error, 'Getting latest branch commit should not error');
var historyCount = 0;
Expand All @@ -167,7 +167,7 @@ exports.history = function(test) {
*/
exports.masterHead = function(test) {
test.expect(1);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getBranch('master', function(error, branch) {
var sha = branch.sha();
repository.getCommit(sha, function(error, commit) {
Expand All @@ -185,7 +185,7 @@ exports.masterHead = function(test) {
*/
exports.parents = function(test) {
test.expect(3);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
commit.getParents(function(error, parents) {
test.equals(parents.length, 1, 'Commit should have exactly one parent');
Expand All @@ -203,7 +203,7 @@ exports.parents = function(test) {
*/
exports.tree = function(test) {
test.expect(2);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
test.equals(error, null, 'Getting latest branch commit should not error');

Expand All @@ -226,7 +226,7 @@ exports.tree = function(test) {
*/
exports.getDiff = function(test) {
test.expect(1);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
commit.getDiff(function(error, diff) {
test.equals(diff.length, 1, 'Should be one item in parents diff trees');
Expand Down
2 changes: 1 addition & 1 deletion test/difflist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6';
*/
exports.walkingDiffs = function(test) {
test.expect(16);
git.Repo.open('../.git', function(error, repository) {
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
commit.getDiff(function(error, diffList) {
test.equal(null, error, 'Should not error');
Expand Down
45 changes: 45 additions & 0 deletions test/nodegit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var fs = require('fs');
var rimraf = require('rimraf');
var ncp = require('ncp').ncp;
var exec = require('child_process').exec;
var path = require('path');
var async = require('async');

var testFiles = ['blob','difflist','oid','repo','tree_entry','commit','reference','revwalk','tree'];

function setupReposCache(cb) {
fs.mkdir('.reposCache',function() {
async.series([
function empty(cb) { exec('git init .reposCache/empty',cb); },
function workdir(cb) { exec('git clone https://github.com/nodegit/nodegit.git .reposCache/workdir',cb); },
function nonrepo(cb) {
fs.mkdir('.reposCache/nonrepo',function() {
fs.writeFile('.reposCache/nonrepo/file.txt','This is a bogus file',cb);
});
}
],cb);
});
}

module.exports = {
setUp: function(cb) {
fs.exists('.reposCache',function(exists) {
if (exists) {
ncp('.reposCache','repos',cb);
} else {
setupReposCache(function(err) {
if (err) { return cb(err); }
ncp('.reposCache','repos',cb);
});
}
});
},
tearDown: function(cb) {
rimraf('repos',cb);
}
};

for(var i in testFiles) {
var testFile = testFiles[i];
module.exports[testFile] = require('./'+testFile);
}
19 changes: 0 additions & 19 deletions test/npm-debug.log

This file was deleted.

2 changes: 1 addition & 1 deletion test/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var git = require('../'),
exports.lookup = function(test) {
test.expect(1);

git.Repo.open('../.git', function(error, repo) {
git.Repo.open('repos/workdir/.git', function(error, repo) {
repo.getReference('refs/heads/master', function(error, reference) {
test.ok(reference instanceof git.Reference);
test.done();
Expand Down
42 changes: 21 additions & 21 deletions test/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@ var git = require('../'),
* Ensure the repo method can handle opening repositories with async/sync
* signatures properly.
*/
exports.open = function(test){
test.expect(2);
exports.openInvalidRepo = function(test){
test.expect(1);

// Test invalid repository
git.Repo.open('../templates', function(error, repository) {
test.equals(error.message, "Could not find repository from '../templates'");
git.Repo.open('repos/nonrepo', function(error, repository) {
test.equals(error.message, "Could not find repository from 'repos/nonrepo'");
test.done();
});
};

// Test valid repository
git.Repo.open('../.git', function(error, repository) {
test.equals(null, error, 'Valid repository error code');
test.done();
});
exports.openValidRepo = function(test){
test.expect(1);

// Test valid repository
git.Repo.open('repos/workdir/.git', function(error, repository) {
test.equals(null, error, 'Valid repository error code');
test.done();
});
};

Expand All @@ -40,18 +45,13 @@ exports.nonexistentDirectory = function(test) {
*/
exports.init = function(test) {
test.expect(2);
// Cleanup, remove test repo directory - if it exists
rimraf('./test.git', function() {
// Create bare repo and test for creation
git.Repo.init('./test.git', true, function(error, path, isBare) {
test.equals(null, error, 'Successfully created bare repository');
// Verify repo exists
git.Repo.open('./test.git', function(error, path, repo) {
test.equals(null, error, 'Valid repository created');

// Cleanup, remove test repo directory
rimraf('./test.git', test.done);
});
// Create bare repo and test for creation
git.Repo.init('repos/newrepo', true, function(error, path, isBare) {
test.equals(null, error, 'Successfully created bare repository');
// Verify repo exists
git.Repo.open('repos/newrepo', function(error, path, repo) {
test.equals(null, error, 'Valid repository created');
test.done();
});
});
};
6 changes: 3 additions & 3 deletions test/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var fileCount = 512; // Number of blob & blob executabless
exports.walk = function(test) {
test.expect(515);

git.Repo.open('../.git', function(error, repo) {
git.Repo.open('repos/workdir/.git', function(error, repo) {
repo.getCommit(sha, function(error, commit) {
var entryCount = 0;
commit.getTree(function(error, tree) {
Expand All @@ -29,8 +29,8 @@ exports.walk = function(test) {
exports.insert = function(test) {
test.expect(1);

git.Repo.open('../.git', function(error, repo) {
repo.getCommit('1e7bc7fba93aabc8c76ebea41918f9ad892141ed', function(error, commit) {
git.Repo.open('repos/workdir/.git', function(error, repo) {
repo.getCommit(sha, function(error, commit) {
commit.getTree(function(error, tree) {
var text = "this is a file\n",
buffer = new Buffer(text);
Expand Down
2 changes: 1 addition & 1 deletion test/tree_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var git = require('../');
var sha = '5716e9757886eaf38d51c86b192258c960d9cfea';

var getEntry = function(path, callback) {
git.Repo.open('../.git', function(error, repo) {
git.Repo.open('repos/workdir/.git', function(error, repo) {
repo.getCommit(sha, function(error, commit) {
commit.getEntry(path, callback);
});
Expand Down