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

Add repo init example by maxkorp · Pull Request #284 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) .json  (1) All 2 file types 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
1 change: 0 additions & 1 deletion 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,7 +3,6 @@ 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';
Expand Down
57 changes: 57 additions & 0 deletions example/create-new-repo.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
@@ -0,0 +1,57 @@
var nodegit = require('../');
var path = require('path');
var Promise = require('nodegit-promise');
var promisify = require('promisify-node');
var fse = promisify(require('fs-extra'));
var fileName = 'newfile.txt';
var fileContent = 'hello world';
var repoDir = '../../newRepo';

fse.ensureDir = promisify(fse.ensureDir);

var repository;
var index;

fse.ensureDir(path.resolve(__dirname, repoDir))
.then(function() {
console.log('a');
return nodegit.Repository.init(path.resolve(__dirname, repoDir), 0);
})
.then(function(repo) {
console.log('b');
repository = repo;
return fse.writeFile(path.join(repository.workdir(), fileName), fileContent);
})
.then(function(){
console.log('c');
return repository.openIndex();
})
.then(function(idx) {
console.log('d');
index = idx;
return index.read(1);
})
.then(function() {
console.log('e');
return index.addByPath(fileName);
})
.then(function() {
console.log('f');
return index.write();
})
.then(function() {
console.log('g');
return index.writeTree();
})
.then(function(oid) {
console.log('j');
var author = nodegit.Signature.create("Scott Chacon", "schacon@gmail.com", 123456789, 60);
var committer = nodegit.Signature.create("Scott A Chacon", "scott@github.com", 987654321, 90);

// Since we're creating an inital commit, it has no parents. Note that unlike
// normal we don't get the head either, because there isn't one yet.
return repository.createCommit('HEAD', author, committer, 'message', oid, []);
})
.done(function(commitId) {
console.log('New Commit: ', commitId);
});
3 changes: 3 additions & 0 deletions generate/descriptor.json
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 @@ -34,6 +34,9 @@
}
}
},
"repository_init_flag": {
"removeString": "INIT_"
},
"otype": {
"JsName": "TYPE",
"owner": "Object",
Expand Down

Back | FazBrowse Home | New Git URL