| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,8 +3,14 @@ var path = require('path'); | |||
| 3 | 3 | var Promise = require('nodegit-promise'); | |
| 4 | 4 | var promisify = require('promisify-node'); | |
| 5 | 5 | var fse = promisify(require('fs-extra')); | |
| 6 | + var mkdirp = promisify(require('mkdirp')); | ||
| 6 | 7 | var fileName = 'newfile.txt'; | |
| 7 | 8 | var fileContent = 'hello world'; | |
| 9 | + var directoryName = 'salad/toast/strangerinastrangeland/theresnowaythisexists'; | ||
| 10 | + // ensureDir is an alias to mkdirp, which has the callback with a weird name | ||
| 11 | + // and in the 3rd position of 4 (the 4th being used for recursion). We have to force | ||
| 12 | + // promisify it, because promisify-node won't detect it on its own and assumes sync | ||
| 13 | + fse.ensureDir = promisify(fse.ensureDir); | ||
| 8 | 14 | ||
| 9 | 15 | /** | |
| 10 | 16 | * This example creates a certain file `newfile.txt`, adds it to the git index and | |
@@ -19,8 +25,13 @@ var parent; | |||
| 19 | 25 | nodegit.Repository.open(path.resolve(__dirname, '../.git')) | |
| 20 | 26 | .then(function(repoResult) { | |
| 21 | 27 | repo = repoResult; | |
| 28 | + return fse.ensureDir(path.join(repo.workdir(), directoryName)); | ||
| 29 | + }).then(function(){ | ||
| 22 | 30 | return fse.writeFile(path.join(repo.workdir(), fileName), fileContent); | |
| 23 | 31 | }) | |
| 32 | + .then(function() { | ||
| 33 | + return fse.writeFile(path.join(repo.workdir(), directoryName, fileName), fileContent); | ||
| 34 | + }) | ||
| 24 | 35 | .then(function() { | |
| 25 | 36 | return repo.openIndex(); | |
| 26 | 37 | }) | |
@@ -31,6 +42,9 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')) | |||
| 31 | 42 | .then(function() { | |
| 32 | 43 | return index.addByPath(fileName); | |
| 33 | 44 | }) | |
| 45 | + .then(function() { | ||
| 46 | + return index.addByPath(path.join(directoryName, fileName)); | ||
| 47 | + }) | ||
| 34 | 48 | .then(function() { | |
| 35 | 49 | return index.write(); | |
| 36 | 50 | }) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments