Skip to content

Commit 77287fe

Browse files
committed
Merge pull request #927 from get-trucked/master
fixes #852 should not be an array with null in it
2 parents 4a8cf95 + 1973dfb commit 77287fe

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

lib/repository.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,16 @@ Repository.prototype.createCommitOnHead = function(
535535
.then(function(treeOid) {
536536
return repo.getHeadCommit()
537537
.then(function(parent) {
538+
if (parent !== null) { // To handle a fresh repo with no commits
539+
parent = [parent];
540+
}
538541
return repo.createCommit(
539542
"HEAD",
540543
author,
541544
committer,
542545
message,
543546
treeOid,
544-
[parent]
547+
parent
545548
);
546549
});
547550
}, callback);

test/tests/repository.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,33 @@ describe("Repository", function() {
231231
assert(!commit);
232232
});
233233
});
234+
235+
it("can commit on head on a empty repo with createCommitOnHead", function() {
236+
var fileName = "my-new-file-that-shouldnt-exist.file";
237+
var fileContent = "new file from repository test";
238+
var repo = this.emptyRepo;
239+
var filePath = path.join(repo.workdir(), fileName);
240+
var authSig = repo.defaultSignature();
241+
var commitSig = repo.defaultSignature();
242+
var commitMsg = "Doug this has been commited";
243+
244+
return fse.writeFile(filePath, fileContent)
245+
.then(function() {
246+
return repo.createCommitOnHead(
247+
[filePath],
248+
authSig,
249+
commitSig,
250+
commitMsg
251+
);
252+
})
253+
.then(function(oidResult) {
254+
return repo.getHeadCommit()
255+
.then(function(commit) {
256+
assert.equal(
257+
commit.toString(),
258+
oidResult.toString()
259+
);
260+
});
261+
});
262+
});
234263
});

0 commit comments

Comments
 (0)