Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch doesn't seem to work with https urls. #322

Closed
Athaphian opened this issue Dec 8, 2014 · 15 comments
Closed

Fetch doesn't seem to work with https urls. #322

Athaphian opened this issue Dec 8, 2014 · 15 comments

Comments

@Athaphian
Copy link

I have cloned a github repo using https. Running the fetch example gives me:

/..../node_modules/nodegit-promise/node_modules/asap/asap.js:45
throw e;
^
Error: The SSL certificate is invalid

Which is probably a correct message, since I never created any SSL certificate. I will try this example using SSH, but I would like HTTPS to work aswel.

@johnhaley81
Copy link
Collaborator

There seems to be an issue with GitHub's cert being falsely flagged as invalid on OSX. You can bypass the check during clone like this:

var url = "https://github.com/nodegit/test.git";
var opts = { ignoreCertErrors: 1 };

return Clone.clone(url, https, opts).then(function(repository) {
  assert.ok(repository instanceof Repository);
});

An unauthorized should return a different error.

If that doesn't work for you feel free to re-open this issue.

@Athaphian
Copy link
Author

Not really sure how to reopen an issue on github, but I have used the example 'clone.js' which uses the ignoreCertErrors flag. The error happens when I run the fetch example on the same repo.

@johnhaley81
Copy link
Collaborator

The button next to "Comment" should be "Reopen Issue" or "Reopen and comment".

Ah! So this is only during fetch and clone is fine. Ok so fetch needs the same flag but it's set differently inside of libgit2. Luckily it's pretty easy with the convenience function:

var nodegit = require('nodegit');

nodegit.Repository.open("path/to/repo/.git").then(function(repo) {
  return repo.fetch("origin", {
    credentials: function(url, userName) {
      return nodegit.Cred.sshKeyFromAgent(userName);
    },
    true /* ignoreCertErrors */
  });
});

@johnhaley81
Copy link
Collaborator

One more note. This flag is set on the remote object and will persist on that object. If you make a new remote you'll have to reset that flag.

@Athaphian
Copy link
Author

I don't think that is correct, since that code example does not compile..

@maxkorp maxkorp reopened this Dec 8, 2014
@maxkorp
Copy link
Collaborator

maxkorp commented Dec 8, 2014

Reopened this for you, Athaphian. FYI, the reopen button is usually under the text input, next to "comment".

@Athaphian
Copy link
Author

Thanx maxkorp, the button was not there. Now there is a button 'Close and comment'.

@maxkorp
Copy link
Collaborator

maxkorp commented Dec 8, 2014

Interesting. I'll take a look through the repo permissions... Thanks for the heads up.

@Athaphian
Copy link
Author

I extracted all the relevant code from my project to make a working example, using one of my public repo's here on github:

var nodegit = require('nodegit'),
    path = require('path');

var tmp = new Date().getTime(),
    clonePath = path.resolve(__dirname, './clones/' + tmp),
    gitPath = path.resolve(__dirname, './clones/' + tmp + '/.git');

var performFetch = function () {

  nodegit.Repository

    // Open the specified directory
      .open(gitPath).then(function (repo) {

        return repo.fetch("origin", {
          credentials: function (url, userName) {
            return nodegit.Cred.sshKeyFromAgent(userName);
          }
        });

      })

      .done(function () {
        console.log('Done fetching.');
      });
};

nodegit.Clone.clone('https://github.com/Athaphian/grunt-websocket.git', clonePath,
    {ignoreCertErrors: 1})
    .done(function () {
      console.log('Done cloning.');
      performFetch();
    });

This code results in:

Done cloning.

/.../node_modules/nodegit-promise/node_modules/asap/asap.js:45
throw e;
^
Error: The SSL certificate is invalid

@johnhaley81
Copy link
Collaborator

var nodegit = require('nodegit');

nodegit.Repository.open("path/to/repo/.git").then(function(repo) {
  return repo.fetch("origin", {
    credentials: function(url, userName) {
      return nodegit.Cred.sshKeyFromAgent(userName);
    }
  },
  true /* ignoreCertErrors */);
});

I miss aligned my brackets. I just ran that locally. In your code you'll just pass that same argument.

@Athaphian
Copy link
Author

Ok that didn't give me an error, I will now check to see if the fetch really works..

@johnhaley81
Copy link
Collaborator

TIL if a repo owner closes an issue then the issue creator can't reopen it.

http://stackoverflow.com/questions/21333654/how-to-re-open-an-issue-in-github

@Athaphian
Copy link
Author

Good to know.

With that 'true' in the correct place, it all works now. Thanks :)

@johnhaley81
Copy link
Collaborator

Great! Glad to hear it :)

tuvokki added a commit to tuvokki/gitcontrol that referenced this issue May 17, 2015
@tjcarroll11
Copy link

Also want to note that I randomly ran into this error on a CentOS machine and found that setting

certificateCheck: function() {
      return 1;
}

on the remote connection options cured it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants