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

Added a push example · nodegit/nodegit@b099d66 · GitHub

Repository navigation

Commit b099d66

Browse files
John Haley
committed
Added a push example
1 parent b1c191e commit b099d66

5 files changed

Lines changed: 86 additions & 6 deletions

File tree

‎example/push.js‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
var nodegit = require('../');
2+
var path = require('path');
3+
var Promise = require('nodegit-promise');
4+
var promisify = require('promisify-node');
5+
var fse = promisify(require('fs-extra'));
6+
fse.ensureDir = promisify(fse.ensureDir);
7+
8+
var fileName = 'newFile.txt';
9+
var fileContent = 'hello world';
10+
11+
var repoDir = '../../newRepo';
12+
13+
var repository;
14+
15+
var signature = nodegit.Signature.create("Foo bar", "foo@bar.com", 123456789, 60);
16+
17+
// Create a new repository in a clean directory, and add our first file
18+
fse.remove(path.resolve(__dirname, repoDir))
19+
.then(function() {
20+
return fse.ensureDir(path.resolve(__dirname, repoDir));
21+
})
22+
.then(function() {
23+
return nodegit.Repository.init(path.resolve(__dirname, repoDir), 0);
24+
})
25+
.then(function(repo) {
26+
repository = repo;
27+
return fse.writeFile(path.join(repository.workdir(), fileName), fileContent);
28+
})
29+
30+
// Load up the repository index and make our initial commit to HEAD
31+
.then(function() {
32+
return repository.openIndex();
33+
})
34+
.then(function(index) {
35+
index.read(1);
36+
index.addByPath(fileName);
37+
index.write()
38+
39+
return index.writeTree();
40+
})
41+
.then(function(oid) {
42+
return repository.createCommit('HEAD', signature, signature, 'initial commit', oid, []);
43+
})
44+
45+
// Add a new remote
46+
.then(function() {
47+
return nodegit.Remote.create(repository, "origin", "git@github.com:nodegit/push-example.git")
48+
.then(function(remote) {
49+
remote.connect(nodegit.Enums.DIRECTION.PUSH);
50+
51+
var push;
52+
53+
// We need to set the auth on the remote, not the push object
54+
remote.setCallbacks({
55+
credentials: function(url, userName) {
56+
return nodegit.Cred.sshKeyFromAgent(userName);
57+
}
58+
});
59+
60+
// Create the push object for this remote
61+
return nodegit.Push.create(remote)
62+
.then(function(pushResult) {
63+
push = pushResult;
64+
65+
// This just says what branch we're pushing onto what branch in the remote
66+
return push.addRefspec("refs/heads/master:refs/heads/master");
67+
}).then(function() {
68+
// This is the call that performs the actual push
69+
return push.finish();
70+
}).then(function() {
71+
// Check to see if the remote accepted our push request.
72+
return push.unpackOk();
73+
});
74+
});
75+
}).done(function() {
76+
console.log("Done!");
77+
})

‎generate/descriptor.json‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,12 @@
946946
"push": {
947947
"cType": "git_push",
948948
"functions": {
949+
"git_push_finish": {
950+
"isAsync": true,
951+
"return": {
952+
"isErrorCode": true
953+
}
954+
},
949955
"git_push_set_callbacks": {
950956
"ignore": true
951957
},
@@ -1051,9 +1057,6 @@
10511057
"git_remote_default_branch": {
10521058
"ignore": true
10531059
},
1054-
"git_remote_get_callbacks": {
1055-
"ignore": true
1056-
},
10571060
"git_remote_get_fetch_refspecs": {
10581061
"ignore": true
10591062
},

‎generate/templates/struct_content.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ NAN_METHOD({{ cppClassName }}::New) {
110110
NanReturnValue(args.This());
111111
}
112112

113-
Handle<Value> {{ cppClassName }}::New({{ cType }}* raw, bool selfFreeing) {
113+
Handle<Value> {{ cppClassName }}::New(void* raw, bool selfFreeing) {
114114
NanEscapableScope();
115115

116116
Handle<Value> argv[2] = { NanNew<External>((void *)raw), NanNew<Boolean>(selfFreeing) };

‎generate/templates/struct_header.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class {{ cppClassName }} : public ObjectWrap {
2727
{{ cType }} *GetValue();
2828
{{ cType }} **GetRefValue();
2929

30-
static Handle<Value> New({{ cType }} *raw, bool selfFreeing);
30+
static Handle<Value> New(void *raw, bool selfFreeing);
3131

3232
bool selfFreeing;
3333

‎test/tests/remote.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe("Remote", function() {
9292
var repo = this.repository;
9393

9494
return Remote.load(repo, "origin")
95-
.then(function(remote)
95+
.then(function(remote) {
9696
remote.connect(NodeGit.Enums.DIRECTION.FETCH);
9797
return remote.download();
9898
})

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL