git ssb

0+

cel / pull-git-remote-helper



Commit 16cb3742dd9d961d752709c70a7d7e0d0139c0f8

Split test remote helper into two: empty and full

Avoids having to deal with two-way IPC/RPC
Charles Lehner committed on 2/8/2016, 4:37:24 AM
Parent: 378b71dc16d7ede4e69a83b6615b8811276606c3

Files changed

index.jschanged
test/run.jschanged
test/git-remote-test.jsdeleted
test/git-remote-empty.jsadded
test/git-remote-full.jsadded
index.jsView
@@ -278,9 +278,9 @@
278278 var prefix = opts.prefix
279279 var objectSink = opts.objectSink
280280 var objectSource = opts.objectSource || pull.empty()
281281 var refSource = opts.refSource || pull.empty()
282- var refSink = opts.refSink
282+ var refSink = opts.refSink || pull.drain()
283283
284284 var options = {
285285 verbosity: 1,
286286 progress: false
test/run.jsView
@@ -14,9 +14,12 @@
1414 name: 'test',
1515 email: 'test@localhost'
1616 }
1717 user.str = user.name + ' <' + user.email + '>'
18-var remote = 'test.js://foo'
18+var remote = {
19+ empty: 'empty.js://',
20+ full: 'full.js://'
21+}
1922
2023 var tmpDir = mktemp.createDirSync(path.join(require('os').tmpdir(), 'XXXXXXX'))
2124
2225 function handleIpcMessage(t, cb) {
@@ -64,9 +67,9 @@
6467 })
6568 })
6669
6770 tape('push with empty repo', function (t) {
68- t.git('push', remote, function (msg) {
71+ t.git('push', remote.empty, function (msg) {
6972 }, function (code) {
7073 t.equals(code, 0, 'pushed')
7174 t.end()
7275 })
@@ -131,9 +134,9 @@
131134 t.git('add', filePath, function (code) {
132135 t.equals(code, 0, 'added file')
133136 t.git('commit', '-m', commitMessage, function (code) {
134137 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) {
136139 if (msg.object)
137140 objects(msg.object)
138141 else if (msg.ref)
139142 refs(msg.ref)
@@ -146,16 +149,14 @@
146149 })
147150 })
148151 })
149152
150-/*
151153 tape('fetch', function (t) {
152- t.git('fetch', '-vv', remote, function (code) {
154+ t.git('fetch', '-vv', remote.full, function (code) {
153155 t.equals(code, 0, 'fetched')
154156 t.end()
155157 })
156158 })
157-*/
158159
159160 tape.onFinish(function () {
160161 if (tmpDir)
161162 rimraf.sync(tmpDir)
test/git-remote-test.jsView
@@ -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.jsView
@@ -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.jsView
@@ -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