gabrielcsapo / node-git-server

🎡 A configurable git server written in Node.js
https://gabrielcsapo.github.io/node-git-server
MIT License
253 stars 73 forks source link

Error: spawn git-upload-pack ENOENT running command git-upload-pack #36

Closed netlander closed 6 years ago

netlander commented 6 years ago

When running a fresh install on Win 10, the commit goes well but I get the above error after trying to access the repo:

$ git clone http://localhost:7005/repo-test master
Cloning into 'master'...
fatal: unable to access 'http://localhost:7005/repo-test/': Recv failure: Connection was reset

The error coming from the server:

fetch repo-test
events.js:137
      throw er; // Unhandled 'error' event
      ^

Error: spawn git-upload-pack ENOENT running command git-upload-pack --stateless-rpc --advertise-refs G:\src\web\portal-development\demos\node-git-server-master\example\tmp\repo-test
    at ChildProcess.ps.on (G:\src\web\portal-development\demos\node-git-server-master\lib\util.js:90:29)
    at ChildProcess.emit (events.js:160:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:207:12)
    at onErrorNT (internal/child_process.js:389:16)
    at process._tickCallback (internal/process/next_tick.js:152:19)

Any pointers as to what is going wrong?

Thanks

jlxip commented 6 years ago

Could you paste the code you are running?

netlander commented 6 years ago

It's the code straight out from example/index.js found in the repo. I have created my own certificates and the created repos can be found in examples/tmp

// You Can Use The Commands Below To Generate A Self Signed Certificate For Use With This Tutorial
// These Commands Require That You have 'openssl' installed on your system
// openssl genrsa -out privatekey.pem 1024
// openssl req -new -key privatekey.pem -out certrequest.csr
// openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem

let type = 'http';

process.argv.slice(2).forEach((arg) => {
  switch(arg) {
    case 'https':
    case '--https':
      type = 'https';
    break;
  }
});

const fs = require('fs');
const path = require('path');

const Server = require('../');

const port = process.env.PORT || 7005;

const repos = new Server(path.normalize(path.resolve(__dirname, 'tmp')), {
    autoCreate: true,
    authenticate: (type, repo, user, next) => {
      console.log(type, repo); // eslint-disable-line
      if(type == 'push') {
        user((username, password) => {
          console.log(username, password); // eslint-disable-line
          next();
        });
      } else {
        next();
      }
    }
});

repos.on('push', (push) => {
    console.log(`push ${push.repo} / ${push.commit} ( ${push.branch} )`); // eslint-disable-line
    repos.list((err, result) => {
        console.log(result); // eslint-disable-line
    });
    push.accept();
});

repos.on('fetch', (fetch) => {
    console.log(`username ${fetch.username}`); // eslint-disable-line
    console.log(`fetch ${fetch.repo}/${fetch.commit}`); // eslint-disable-line
    fetch.accept();
});

repos.listen(port, {
  type,
  key: fs.readFileSync('./privatekey.pem'),
  cert: fs.readFileSync('./certificate.pem')
}, (error) => {
    if(error) return console.error(`failed to start git-server because of error ${error}`); // eslint-disable-line
    console.log(`node-git-server running at ${type}://localhost:${port}`); // eslint-disable-line
    repos.list((err, result) => {
        if (!result) {
            console.log("No repositories available..."); // eslint-disable-line
        } else {
            console.log(result); // eslint-disable-line
        }
    });
});
jlxip commented 6 years ago

Works on my machine. These are the steps I followed:

It ran without errors.

Now, in another terminal:

Everything seems to be working fine. Try it, and if it doesn't work, the problem probably has to do with your NodeJS installation.

gabrielcsapo commented 6 years ago

Thank you so much @jlxip for helping @netlander with his issue! Really thorough instructions. @netlander did these help? If so I think we could add these to the docs so that anyone else facing this issue can refer back to this for help.

netlander commented 6 years ago

@jlxip Thanks for the instructions. @gabrielcsapo Just trying these now... Will update later (probably tomorrow).

netlander commented 6 years ago

The above instructions didn't work for me. In fact I tried something similar before opening this issue but when I try to do npm i node-git-server inside the repo, I get the following error, which is the same error I got when I tried the above steps.

npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "node-git-server" under a package
npm ERR! also called "node-git-server". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR!
npm ERR! For more information, see:
npm ERR!     <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\yaseen\AppData\Roaming\npm-cache\_logs\2018-03-06T13_34_56_108Z-debug.log

@gabrielcsapo You need to amend the documentation to make it clear that users can use the given example either in a fresh node project or an existing one but outside of this repo.

Edit:

I did get this working on a new node project.

gabrielcsapo commented 6 years ago

When you install from source it is simply npm install.

@netlander so the documentation did work after installing in a npm project?