@@ -3,8 +3,14 @@ var path = require('path');
33var Promise = require ( 'nodegit-promise' ) ;
44var promisify = require ( 'promisify-node' ) ;
55var fse = promisify ( require ( 'fs-extra' ) ) ;
6+ var mkdirp = promisify ( require ( 'mkdirp' ) ) ;
67var fileName = 'newfile.txt' ;
78var 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 ) ;
814
915/**
1016 * This example creates a certain file `newfile.txt`, adds it to the git index and
@@ -19,8 +25,13 @@ var parent;
1925nodegit . Repository . open ( path . resolve ( __dirname , '../.git' ) )
2026. then ( function ( repoResult ) {
2127 repo = repoResult ;
28+ return fse . ensureDir ( path . join ( repo . workdir ( ) , directoryName ) ) ;
29+ } ) . then ( function ( ) {
2230 return fse . writeFile ( path . join ( repo . workdir ( ) , fileName ) , fileContent ) ;
2331} )
32+ . then ( function ( ) {
33+ return fse . writeFile ( path . join ( repo . workdir ( ) , directoryName , fileName ) , fileContent ) ;
34+ } )
2435. then ( function ( ) {
2536 return repo . openIndex ( ) ;
2637} )
@@ -31,6 +42,9 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git'))
3142. then ( function ( ) {
3243 return index . addByPath ( fileName ) ;
3344} )
45+ . then ( function ( ) {
46+ return index . addByPath ( path . join ( directoryName , fileName ) ) ;
47+ } )
3448. then ( function ( ) {
3549 return index . write ( ) ;
3650} )
0 commit comments