Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-package.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ package-lock.json
.vs/
dist
temp
etc
etc
build-complete.meta

# Too lazy to delete it manually, sorry
test
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git-package.meta
137 changes: 75 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,27 @@ npm install node-git-server

## Simple

```javascript
const path = require('path');
const Server = require('node-git-server');

const repos = new Server(path.resolve(__dirname, 'tmp'), {
autoCreate: true,
});
const port = process.env.PORT || 7005;

repos.on('push', (push) => {
console.log(`push ${push.repo}/${push.commit} (${push.branch})`);
```typescript
import { Git } from 'node-git-server';
import { join } from 'path';

const port = !process.env.PORT || isNaN(process.env.PORT)
? 7005
: parseInt(process.env.PORT);

const repos = new Git(
join(__dirname, '../repo'),
{
autoCreate: true,
}
);

repos.on('push', push => {
console.log(`push ${push.repo}/${push.commit} ( ${push.branch} )`);
push.accept();
});

repos.on('fetch', (fetch) => {
repos.on("fetch", fetch => {
console.log(`fetch ${fetch.commit}`);
fetch.accept();
});
Expand All @@ -48,6 +54,7 @@ then start up the node-git-server server...

```
$ node example/index.js
node-git-server running at http://localhost:7005
```

meanwhile...
Expand All @@ -65,29 +72,37 @@ To http://localhost:7005/beep

## Sending logs

```javascript
const path = require('path');
const Server = require('node-git-server');

const repos = new Server(path.resolve(__dirname, 'tmp'), {
autoCreate: true,
```typescript
import { Git } from 'node-git-server';
import { join } from 'path';

const port = !process.env.PORT || isNaN(process.env.PORT)
? 7005
: parseInt(process.env.PORT);

const repos = new Git(
join(__dirname, '../repo'),
{
autoCreate: true,
}
);

repos.on('push', async push => {
console.log(`push ${push.repo}/${push.commit} ( ${push.branch} )`);

push.log();
push.log('Hey!');
push.log('Checkout these other repos:');
for (const repo of await repo.list()) {
push.log(`- ${repo}`);
}
push.log();
push.accept();
});
const port = process.env.PORT || 7005;

repos.on('push', (push) => {
console.log(`push ${push.repo}/${push.commit} (${push.branch})`);

repos.list((err, results) => {
push.log(' ');
push.log('Hey!');
push.log('Checkout these other repos:');
for (const repo of results) {
push.log(`- ${repo}`);
}
push.log(' ');
});

push.accept();
repos.on("fetch", fetch => {
console.log(`fetch ${fetch.commit}`);
fetch.accept();
});

repos.listen(port, () => {
Expand All @@ -99,6 +114,7 @@ then start up the node-git-server server...

```
$ node example/index.js
node-git-server running at http://localhost:7005
```

meanwhile...
Expand All @@ -121,38 +137,34 @@ To http://localhost:7005/test

### Authentication

```javascript
const path = require('path');
const Server = require('node-git-server');

const repos = new Server(path.normalize(path.resolve(__dirname, 'tmp')), {
autoCreate: true,
authenticate: ({ type, repo, user, headers }, next) => {
console.log(type, repo, headers); // eslint-disable-line
if (type == 'push') {
// Decide if this user is allowed to perform this action against this repo.
user((username, password) => {
if (username === '42' && password === '42') {
next();
} else {
next('wrong password');
}
});
} else {
// Check these credentials are correct for this user.
next();
}
},
});

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

repos.on('push', (push) => {
console.log(`push ${push.repo}/${push.commit} (${push.branch})`);
```typescript
import { Git } from 'node-git-server';
import { join } from 'path';

const port = !process.env.PORT || isNaN(process.env.PORT)
? 7005
: parseInt(process.env.PORT);

const repos = new Git(
join(__dirname, '../repo'),
{
autoCreate: true,
autheficate: ({ type, user }, next) =>
type == 'push'
? user(([username, password]) => {
console.log(username, password);
next();
})
: next()
}
);

repos.on('push', push => {
console.log(`push ${push.repo}/${push.commit} ( ${push.branch} )`);
push.accept();
});

repos.on('fetch', (fetch) => {
repos.on("fetch", fetch => {
console.log(`fetch ${fetch.commit}`);
fetch.accept();
});
Expand All @@ -166,6 +178,7 @@ then start up the node-git-server server...

```
$ node example/index.js
node-git-server running at http://localhost:7005
```

meanwhile...
Expand Down
2 changes: 1 addition & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ process.argv.slice(2).forEach((arg) => {
const fs = require('fs');
const path = require('path');

const Server = require('../');
const { Git : Server } = require("../");

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

Expand Down
1 change: 0 additions & 1 deletion index.js

This file was deleted.

15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"contributors": [
{
"name": "echopoint",
"email": "echopoint <echopoint@tutanota.com>"
"email": "echopoint@tutanota.com"
},
{
"name": "Buj Itself",
"email": "primary@buj-dev.site"
}
],
"license": "MIT",
Expand All @@ -18,15 +22,16 @@
"type": "git",
"url": "git+https://github.com/gabrielcsapo/node-git-server.git"
},
"main": "index.js",
"main": "dist/index.js",
"engine": {
"node": ">= 14"
},
"scripts": {
"lint": "eslint src/*",
"test": "jest",
"build": "tsc",
"coverage": "jest --coverage"
"build": "echo \"\" > ./build-complete.meta && tsc",
"coverage": "jest --coverage",
"install": "( [ -f ./git-package.meta ] && [ ! -f ./build-complete.meta ] && echo \"\" > ./build-complete.meta && npm install . && tsc ) || echo \"\" > ./build-complete.meta"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason npm does not build any package installed from git, so I added this cos it was too annoying (however I forgot to delete dist while testing, so I noticed that it doesn't work only when I committed this)

},
"dependencies": {
"through": "^2.3.8"
Expand All @@ -52,3 +57,5 @@
"./website"
]
}


2 changes: 1 addition & 1 deletion src/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ describe('git', () => {
if (type === 'fetch' && repo === 'doom') {
user((username, password) => {
if (username == 'root' && password == 'root') {
return resolve('');
return resolve(void 0);
} else {
return reject('that is not the correct password');
}
Expand Down
Loading