Files: 378b71dc16d7ede4e69a83b6615b8811276606c3 / test / git-remote-test.js
1731 bytesRaw
1 | |
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 | ) |
75 |
Built with git-ssb-web