Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Problems with push #973

Copy link
Copy link
@johnvogen

Description

@johnvogen
Issue body actions

Hello,
I am trying to implement the code snippet found in examples/push.js
I have inserted the code pretty much verbatim - only changing the source location for nodegit, the value of repodir and the url specified for the remote to coincide with my own github repository.
Running the app, the repository is created and newfile.txt is commited however I then get the following error:

TypeError: nodegit.Remote.create(...).then is not a function...

I tried using the resolution code found in Issue 463 but the scenario is somewhat different. Checking the API documentation I see that the create method on Remote is synchronous rather than asynchronous and I'm wondering if that is the issue. I have also successfully employed the example code for cloning a GitHub repository but when I try to commit and push using the code in examples/push.js it fails with the same error.
Thanks so much for your help!

This is my code:

var nodegit = require("nodegit");
var path = require("path");
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 remote;

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:johnvogen/push-example.git")
.then(function(remoteResult) {
remote = remoteResult;

// Create the push object for this remote
return remote.push(
  ["refs/heads/master:refs/heads/master"],
  {
    callbacks: {
      credentials: function(url, userName) {
        return nodegit.Cred.sshKeyFromAgent(userName);
      }
    }
  }
);

});
}).done(function() {
console.log("Done!");
});

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.