Skip to content

Commit fa5f12b

Browse files
committed
update add-and-commit example to include new paths
1 parent 4462aaf commit fa5f12b

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

example/add-and-commit.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ var path = require('path');
33
var Promise = require('nodegit-promise');
44
var promisify = require('promisify-node');
55
var fse = promisify(require('fs-extra'));
6+
var mkdirp = promisify(require('mkdirp'));
67
var fileName = 'newfile.txt';
78
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);
814

915
/**
1016
* This example creates a certain file `newfile.txt`, adds it to the git index and
@@ -19,8 +25,13 @@ var parent;
1925
nodegit.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

Comments
 (0)