|
| 1 | +var nodegit = require('../'); |
| 2 | +var path = require('path'); |
| 3 | +var Promise = require('nodegit-promise'); |
| 4 | +var promisify = require('promisify-node'); |
| 5 | +var fse = promisify(require('fs-extra')); |
| 6 | +var fileName = 'newfile.txt'; |
| 7 | +var fileContent = 'hello world'; |
| 8 | +var repoDir = '../../newRepo'; |
| 9 | + |
| 10 | +fse.ensureDir = promisify(fse.ensureDir); |
| 11 | + |
| 12 | +var repository; |
| 13 | +var index; |
| 14 | + |
| 15 | +fse.ensureDir(path.resolve(__dirname, repoDir)) |
| 16 | +.then(function() { |
| 17 | + console.log('a'); |
| 18 | + return nodegit.Repository.init(path.resolve(__dirname, repoDir), 0); |
| 19 | +}) |
| 20 | +.then(function(repo) { |
| 21 | + console.log('b'); |
| 22 | + repository = repo; |
| 23 | + return fse.writeFile(path.join(repository.workdir(), fileName), fileContent); |
| 24 | +}) |
| 25 | +.then(function(){ |
| 26 | + console.log('c'); |
| 27 | + return repository.openIndex(); |
| 28 | +}) |
| 29 | +.then(function(idx) { |
| 30 | + console.log('d'); |
| 31 | + index = idx; |
| 32 | + return index.read(1); |
| 33 | +}) |
| 34 | +.then(function() { |
| 35 | + console.log('e'); |
| 36 | + return index.addByPath(fileName); |
| 37 | +}) |
| 38 | +.then(function() { |
| 39 | + console.log('f'); |
| 40 | + return index.write(); |
| 41 | +}) |
| 42 | +.then(function() { |
| 43 | + console.log('g'); |
| 44 | + return index.writeTree(); |
| 45 | +}) |
| 46 | +.then(function(oid) { |
| 47 | + console.log('j'); |
| 48 | + var author = nodegit.Signature.create("Scott Chacon", "[email protected]", 123456789, 60); |
| 49 | + var committer = nodegit.Signature.create("Scott A Chacon", "[email protected]", 987654321, 90); |
| 50 | + |
| 51 | + // Since we're creating an inital commit, it has no parents. Note that unlike |
| 52 | + // normal we don't get the head either, because there isn't one yet. |
| 53 | + return repository.createCommit('HEAD', author, committer, 'message', oid, []); |
| 54 | +}) |
| 55 | +.done(function(commitId) { |
| 56 | + console.log('New Commit: ', commitId); |
| 57 | +}); |
0 commit comments