FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

update add-and-commit example to include new paths by maxkorp · Pull Request #283 · nodegit/nodegit · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 14 additions & 0 deletions example/add-and-commit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ var path = require('path');
var Promise = require('nodegit-promise');
var promisify = require('promisify-node');
var fse = promisify(require('fs-extra'));
var mkdirp = promisify(require('mkdirp'));
var fileName = 'newfile.txt';
var fileContent = 'hello world';
var directoryName = 'salad/toast/strangerinastrangeland/theresnowaythisexists';
// ensureDir is an alias to mkdirp, which has the callback with a weird name
// and in the 3rd position of 4 (the 4th being used for recursion). We have to force
// promisify it, because promisify-node won't detect it on its own and assumes sync
fse.ensureDir = promisify(fse.ensureDir);

/**
* This example creates a certain file `newfile.txt`, adds it to the git index and
Expand All @@ -19,8 +25,13 @@ var parent;
nodegit.Repository.open(path.resolve(__dirname, '../.git'))
.then(function(repoResult) {
repo = repoResult;
return fse.ensureDir(path.join(repo.workdir(), directoryName));
}).then(function(){
return fse.writeFile(path.join(repo.workdir(), fileName), fileContent);
})
.then(function() {
return fse.writeFile(path.join(repo.workdir(), directoryName, fileName), fileContent);
})
.then(function() {
return repo.openIndex();
})
Expand All @@ -31,6 +42,9 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git'))
.then(function() {
return index.addByPath(fileName);
})
.then(function() {
return index.addByPath(path.join(directoryName, fileName));
})
.then(function() {
return index.write();
})
Expand Down

Back | FazBrowse Home | New Git URL