Skip to content

Commit f7079f6

Browse files
committed
rebase
1 parent bdcfd01 commit f7079f6

7 files changed

+135
-53
lines changed

README.md

+24-3
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,27 @@ Now `cd` to a directory in which you have some bare git repos and run this serve
3939
> cd __fixtures__
4040
> ls
4141
test-repo1.git test-repo2.git imaginatively-named-repo.git
42-
> git-http-mock-server &
43-
> git-ssh-mock-server &
42+
> git-http-mock-server
4443
```
4544

4645
Now in another shell, clone and push away...
4746
```sh
4847
> git clone http://localhost:8174/test-repo1.git
4948
> git clone http://localhost:8174/test-repo2.git
5049
> git clone http://localhost:8174/imaginatively-named-repo.git
50+
```
51+
52+
To do the same thing but with SSH
53+
54+
```sh
55+
> cd __fixtures__
56+
> ls
57+
test-repo1.git test-repo2.git imaginatively-named-repo.git
58+
> git-ssh-mock-server
59+
```
60+
61+
Now in another shell,
62+
```sh
5163
> git clone ssh://localhost:2222/imaginatively-named-repo.git
5264
```
5365

@@ -65,6 +77,14 @@ you can run the server as a daemon in the background:
6577
Just be sure to run `start` and `stop` from the same working directory.
6678
(The `start` command writes the PID of the server to `./git-http-mock-server.pid` so that the `stop` command knows what process to kill.)
6779

80+
Same thing for SSH:
81+
82+
```sh
83+
> git-ssh-mock-server start
84+
> # do stuff
85+
> git-ssh-mock-server stop
86+
```
87+
6888
### Environment Variables
6989

7090
- `GIT_HTTP_MOCK_SERVER_PORT` default is 8174 (to be compatible with [git-http-server](https://github.com/bahamas10/node-git-http-server))
@@ -123,9 +143,10 @@ originally inspired by '[git-http-server](https://github.com/bahamas10/node-git-
123143

124144
MIT
125145

126-
127146
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fisomorphic-git%2Fgit-http-mock-server.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fisomorphic-git%2Fgit-http-mock-server?ref=badge_large)
128147

129148
## Changelog
130149

150+
1.2.0 - add SSH server
151+
1.1.0 - support running in background and CORS headers
131152
1.0.0 - Initial release

daemon.js

+46-46
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,57 @@ const {spawn} = require('child_process')
55
const kill = require('tree-kill')
66
const minimisted = require('minimisted')
77

8-
const cmdName = 'git-http-mock-server'
9-
const target = require.resolve('./bin.js')
10-
const args = [
11-
target
12-
]
8+
module.exports = function (cmdName, target) {
9+
const args = [
10+
target
11+
]
1312

14-
async function main({_: [cmd]}) {
15-
switch (cmd) {
16-
case 'start': {
17-
require('daemonize-process')()
18-
let server = spawn(
19-
'node', args,
20-
{
21-
stdio: 'inherit',
22-
windowsHide: true,
23-
}
24-
)
25-
fs.writeFileSync(
26-
path.join(process.cwd(), `${cmdName}.pid`),
27-
String(process.pid),
28-
'utf8'
29-
)
30-
process.on('exit', server.kill)
31-
return
32-
}
33-
case 'stop': {
34-
let pid
35-
try {
36-
pid = fs.readFileSync(
13+
async function main({_: [cmd]}) {
14+
switch (cmd) {
15+
case 'start': {
16+
require('daemonize-process')()
17+
let server = spawn(
18+
'node', args,
19+
{
20+
stdio: 'inherit',
21+
windowsHide: true,
22+
}
23+
)
24+
fs.writeFileSync(
3725
path.join(process.cwd(), `${cmdName}.pid`),
26+
String(process.pid),
3827
'utf8'
39-
);
40-
} catch (err) {
41-
console.log(`No ${cmdName}.pid file`)
28+
)
29+
process.on('exit', server.kill)
4230
return
4331
}
44-
pid = parseInt(pid)
45-
console.log('killing', pid)
46-
kill(pid, (err) => {
47-
if (err) {
48-
console.log(err)
49-
} else {
50-
fs.unlinkSync(path.join(process.cwd(), `${cmdName}.pid`))
32+
case 'stop': {
33+
let pid
34+
try {
35+
pid = fs.readFileSync(
36+
path.join(process.cwd(), `${cmdName}.pid`),
37+
'utf8'
38+
);
39+
} catch (err) {
40+
console.log(`No ${cmdName}.pid file`)
41+
return
5142
}
52-
})
53-
return
54-
}
55-
default: {
56-
require(target)
43+
pid = parseInt(pid)
44+
console.log('killing', pid)
45+
kill(pid, (err) => {
46+
if (err) {
47+
console.log(err)
48+
} else {
49+
fs.unlinkSync(path.join(process.cwd(), `${cmdName}.pid`))
50+
}
51+
})
52+
return
53+
}
54+
default: {
55+
require(target)
56+
}
5757
}
5858
}
59-
}
60-
61-
minimisted(main)
59+
60+
minimisted(main)
61+
}

http-daemon.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
const cmdName = 'git-http-mock-server'
3+
const target = require.resolve('./http-server.js')
4+
require('./daemon.js')(cmdName, target)

bin.js renamed to http-server.js

File renamed without changes.

package-lock.json

+55-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "Clone and push to git repository test fixtures over HTTP.",
55
"main": "index.js",
66
"bin": {
7-
"git-http-mock-server": "daemon.js",
8-
"git-ssh-mock-server": "ssh-server.js"
7+
"git-http-mock-server": "http-daemon.js",
8+
"git-ssh-mock-server": "ssh-daemon.js"
99
},
1010
"scripts": {
1111
"test": "echo \"No tests\"",

ssh-daemon.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
const cmdName = 'git-ssh-mock-server'
3+
const target = require.resolve('./ssh-server.js')
4+
require('./daemon.js')(cmdName, target)

0 commit comments

Comments
 (0)