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
5 changes: 4 additions & 1 deletion lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions test/tests/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
});
});
});
});