git ssb

0+

cel / pull-git-remote-helper



Tree: 16cb3742dd9d961d752709c70a7d7e0d0139c0f8

Files: 16cb3742dd9d961d752709c70a7d7e0d0139c0f8 / test / git-remote-empty.js

1621 bytesRaw
1#!/usr/bin/env node
2
3var toPull = require('stream-to-pull-stream')
4var pull = require('pull-stream')
5var util = require('../util')
6
7process.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
14var objects = {}
15var refs = {}
16
17function 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
28pull(
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)
70

Built with git-ssb-web