File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments