| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -535,13 +535,16 @@ Repository.prototype.createCommitOnHead = function( | |||
| 535 | 535 | .then(function(treeOid) { | |
| 536 | 536 | return repo.getHeadCommit() | |
| 537 | 537 | .then(function(parent) { | |
| 538 | + if (parent !== null) { // To handle a fresh repo with no commits | ||
| 539 | + parent = [parent]; | ||
| 540 | + } | ||
| 538 | 541 | return repo.createCommit( | |
| 539 | 542 | "HEAD", | |
| 540 | 543 | author, | |
| 541 | 544 | committer, | |
| 542 | 545 | message, | |
| 543 | 546 | treeOid, | |
| 544 | - [parent] | ||
| 547 | + parent | ||
| 545 | 548 | ); | |
| 546 | 549 | }); | |
| 547 | 550 | }, callback); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -231,4 +231,33 @@ describe("Repository", function() { | |||
| 231 | 231 | assert(!commit); | |
| 232 | 232 | }); | |
| 233 | 233 | }); | |
| 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 | + }); | ||
| 234 | 263 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments