| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b1c191e commit b099d66
5 files changed
| Original file line number | Diff line number | Diff 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 | + }) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -946,6 +946,12 @@ | |||
| 946 | 946 | "push": { | |
| 947 | 947 | "cType": "git_push", | |
| 948 | 948 | "functions": { | |
| 949 | + "git_push_finish": { | ||
| 950 | + "isAsync": true, | ||
| 951 | + "return": { | ||
| 952 | + "isErrorCode": true | ||
| 953 | + } | ||
| 954 | + }, | ||
| 949 | 955 | "git_push_set_callbacks": { | |
| 950 | 956 | "ignore": true | |
| 951 | 957 | }, | |
@@ -1051,9 +1057,6 @@ | |||
| 1051 | 1057 | "git_remote_default_branch": { | |
| 1052 | 1058 | "ignore": true | |
| 1053 | 1059 | }, | |
| 1054 | - "git_remote_get_callbacks": { | ||
| 1055 | - "ignore": true | ||
| 1056 | - }, | ||
| 1057 | 1060 | "git_remote_get_fetch_refspecs": { | |
| 1058 | 1061 | "ignore": true | |
| 1059 | 1062 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -110,7 +110,7 @@ NAN_METHOD({{ cppClassName }}::New) { | |||
| 110 | 110 | NanReturnValue(args.This()); | |
| 111 | 111 | } | |
| 112 | 112 | ||
| 113 | - Handle<Value> {{ cppClassName }}::New({{ cType }}* raw, bool selfFreeing) { | ||
| 113 | + Handle<Value> {{ cppClassName }}::New(void* raw, bool selfFreeing) { | ||
| 114 | 114 | NanEscapableScope(); | |
| 115 | 115 | ||
| 116 | 116 | Handle<Value> argv[2] = { NanNew<External>((void *)raw), NanNew<Boolean>(selfFreeing) }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,7 @@ class {{ cppClassName }} : public ObjectWrap { | |||
| 27 | 27 | {{ cType }} *GetValue(); | |
| 28 | 28 | {{ cType }} **GetRefValue(); | |
| 29 | 29 | ||
| 30 | - static Handle<Value> New({{ cType }} *raw, bool selfFreeing); | ||
| 30 | + static Handle<Value> New(void *raw, bool selfFreeing); | ||
| 31 | 31 | ||
| 32 | 32 | bool selfFreeing; | |
| 33 | 33 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,7 +92,7 @@ describe("Remote", function() { | |||
| 92 | 92 | var repo = this.repository; | |
| 93 | 93 | ||
| 94 | 94 | return Remote.load(repo, "origin") | |
| 95 | - .then(function(remote) | ||
| 95 | + .then(function(remote) { | ||
| 96 | 96 | remote.connect(NodeGit.Enums.DIRECTION.FETCH); | |
| 97 | 97 | return remote.download(); | |
| 98 | 98 | }) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments