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

[WIP] Push example by johnhaley81 · Pull Request #288 · 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 .cc  (1) .h  (1) .js  (3) .json  (2) All 4 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
77 changes: 77 additions & 0 deletions example/push.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,77 @@
var nodegit = require('../');
var path = require('path');
var Promise = require('nodegit-promise');
var promisify = require('promisify-node');
var fse = promisify(require('fs-extra'));
fse.ensureDir = promisify(fse.ensureDir);

var fileName = 'newFile.txt';
var fileContent = 'hello world';

var repoDir = '../../newRepo';

var repository;

var signature = nodegit.Signature.create("Foo bar", "foo@bar.com", 123456789, 60);

// Create a new repository in a clean directory, and add our first file
fse.remove(path.resolve(__dirname, repoDir))
.then(function() {
return fse.ensureDir(path.resolve(__dirname, repoDir));
})
.then(function() {
return nodegit.Repository.init(path.resolve(__dirname, repoDir), 0);
})
.then(function(repo) {
repository = repo;
return fse.writeFile(path.join(repository.workdir(), fileName), fileContent);
})

// Load up the repository index and make our initial commit to HEAD
.then(function() {
return repository.openIndex();
})
.then(function(index) {
index.read(1);
index.addByPath(fileName);
index.write()

return index.writeTree();
})
.then(function(oid) {
return repository.createCommit('HEAD', signature, signature, 'initial commit', oid, []);
})

// Add a new remote
.then(function() {
return nodegit.Remote.create(repository, "origin", "git@github.com:nodegit/push-example.git")
.then(function(remote) {
remote.connect(nodegit.Enums.DIRECTION.PUSH);

var push;

// We need to set the auth on the remote, not the push object
remote.setCallbacks({
credentials: function(url, userName) {
return nodegit.Cred.sshKeyFromAgent(userName);
}
});

// Create the push object for this remote
return nodegit.Push.create(remote)
.then(function(pushResult) {
push = pushResult;

// This just says what branch we're pushing onto what branch in the remote
return push.addRefspec("refs/heads/master:refs/heads/master");
}).then(function() {
// This is the call that performs the actual push
return push.finish();
}).then(function() {
// Check to see if the remote accepted our push request.
return push.unpackOk();
});
});
}).done(function() {
console.log("Done!");
})
10 changes: 5 additions & 5 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 @@ -946,8 +946,11 @@
"push": {
"cType": "git_push",
"functions": {
"git_push_new": {
"ignore": true
"git_push_finish": {
"isAsync": true,
"return": {
"isErrorCode": true
}
},
"git_push_set_callbacks": {
"ignore": true
Expand Down Expand Up @@ -1054,9 +1057,6 @@
"git_remote_default_branch": {
"ignore": true
},
"git_remote_get_callbacks": {
"ignore": true
},
"git_remote_get_fetch_refspecs": {
"ignore": true
},
Expand Down
17 changes: 16 additions & 1 deletion generate/libgit2-supplement.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 @@ -115,7 +115,22 @@
[
"git_direction",
{
"type": "enum"
"type": "enum",
"description": "Enum to indicate the direction that a remote connection is going to go",
"fields": [
{
"type": "int",
"name": "GIT_DIRECTION_FETCH",
"comments": "Fetching from the remote repository",
"value": 0
},
{
"type": "int",
"name": "GIT_DIRECTION_PUSH",
"comments": "Pushing to a remote repository",
"value": 1
}
]
}
],
[
Expand Down
2 changes: 1 addition & 1 deletion generate/templates/struct_content.cc
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 @@ -110,7 +110,7 @@ NAN_METHOD({{ cppClassName }}::New) {
NanReturnValue(args.This());
}

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

Handle<Value> argv[2] = { NanNew<External>((void *)raw), NanNew<Boolean>(selfFreeing) };
Expand Down
2 changes: 1 addition & 1 deletion generate/templates/struct_header.h
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 @@ -27,7 +27,7 @@ class {{ cppClassName }} : public ObjectWrap {
{{ cType }} *GetValue();
{{ cType }} **GetRefValue();

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

bool selfFreeing;

Expand Down
8 changes: 8 additions & 0 deletions lib/remote.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
@@ -1,5 +1,13 @@
var NodeGit = require("../");
var normalizeOptions = require("./util/normalize_options");

var Remote = NodeGit.Remote;
var setCallbacks = Remote.prototype.setCallbacks;

Remote.prototype.setCallbacks = function(callbacks) {
callbacks = normalizeOptions(callbacks, NodeGit.RemoteCallbacks);

return setCallbacks.call(this, callbacks);
};

module.exports = Remote;
3 changes: 2 additions & 1 deletion test/tests/remote.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 @@ -4,6 +4,7 @@ var path = require("path");
describe("Remote", function() {
var reposPath = path.resolve("test/repos/workdir/.git");

var NodeGit = require("../../");
var Repository = require("../../lib/repository");
var Remote = require("../../lib/remote");

Expand Down Expand Up @@ -92,7 +93,7 @@ describe("Remote", function() {

return Remote.load(repo, "origin")
.then(function(remote) {
remote.connect(0);
remote.connect(NodeGit.Enums.DIRECTION.FETCH);
return remote.download();
})
.then(function() {
Expand Down

Back | FazBrowse Home | New Git URL