Commit 16cb3742dd9d961d752709c70a7d7e0d0139c0f8
Split test remote helper into two: empty and full
Avoids having to deal with two-way IPC/RPCCharles Lehner committed on 2/8/2016, 4:37:24 AM
Parent: 378b71dc16d7ede4e69a83b6615b8811276606c3
Files changed
index.js | changed |
test/run.js | changed |
test/git-remote-test.js | deleted |
test/git-remote-empty.js | added |
test/git-remote-full.js | added |
index.js | ||
---|---|---|
@@ -278,9 +278,9 @@ | ||
278 | 278 | var prefix = opts.prefix |
279 | 279 | var objectSink = opts.objectSink |
280 | 280 | var objectSource = opts.objectSource || pull.empty() |
281 | 281 | var refSource = opts.refSource || pull.empty() |
282 | - var refSink = opts.refSink | |
282 | + var refSink = opts.refSink || pull.drain() | |
283 | 283 | |
284 | 284 | var options = { |
285 | 285 | verbosity: 1, |
286 | 286 | progress: false |
test/run.js | ||
---|---|---|
@@ -14,9 +14,12 @@ | ||
14 | 14 | name: 'test', |
15 | 15 | email: 'test@localhost' |
16 | 16 | } |
17 | 17 | user.str = user.name + ' <' + user.email + '>' |
18 | -var remote = 'test.js://foo' | |
18 | +var remote = { | |
19 | + empty: 'empty.js://', | |
20 | + full: 'full.js://' | |
21 | +} | |
19 | 22 | |
20 | 23 | var tmpDir = mktemp.createDirSync(path.join(require('os').tmpdir(), 'XXXXXXX')) |
21 | 24 | |
22 | 25 | function handleIpcMessage(t, cb) { |
@@ -64,9 +67,9 @@ | ||
64 | 67 | }) |
65 | 68 | }) |
66 | 69 | |
67 | 70 | tape('push with empty repo', function (t) { |
68 | - t.git('push', remote, function (msg) { | |
71 | + t.git('push', remote.empty, function (msg) { | |
69 | 72 | }, function (code) { |
70 | 73 | t.equals(code, 0, 'pushed') |
71 | 74 | t.end() |
72 | 75 | }) |
@@ -131,9 +134,9 @@ | ||
131 | 134 | t.git('add', filePath, function (code) { |
132 | 135 | t.equals(code, 0, 'added file') |
133 | 136 | t.git('commit', '-m', commitMessage, function (code) { |
134 | 137 | t.equals(code, 0, 'made initial commit') |
135 | - t.git('push', '-vv', remote, 'master', function (msg) { | |
138 | + t.git('push', '-vv', remote.empty, 'master', function (msg) { | |
136 | 139 | if (msg.object) |
137 | 140 | objects(msg.object) |
138 | 141 | else if (msg.ref) |
139 | 142 | refs(msg.ref) |
@@ -146,16 +149,14 @@ | ||
146 | 149 | }) |
147 | 150 | }) |
148 | 151 | }) |
149 | 152 | |
150 | -/* | |
151 | 153 | tape('fetch', function (t) { |
152 | - t.git('fetch', '-vv', remote, function (code) { | |
154 | + t.git('fetch', '-vv', remote.full, function (code) { | |
153 | 155 | t.equals(code, 0, 'fetched') |
154 | 156 | t.end() |
155 | 157 | }) |
156 | 158 | }) |
157 | -*/ | |
158 | 159 | |
159 | 160 | tape.onFinish(function () { |
160 | 161 | if (tmpDir) |
161 | 162 | rimraf.sync(tmpDir) |
test/git-remote-test.js | ||
---|---|---|
@@ -1,74 +1,0 @@ | ||
1 | -#!/usr/bin/env node | |
2 | - | |
3 | -var toPull = require('stream-to-pull-stream') | |
4 | -var pull = require('pull-stream') | |
5 | -var util = require('../util') | |
6 | - | |
7 | -process.on('uncaughtException', function (err) { | |
8 | - if (err.stack) | |
9 | - err = {stack: err.stack, message: err.message} | |
10 | - process.send({error: err}) | |
11 | - process.exit(1) | |
12 | -}) | |
13 | - | |
14 | -var objects = {} | |
15 | -var refs = {} | |
16 | - | |
17 | -if (0) | |
18 | - refs['refs/heads/master'] = refs.HEAD = { | |
19 | - value: 'edb5b50e8019797925820007d318870f8c346726' | |
20 | - } | |
21 | - | |
22 | -function refsSource() { | |
23 | - var arr = [] | |
24 | - for (var name in refs) | |
25 | - arr.push({ | |
26 | - name: name, | |
27 | - value: refs[name].value, | |
28 | - attrs: refs[name].attrs | |
29 | - }) | |
30 | - return pull.values(arr) | |
31 | -} | |
32 | - | |
33 | -pull( | |
34 | - toPull(process.stdin), | |
35 | - require('../')({ | |
36 | - prefix: 'foo', | |
37 | - objectSink: function (readObject) { | |
38 | - readObject(null, function next(end, type, length, read) { | |
39 | - if (end === true) return | |
40 | - if (end) throw end | |
41 | - var hasher = util.createGitObjectHash(type, length) | |
42 | - pull( | |
43 | - read, | |
44 | - hasher, | |
45 | - pull.collect(function (err, bufs) { | |
46 | - if (err) throw err | |
47 | - var buf = Buffer.concat(bufs) | |
48 | - process.send({object: { | |
49 | - type: type, | |
50 | - data: buf.toString('ascii'), | |
51 | - length: length, | |
52 | - hash: hasher.digest('hex') | |
53 | - }}) | |
54 | - readObject(null, next) | |
55 | - }) | |
56 | - ) | |
57 | - }) | |
58 | - }, | |
59 | - refSink: pull.drain(function (ref) { | |
60 | - refs[ref.name] = {value: ref.new} | |
61 | - console.error('got ref', refs) | |
62 | - process.send({ref: ref}) | |
63 | - }), | |
64 | - refSource: function () { | |
65 | - console.error('sending refs', refs) | |
66 | - return refsSource() | |
67 | - } | |
68 | - }), | |
69 | - toPull(process.stdout, function (err) { | |
70 | - if (err) | |
71 | - throw err | |
72 | - process.disconnect() | |
73 | - }) | |
74 | -) |
test/git-remote-empty.js | ||
---|---|---|
@@ -1,0 +1,69 @@ | ||
1 | +#!/usr/bin/env node | |
2 | + | |
3 | +var toPull = require('stream-to-pull-stream') | |
4 | +var pull = require('pull-stream') | |
5 | +var util = require('../util') | |
6 | + | |
7 | +process.on('uncaughtException', function (err) { | |
8 | + if (err.stack) | |
9 | + err = {stack: err.stack, message: err.message} | |
10 | + process.send({error: err}) | |
11 | + process.exit(1) | |
12 | +}) | |
13 | + | |
14 | +var objects = {} | |
15 | +var refs = {} | |
16 | + | |
17 | +function refsSource() { | |
18 | + var arr = [] | |
19 | + for (var name in refs) | |
20 | + arr.push({ | |
21 | + name: name, | |
22 | + value: refs[name].value, | |
23 | + attrs: refs[name].attrs | |
24 | + }) | |
25 | + return pull.values(arr) | |
26 | +} | |
27 | + | |
28 | +pull( | |
29 | + toPull(process.stdin), | |
30 | + require('../')({ | |
31 | + prefix: 'foo', | |
32 | + objectSink: function (readObject) { | |
33 | + readObject(null, function next(end, type, length, read) { | |
34 | + if (end === true) return | |
35 | + if (end) throw end | |
36 | + var hasher = util.createGitObjectHash(type, length) | |
37 | + pull( | |
38 | + read, | |
39 | + hasher, | |
40 | + pull.collect(function (err, bufs) { | |
41 | + if (err) throw err | |
42 | + var buf = Buffer.concat(bufs) | |
43 | + process.send({object: { | |
44 | + type: type, | |
45 | + data: buf.toString('ascii'), | |
46 | + length: length, | |
47 | + hash: hasher.digest('hex') | |
48 | + }}) | |
49 | + readObject(null, next) | |
50 | + }) | |
51 | + ) | |
52 | + }) | |
53 | + }, | |
54 | + refSink: pull.drain(function (ref) { | |
55 | + refs[ref.name] = {value: ref.new} | |
56 | + console.error('got ref', refs) | |
57 | + process.send({ref: ref}) | |
58 | + }), | |
59 | + refSource: function () { | |
60 | + console.error('sending refs', refs) | |
61 | + return refsSource() | |
62 | + } | |
63 | + }), | |
64 | + toPull(process.stdout, function (err) { | |
65 | + if (err) | |
66 | + throw err | |
67 | + process.disconnect() | |
68 | + }) | |
69 | +) |
test/git-remote-full.js | ||
---|---|---|
@@ -1,0 +1,44 @@ | ||
1 | +#!/usr/bin/env node | |
2 | + | |
3 | +var toPull = require('stream-to-pull-stream') | |
4 | +var pull = require('pull-stream') | |
5 | + | |
6 | +process.on('uncaughtException', function (err) { | |
7 | + if (err.stack) | |
8 | + err = {stack: err.stack, message: err.message} | |
9 | + process.send({error: err}) | |
10 | + process.exit(1) | |
11 | +}) | |
12 | + | |
13 | +var objects = {} | |
14 | + | |
15 | +var ref = {value: 'edb5b50e8019797925820007d318870f8c346726'} | |
16 | +var refs = { | |
17 | + 'refs/heads/master': ref, | |
18 | + HEAD: ref | |
19 | +} | |
20 | + | |
21 | +function refsSource() { | |
22 | + console.error('sending refs', refs) | |
23 | + var arr = [] | |
24 | + for (var name in refs) | |
25 | + arr.push({ | |
26 | + name: name, | |
27 | + value: refs[name].value, | |
28 | + attrs: refs[name].attrs | |
29 | + }) | |
30 | + return pull.values(arr) | |
31 | +} | |
32 | + | |
33 | +pull( | |
34 | + toPull(process.stdin), | |
35 | + require('../')({ | |
36 | + prefix: 'foo', | |
37 | + refSource: refsSource | |
38 | + }), | |
39 | + toPull(process.stdout, function (err) { | |
40 | + if (err) | |
41 | + throw err | |
42 | + process.disconnect() | |
43 | + }) | |
44 | +) |
Built with git-ssb-web