diff --git a/lib/repository.js b/lib/repository.js index 61d221729..47e2220e9 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -535,13 +535,16 @@ Repository.prototype.createCommitOnHead = function( .then(function(treeOid) { return repo.getHeadCommit() .then(function(parent) { + if (parent !== null) { // To handle a fresh repo with no commits + parent = [parent]; + } return repo.createCommit( "HEAD", author, committer, message, treeOid, - [parent] + parent ); }); }, callback); diff --git a/test/tests/repository.js b/test/tests/repository.js index adaec151e..6f710ef10 100644 --- a/test/tests/repository.js +++ b/test/tests/repository.js @@ -231,4 +231,33 @@ describe("Repository", function() { assert(!commit); }); }); + + it("can commit on head on a empty repo with createCommitOnHead", function() { + var fileName = "my-new-file-that-shouldnt-exist.file"; + var fileContent = "new file from repository test"; + var repo = this.emptyRepo; + var filePath = path.join(repo.workdir(), fileName); + var authSig = repo.defaultSignature(); + var commitSig = repo.defaultSignature(); + var commitMsg = "Doug this has been commited"; + + return fse.writeFile(filePath, fileContent) + .then(function() { + return repo.createCommitOnHead( + [filePath], + authSig, + commitSig, + commitMsg + ); + }) + .then(function(oidResult) { + return repo.getHeadCommit() + .then(function(commit) { + assert.equal( + commit.toString(), + oidResult.toString() + ); + }); + }); + }); });