Files: 28bf61d928af584e5e33b424fc41deafa9dddb77 / lib / create.js
1748 bytesRaw
1 | var proc = require('child_process') |
2 | var u = require('./util') |
3 | var path = require('path') |
4 | |
5 | exports.help = ` |
6 | Usage: git ssb create <remote> [<name>] |
7 | |
8 | Create a new git-ssb repo and add it as a git remote |
9 | |
10 | Arguments: |
11 | remote Name of the remote to add. e.g. 'origin' or 'ssb' |
12 | name Name to give the repo, if any |
13 | |
14 | Options: |
15 | --private Make repo private |
16 | --recps <feed>,... List of recipients for a private repo. Implies --private |
17 | ` |
18 | |
19 | function hasRemote(name) { |
20 | var child = proc.spawnSync('git', ['remote']) |
21 | if (child.status !== 0) throw u.gitError(child.stderr) |
22 | var remotes = child.stdout.toString().split(/\n/) |
23 | return !!~remotes.indexOf(name) |
24 | } |
25 | |
26 | exports.fn = function (argv) { |
27 | if (argv._.length < 1 || argv._.length > 2) return u.help('create') |
28 | |
29 | module.exports.createRepo(argv, argv._[0], argv._[1]); |
30 | } |
31 | |
32 | exports.createRepo = function (config, remoteName, name, upstream) { |
33 | if (!remoteName) throw 'Missing remote name' |
34 | if (hasRemote(remoteName)) throw `Remote '${remoteName}' already exists` |
35 | |
36 | // If no name is given, use the current directory's name. |
37 | if (!name) name = path.basename(process.cwd()) |
38 | |
39 | u.getSbot(config, function (err, sbot) { |
40 | if (err) throw err |
41 | u.getRecps(sbot, config, function (err, recps) { |
42 | if (err) throw err |
43 | require('ssb-git-repo').createRepo(sbot, { |
44 | upstream: upstream, |
45 | name: name, |
46 | recps: recps, |
47 | }, function (err, repo) { |
48 | if (err) throw err |
49 | var url = 'ssb://' + repo.id |
50 | console.log('Created repo:', url, name ? '(' + name + ')' : '') |
51 | proc.spawnSync('git', ['remote', 'add', remoteName, url]) |
52 | console.log('Added remote:', remoteName) |
53 | repo.close() |
54 | sbot.close() |
55 | }) |
56 | }) |
57 | }) |
58 | } |
59 | |
60 |
Built with git-ssb-web