Code Monkey home page Code Monkey logo

nodejs-git-server's Introduction

NodeJS Git Server

image Build Status Coverage Status

A multi-tenant git server using NodeJS.

Read the Documented Source Code Here

Made to be able to support many git repo's and users with Read/Write customizable permissions.

Install Git Server

To install the git server run:

npm install git-server

To run tests

git clone https://github.com/qrpike/NodeJS-Git-Server.git
cd ./NodeJS-Git-Server
make test

Example Usage

The GitServer is a very easy to get up and running git server. It uses the Pushover and git-emit modules for listening to git events, and its own layer to do the security for each repo & user.

	var GitServer = require('git-server');
	var newUser = {
		username:'demo',
		password:'demo'
	}
	var newRepo = {
		name:'myrepo',
		anonRead:false,
		users: [
			{ user:newUser, permissions:['R','W'] }
		]
	}
	server = new GitServer({repos: [ newRepo ]});

Events:

Server object emits these events:

##passive events

These events are informational only. They can not be aborted.

  • post-applypatch
  • post-commit
  • post-checkout
  • post-merge
  • post-receive
  • post-update
  • post-rewrite

##abortable events

These events can be aborted or accepted. If there will be no listeners for any of these events, they will be automatically accepted. If object can be aborted, it will have canAbort property in update argument.

  • fetch
  • commit
  • applypatch-msg
  • pre-applypatch
  • pre-commit
  • prepare-commit-msg
  • commit-msg
  • pre-rebase
  • pre-receive
  • update
  • pre-auto-gc
	var GitServer = require('git-server');
	var newUser = {
		username:'demo',
		password:'demo'
	}
	var newRepo = {
		name:'myrepo',
		anonRead:false,
		users: [
			{ user:newUser, permissions:['R','W'] }
		]
	}
	server = new GitServer({repos: [ newRepo ]});
	server.on('commit', function(update, repo) {
		// do some logging or other stuff
		update.accept() //accept the update.
	});
	server.on('post-update', function(update, repo) {
		//do some deploy stuff
	});

When we start the git server, it will default to port 7000. We can test this using git on this (or another ) machine.

	git clone http://localhost:7000/myrepo.git

Since this repo does NOT allow anonymous reading, it will prompt us for a user/pass

To make this faster, we can use the basic auth structure:

git clone http://demo:demo@localhost:7000/myrepo.git

This should not prompt you for any user/pass. Also in the future when you push changes, or pull, it will not ask you for this info again.

Repo object

Repo object is the object passed to start the server plus some additional methods and properties.

{
  name: 'stackdot',
  anonRead: false,
  users: [ { user: {username: "demo", password: "demo"}, permissions: ["R", "W"] } ],
  path: '/tmp/repos/stackdot.git',
  last_commit: {
  	status: 'pending',
  	repo: 'anon.git',
  	service: 'receive-pack',
  	cwd: '/tmp/repos/stackdot.git',
  	last: '00960000000000000000000000000000000000000000',
  	commit: '67359bb4a6cddd97b59507413542e0b08ef078b0',
  	evName: 'push',
  	branch: 'master'
  }
}

Update object

update is an http duplex object (see below) with these extra properties:

{
  cwd: '/tmp/repos/stackdot.git', // Current repo dir
  repo: 'stackdot.git', // Repo name
  accept: [Function], // Method to accept request (if aplicable)
  reject: [Function], // Method to reject request (if aplicable)
  exists: true, // Does the repo exist
  name: 'fetch', // Event name
  canAbort: true // If event can be abbortable
}

HTTPS

The ability to use HTTPS is now implemented for the module and the cli. This is important so that your username & password is encrypted when being sent over the wire. If you are not using username/password then you may want to disregard this section.

To enable HTTPS in the module, use the 'cert' param:

	var fs = require('fs');
	var certs = {
		key		: fs.readFileSync('../certs/privatekey.pem')
		cert	: fs.readFileSync('../certs/certificate.pem')
	};
	_g = new GitServer({repos: [ newRepo ]}, undefined, undefined, undefined, certs);

To enable HTTPS in the cli, use the '--ssl' option along with '--key' and '--cert' options:

git-server[|gitserver] --ssl --key ../certs/privatekey.pem --cert ../certs/certificate.pem

To create these certs you can run:

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

Also, be aware that when using HTTPS for the git server, when you try to clone,etc. It will give you an SSL error because git (which uses CURL) cannot verify the SSL Cert. To correct this, install a actual, verified SSL Cert ( Free ones here: StartCom )

If you want to keep using the self signed cert like we created above ^ just tell git to not verify the cert. ( Other ways to do it here )

export GIT_SSL_NO_VERIFY=true

And you are good to go!

CLI Usage

When you install this package globally using

	sudo npm install -g git-server

You will now have a CLI interface you can run and interact with.

Get started by typing git-server or gitserver into your terminal.

You should see something similar to this: image

With this interface you can type the following to see the available commands:

git-server> help

You will see a list of possible commands, just enter a command and the prompt will ask you for any additional details needed.

TODO Items

  • Make YouTube demo of the app

This is a work in progress - please feel free to contribute!

please contribute #License

(The MIT License)

Copyright (c) 2016 Quinton Pike

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

nodejs-git-server's People

Contributors

gabrielcsapo avatar jhowarth15 avatar jutaz avatar kingcody avatar qrpike avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nodejs-git-server's Issues

Git push really slow

Hi, thank you very much for posting this project online. It looks immensely helpful.

When i try to make a git push origin master It takes up about 1 hour on upload 5mb...
I don't know why is so slow...

I hope you can help me.

Thank you.

Running on Windows with cygwin/msysgit

Hi,

I've been running this module on my dev machine (mac OS) without an issue. But when trying to run it on my windows production machine, I'm running in to problems.

Basically, I've tried this with msysgit (1.9.4) and cygwin (1.8.1.2). With cygwin, I've set the path env variable to the cygwin bin dir, so all necessary executables were available. With msysgit, I've set env paths to msysgit/bin and msysgit/libexec/git-core dirs. The results were always the same.

Also, I've tried versions 0.2.1 and 0.2.0 of this module, with the same results.

Git pull is not an issue, this works great. But as soon as i push, I'm getting this (using longjohn for extended stack trace):

Server:

LOG:  Got a PUSH call for myrepo.git
LOG:  demo is trying to push on repo: myrepo ...
LOG:  demo Successfully did a push on myrepo

D:\node\AppHost2\node_modules\longjohn\dist\long
        throw e;
              ^
Error: read ECONNRESET
    at errnoException (net.js:904:11)
    at onread (net.js:558:19)

    at fireErrorCallbacks (net.js:439:15)
    at Socket._destroy (net.js:475:3)
    at onread (net.js:558:10)

Client:

Pushing to http://demo:[email protected]:7000/myrepo.git
POST git-receive-pack (658 bytes)
error: RPC failed; result=56, HTTP code = 0
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
Everything up-to-date

I've no clue what to try now. Have you successfully run this module on a windows environment? Do you have any idea?

Hosting bare git repos on a separate server?

Hello, thank you so much for the amazing repo.

I understand that in your implementation, you use git-upload-pack and git-receive-pack processes to allow the client and server to talk to each other (figure out what packets the other needs, etc.)
To my knowledge, this git command accepts a local directory, but what if I host all my bare git repositories on a separate server, like an AWS S3 bucket? Could I stream a remote bare repo to these git commands, that then stream the necessary packets to the client?
I don't want to host all my bare git repos on my heroku instance, since the storage is ephemeral and limited. Any guidance would be appreciated!

issues with async 2.0

filter, reject, some, every, and related functions now expect an error as the first callback argument, rather than just a simple boolean. Pass null as the first argument, or use fs.access instead of fs.exists. (#118, #774, #1028, #1041)

causes

/root/node-distribute/node_modules/git-server/host.js:269
          if (results.length > 0) {
                     ^
TypeError: Cannot read property 'length' of null

throw erro when push

events.js:85
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at exports._errnoException (util.js:746:11)
at TCP.onread (net.js:559:26)

platform:window 2012 node -v 0.12.6

About ReadMe

hay, Give some Readme for better starting.......

Future?

hello, i see this is a very good project, can i know the future enchantment? maybe i could help. i mean like http based API to add users and list etc.

Custom authentication handling

Is it possible to handle authentication manually using this library?

I need to be able to authenticate users with a password hash or key.

How can I do to create a git system ?

Hi, thank you for the lib, but I have a question.

I have got the project and run the example.js by nodejs.

And then what I should do ? I don't know in where to create the repo, I tried to create a dir: NodeJS-Git-Server/tmp/repos/stackdot and use the 'git init' to create .git

Then, I'm clone http://localhost:7000/stackdot.git, The vaily of name and pass is ok. When I add->commit->push file, the server log can print in console.

But,the dir NodeJS-Git-Server/tmp/repos/stackdot has none.

So, I hope know what should I do to build a git system...

Excuse me, I'm a new comer, the technology and english is bad...

Thank you very much !

TypeError: Cannot read property 'length' of null

I used the example but something is wrong.
Can't figure what...

/home/git-server# node index

/home/git-server/node_modules/git-server/host.js:265
          if (results.length > 0) {
                     ^
TypeError: Cannot read property 'length' of null
    at /home/git-server/node_modules/git-server/host.js:265:22
    at /home/git-server/node_modules/git-server/node_modules/async/dist/async.js                                                :3327:9
    at /home/git-server/node_modules/git-server/node_modules/async/dist/async.js                                                :421:16
    at iteratorCallback (/home/git-server/node_modules/git-server/node_modules/a                                                sync/dist/async.js:998:13)
    at /home/git-server/node_modules/git-server/node_modules/async/dist/async.js                                                :906:16
    at /home/git-server/node_modules/git-server/node_modules/async/dist/async.js                                                :3319:13
    at /home/git-server/node_modules/git-server/node_modules/async/dist/async.js                                                :4256:13
    at Object.cb [as oncomplete] (fs.js:169:19)

This happens with node v0.1 to v6. v8 gives me this bug: #41

Any ideas?

TypeError: Cannot read property 'prototype' of undefined

Any ideas why I'm getting this error when trying to start the server (npm start) with the following snippet of code?

var GitServer = require('git-server');
var newUser = {
	username:'demo',
	password:'demo'
}
var newRepo = {
	name:'myrepo',
	anonRead:false,
	users: [
		{ user:newUser, permissions:['R','W'] }
	]
}
_g = new GitServer([ newRepo ]);

The error

Store.prototype.__proto__ = EventEmitter.prototype;
                                         ^

TypeError: Cannot read property 'prototype' of undefined
    at Object.<anonymous> (G:\src\web\portal-development\git-wiki\git-wiki-server\git-wiki-server\node_modules\socket.io\lib\store.js:35:42)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (G:\src\web\portal-development\git-wiki\git-wiki-server\git-wiki-server\node_modules\socket.io\lib\manager.js:14:13)
    at Module._compile (module.js:660:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

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

npm install error

This command

npm install git-server

Throws this error

npm ERR! code E404
npm ERR! 404 Not Found - GET https://github.com/substack/socket.io-client/tarball/master
npm ERR! 404 
npm ERR! 404  'socket.io-client@https://github.com/substack/socket.io-client/tarball/master' is not in this registry.
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/foo/.npm/_logs/2023-09-14T21_17_01_619Z-debug-0.log

I got error, at events.js:72

I followed instruction on web site.

I got error when I tried to use git clone http://localhost:7000/myrepo.git

the server show log as following:

events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)

I run it on windows 7

Customize page

Hi, so I'm running it and works really really well, I love this project.

However, when I access with the browser, a "not found" message appears, and I was wondering if there is any way I could use an http object to manage this requests.

Thanks!

Can we modify the returned log when a git push is performed?

Your app is just what I dream 👍

When a git push is performed, there is a classic log:

Counting objects: 356, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (133/133), done.
Writing objects: 100% (356/356), 46.20 KiB, done.
Total 356 (delta 210), reused 355 (delta 210)
....
 * [new branch]      master -> master

Can we add some lines to this log?

Thanks!

Cannot push, `fatal: The remote end hung up unexpectedly`

It seems the server claims success right away and doesn't care about any further data sent.

Git log (german):

$ git push [remote]
[...]
Username for 'http://[server]:[port]': [user]
Password for 'http://[user]@[server]:[port]': 
Zähle Objekte: 36652, Fertig.
Delta compression using up to 4 threads.
Komprimiere Objekte: 100% (12361/12361), Fertig.
Schreibe Objekte: 100% (36652/36652), 6.87 MiB | 65.00 KiB/s, Fertig.
Total 36652 (delta 23074), reused 36314 (delta 22736)
error: RPC failed; result=55, HTTP code = 0
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
Everything up-to-date

Server log:

$ node index.js 
LOG:  Making repos if they dont exist
WARNING: No SSL certs passed in. Running as HTTP and not HTTPS.
Be careful, without HTTPS your user/pass will not be encrypted
LOG:  Server listening on  [port] 
LOG:  Got a FETCH call for [repo].git
LOG:  Got a FETCH call for [repo].git
LOG:  Got a FETCH call for [repo].git
LOG:  [user] is trying to fetch on repo: [repo] ...
LOG:  [user] Successfully did a fetch on [repo]
LOG:  Got a PUSH call for [repo].git
LOG:  [user] is trying to push on repo: [repo] ...
LOG:  [user] Successfully did a push on [repo]

Adding a repo after creating server

Hello,

I'm trying to create an app where I can create repos on the fly. I"m trying the following approach:

// server.js
var repos = [ ... ]

server = new GitServer(repos);

server.createRepo({
  name:'MyNewRepo',
  anonRead:false,
  users: [
    { user:newUser, permissions:['R','W'] }
  ]
}, function(err, repo) {
    console.log(err, repo);
})

When I run node server.js I get an error message:

{ [Error: ENOENT, open '/tmp/repos/MyNewRepo.git/hooks/.git-emit.port']
  errno: -2,
  code: 'ENOENT',
  path: '/tmp/repos/MyNewRepo.git/hooks/.git-emit.port' } undefined

Am I missing something simple, or does this package not support adding repos on the fly?

Documentation?

Thank you very much for posting this project online. It looks immensely helpful, and I want to start using it ASAP.

Is there any further documentation beyond what is written, and the commented source code? For example, the docs seem to indicate that you can only create new repos and add users to them. I think this package can do much more but just not sure how to use any of the methods. For example, how do you list existing repos? Would love to learn more.

Thank you.

hello i'd like to contribute.;-)

this is an awsome project, would it be nicer with a web gui like github?

i would work on it if community like to and , if some of you want to participate it 'll be awsome!!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.