GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — connect and push · Issue #1035 · nodegit/nodegit

connect and push  #1035

New issue
Copy link
New issue
Copy link
Open
Open
connect and push #1035
Copy link

Description

@feifeipan
feifeipan
opened on May 17, 2016
Issue body actions

I need to modify a file and push. Here is my code.
But it can't push, because it continually print "url" and "username". Please help me,thanks.

// PUSH
.then(function() {
    return repo.getRemote("origin");
}).then(function(remoteResult) {

  console.log('remote Loaded');
  remote = remoteResult;

  // remote.setCallbacks({
  //     credentials: function(url, userName) {
  //         return nodegit.Cred.sshKeyFromAgent(userName);
  //     }
  // });

  console.log('remote Configured');
  return remote.connect(nodegit.Enums.DIRECTION.PUSH,{
      credentials: function(url, userName) {
        console.log(url);
        console.log(userName);
        return nodegit.Cred.sshKeyFromAgent(userName);
      }
  });
}).then(function() {
  console.log('remote Connected?', remote.connected())

  return remote.push(
            ["refs/heads/master:refs/heads/master"],
            null,
            repo.defaultSignature(),
            "Push to master")
}).then(function() {
    console.log('remote Pushed!')
})
.catch(function(reason) {
    console.log(reason);
})
Reacted by Zak Henry, Connor Ross and Alex Patterson

Activity

  1. zakhenry commented on Jun 2, 2016

    @zakhenry
    zakhenry
    on Jun 2, 2016
    More actions

    Same issue. My config:

          const dir = path.resolve(this.basePath, config.dir);
          const pkg = require(this.basePath + '/package.json');
    
          let index, repository;
    
          this.log(`Initializing repo at ${dir}`);
          git.Repository.init(dir, 0)
            .then((repo) => {
              repository = repo;
              this.log(`refreshing index`);
              return repo.refreshIndex();
            })
            .then((idx) => {
              index = idx;
              this.log(`adding files`);
              return index.addAll();
            })
            .then(() => {
              this.log(`writing tree`);
              return index.writeTree();
            })
            .then((oid) => {
              this.log(`committing`);
              const author = git.Signature.create(pkg.author.name, pkg.author.email, Math.round(Date.now() / 1000), 60);
              return repository.createCommit("HEAD", author, author, "message", oid, []);
            })
            .then(() => {
              this.log(`adding remote`);
              return git.Remote.create(repository, 'origin', config.repo);
            })
            .then((remote) => {
              this.log(`pushing`);
              return remote.push([`refs/heads/master:refs/heads/${config.branch}`], {
                callbacks: {
                  certificateCheck: () => 1,
                  credentials: function(url, userName) {
                    console.log(`getting creds for url:${url} username:${userName}`);
                    return git.Cred.sshKeyFromAgent(userName);
                  },
                  transferProgress: (progress) => {
                    this.log('progress: ', progress)
                  }
                }
              })
            })
            .catch((e) => {
              console.log(e);
            })
            .done(() => {
              done();
            })

    Output:

    [19:42:35] Starting 'doc:deploy'...
    [19:42:35] Initializing repo at /Users/zak/ubiquits/core/dist-docs
    [19:42:35] refreshing index
    [19:42:35] adding files
    [19:42:35] writing tree
    [19:42:35] committing
    [19:42:35] adding remote
    [19:42:35] pushing
    getting creds for url:[email protected]:ubiquits/ubiquits.github.io.git username:git
    getting creds for url:[email protected]:ubiquits/ubiquits.github.io.git username:git
    getting creds for url:[email protected]:ubiquits/ubiquits.github.io.git username:git
    getting creds for url:[email protected]:ubiquits/ubiquits.github.io.git username:git
    getting creds for url:[email protected]:ubiquits/ubiquits.github.io.git username:git
    [...etc]
    
    • MacOS 10.11.5
    • "nodegit": "^0.13.0",
    • node v6.2.0
  2. zakhenry commented on Jun 3, 2016

    @zakhenry
    zakhenry
    on Jun 3, 2016
    More actions

    Update - this issue may be isolated to mac - the same code works fine on travis ci. @feifeipan are you using a mac?

  3. johnhaley81 commented on Jun 8, 2016

    @johnhaley81
    johnhaley81
    on Jun 8, 2016
    Collaborator
    More actions

    If you're using ssh agent on OSX you have to add your ssh key to your keychain. You can do that with:

    ssh-add -K /path/of/private/key

    Otherwise you can use NodeGit.Cred.sshKeyNew passing in both the private and public keys (both are required).

    Reacted by Alex Patterson, Andrew Blaney and Marco Moschettini
  4. codercatdev commented on Dec 22, 2018

    @codercatdev
    codercatdev
    on Dec 22, 2018
    More actions

    Here is a simple example in which I can use agent, but no success using sshKeyNew.

    var nodegit = require('nodegit');
    var fse = require('fs-extra');
    var path = require('path');
    var local = path.join.bind(path, __dirname);
    
    var sshPublicKeyPath = '/Users/ajonp/.ssh/id_rsa.pub';
    var sshPrivateKeyPath = '/Users/ajonp/.ssh/id_rsa';
    
    var clonePath = local('../repos/clone');
    var debug = 0;
    
    console.log('clonepath',clonePath)
    
    fse.remove(clonePath).then(async function() {
      try {
        const repo = await nodegit.Clone(
          '[email protected]:AJONPLLC/lesson-8-hugo.git',
          clonePath,
          {
            fetchOpts: {
              callbacks: {
                certificateCheck: () => {
                  // github will fail cert check on some OSX machines
                  // this overrides that check
                  return 1;
                },
                credentials: (url, userName) => {
                    console.log(sshPublicKeyPath)
                    console.log(sshPrivateKeyPath)
                    // avoid infinite loop when authentication agent is not loaded
                    if (debug++ > 10){
                        console.log('Failed too often, bailing.')
                        throw "Authentication agent not loaded.";
                    }
                  return nodegit.Cred.sshKeyNew(
                    userName,
                    sshPublicKeyPath,
                    sshPrivateKeyPath,
                    ''
                  );
                // return nodegit.Cred.sshKeyFromAgent(userName);
                }
              }
            }
          }
        );
      } catch (err) {
        console.log(err);
      }
    });
    
  5. codercatdev commented on Dec 25, 2018

    @codercatdev
    codercatdev
    on Dec 25, 2018
    More actions

    SSH works fine testing direct to github.

    { [Error: Failed to authenticate SSH session: Invalid public key data] errno: -1, errorFunction: 'Remote.push' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.