git ssb

2+

cel / git-airpaste



Commit 18024992bfb2fc4f955daa3aeaf04a6f7dc68e01

Initial commit

cel committed on 4/29/2017, 7:14:12 AM

Files changed

README.mdadded
bin/git-airpasteadded
bin/git-remote-airpasteadded
package.jsonadded
test/index.jsadded
README.mdView
@@ -1,0 +1,19 @@
1 +# git-airpaste
2 +
3 +Use git over [airpaste](https://github.com/mafintosh/airpaste).
4 +
5 +## Usage
6 +
7 +`git airpaste [namespace]`: serve a git connection to the current git repo, over airpaste.
8 +`git <cmd> airpaste://[namespace]`: interact with a git repo being served over
9 +airpaste.
10 +
11 +## License
12 +
13 +Copyright (c) 2017 [@cel](@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519)
14 +
15 +Usage of the works is permitted provided that this instrument
16 +is retained with the works, so that any entity that uses the
17 +works is notified of this instrument.
18 +
19 +DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
bin/git-airpasteView
@@ -1,0 +1,12 @@
1 +#!/usr/bin/env node
2 +
3 +var proc = require('child_process')
4 +var airpaste = require('airpaste')
5 +
6 +var namespace = process.argv[2]
7 +var stream = airpaste(namespace)
8 +var child = proc.spawn('git', ['remote-ext', namespace, 'git %s .'], {
9 + stdio: ['pipe', 'pipe', 'inherit'],
10 +})
11 +child.stdout.pipe(stream).pipe(child.stdin)
12 +child.on('close', process.exit)
bin/git-remote-airpasteView
@@ -1,0 +1,8 @@
1 +#!/usr/bin/env node
2 +
3 +var airpaste = require('airpaste')
4 +
5 +var namespace = process.argv[3].replace(/^airpaste:\/\//, '')
6 +var stream = airpaste(namespace)
7 +
8 +process.stdin.pipe(stream).pipe(process.stdout)
package.jsonView
@@ -1,0 +1,27 @@
1 +{
2 + "name": "git-airpaste",
3 + "version": "1.0.0",
4 + "description": "git over airpaste",
5 + "dependencies": {
6 + "airpaste": "^1.0.9"
7 + },
8 + "devDependencies": {
9 + "mktemp": "^0.4.0",
10 + "rimraf": "^2.6.1",
11 + "tape": "^4.6.3"
12 + },
13 + "bin": {
14 + "git-airpaste": "bin/git-airpaste",
15 + "git-remote-airpaste": "bin/git-remote-airpaste"
16 + },
17 + "scripts": {
18 + "test": "node test"
19 + },
20 + "author": "cel",
21 + "homepage": "https://git.scuttlebot.io/%252%2F88SViRBb0olEcxvZfS8C%2BchcMz07ZWifGG9srN3kM%3D.sha256",
22 + "repository": {
23 + "type": "git",
24 + "url": "ssb://%2/88SViRBb0olEcxvZfS8C+chcMz07ZWifGG9srN3kM=.sha256"
25 + },
26 + "license": "Fair"
27 +}
test/index.jsView
@@ -1,0 +1,104 @@
1 +var path = require('path')
2 +var proc = require('child_process')
3 +var mktemp = require('mktemp')
4 +var rimraf = require('rimraf')
5 +var fs = require('fs')
6 +var tape = require('tape')
7 +
8 +var tmpDirTemplate = path.join(require('os').tmpdir(), 'XXXXXXX')
9 +var tmpDirs = []
10 +
11 +tape.onFinish(function () {
12 + tmpDirs.forEach(function (dir) {
13 + rimraf.sync(dir)
14 + })
15 +})
16 +
17 +function Git(cb) {
18 + var env = Object.create(process.env)
19 + env.PATH = path.join(__dirname, 'bin') + ':' + env.PATH
20 + var tmpDir = mktemp.createDirSync(tmpDirTemplate)
21 + tmpDirs.push(tmpDir)
22 +
23 + function git() {
24 + var args = [].slice.call(arguments)
25 + var doneCb = args.pop()
26 + return proc.spawn('git', args, {
27 + env: env,
28 + cwd: tmpDir,
29 + stdio: ['ignore', 'inherit', 'inherit']
30 + })
31 + .on('close', doneCb)
32 + }
33 +
34 + git('init', function (code) {
35 + if (code) return cb(new Error('git failed: ' + code))
36 + git('config', 'user.name', 'name', function (code) {
37 + if (code) return cb(new Error('git failed: ' + code))
38 + git('config', 'user.email', 'email', function (code) {
39 + if (code) return cb(new Error('git failed: ' + code))
40 + cb(null, git)
41 + })
42 + })
43 + })
44 +}
45 +
46 +tape('clone empty repo', function (t) {
47 + Git(function (err, git) {
48 + t.error(err, 'init')
49 +
50 + git('clone', '.', '1', function (code) {
51 + t.equals(code, 0, 'clone')
52 + t.end()
53 + })
54 + })
55 +})
56 +
57 +tape('clone empty repo with airpaste', function (t) {
58 + t.plan(3)
59 +
60 + Git(function (err, git) {
61 + t.error(err, 'init')
62 +
63 + var ns = 'test-' + Math.random()
64 +
65 + git('airpaste', ns, function (code) {
66 + t.equals(code, 0, 'served')
67 + })
68 +
69 + git('clone', 'airpaste://' + ns, '2', function (code) {
70 + t.equals(code, 0, 'cloned')
71 + })
72 + })
73 +})
74 +
75 +tape('push', function (t) {
76 + t.plan(5)
77 +
78 + Git(function (err, git1) {
79 + t.error(err, 'init1')
80 +
81 + Git(function (err, git2) {
82 + t.error(err, 'init2')
83 +
84 + var ns = 'test-' + Math.random()
85 +
86 + git2('commit', '--allow-empty', '-m', 'first', function (code) {
87 + t.equals(code, 0, 'commit')
88 +
89 + git2('push', 'airpaste://' + ns, 'master', function (code) {
90 + // this fails for some reason but still woks
91 + // t.equals(code, 0, 'push')
92 + })
93 +
94 + git1('airpaste', ns, function (code) {
95 + t.equals(code, 0, 'served')
96 +
97 + git1('log', '-1', function (code) {
98 + t.equals(code, 0, 'got the commit')
99 + })
100 + })
101 + })
102 + })
103 + })
104 +})

Built with git-ssb-web