git ssb

39+

cel / git-ssb



Commit a09b2ebd1be805f4383f7b7b114a14678b39d5bb

Simplify getting repo ids

Use getRemote only, and pass it a falsy value to get the default remote
cel committed on 11/21/2016, 11:07:14 PM
Parent: a9b72303067dfe180cdc0931c8297bcfad4ad5c1

Files changed

lib/fork.jschanged
lib/forks.jschanged
lib/issues.jschanged
lib/name.jschanged
lib/pull-request.jschanged
lib/pull-requests.jschanged
lib/util.jschanged
lib/fork.jsView
@@ -3,9 +3,9 @@
33 module.exports = function (argv) {
44 if (argv.help || argv._.length < 1 || argv._.length > 2) return require('./help')('fork')
55
66 var repo
7- if (argv._.length == 1) repo = u.getDefaultRemote()
7 + if (argv._.length == 1) repo = u.getRemote()
88 else if (argv._.length == 2) repo = u.getRemote(argv._.shift())
99 if (!repo) throw 'unable to find git-ssb upstream repo'
1010 var name = argv._[0]
1111 if (!name) throw 'missing remote name'
lib/forks.jsView
@@ -26,9 +26,9 @@
2626 module.exports = function repoForks(argv) {
2727 if (argv.help || argv._.length > 1) return require('./help')('forks')
2828
2929 process.stderr.write('Loading forks...\r')
30- var id = u.repoId(u.getRemoteUrl(argv._[0])) || u.getDefaultRemote()
30 + var id = u.getRemote(argv._[0])
3131 if (!id) throw 'unable to find git-ssb repo'
3232
3333 u.getSbot(argv, function (err, sbot) {
3434 if (err) throw err
lib/issues.jsView
@@ -7,9 +7,9 @@
77 module.exports = function (argv) {
88 if (argv.help || argv._.length > 1) return require('./help')('issues')
99
1010 process.stderr.write('Loading issues...\r')
11- var id = u.repoId(u.getRemoteUrl(argv._[0])) || u.getDefaultRemote()
11 + var id = u.getRemote(argv._[0])
1212 if (!id) throw 'unable to find git-ssb repo'
1313
1414 var open = u.issueStateBool(argv)
1515
lib/name.jsView
@@ -3,9 +3,9 @@
33 module.exports = function (argv) {
44 if (argv.help || argv._.length < 1 || argv._.length > 2) return require('./help')('name')
55
66 var repo
7- if (argv._.length == 1) repo = u.getDefaultRemote()
7 + if (argv._.length == 1) repo = u.getRemote()
88 else if (argv._.length == 2) repo = u.getRemote(argv._.shift())
99 if (!repo) throw 'unable to find git-ssb repo'
1010 var name = argv._[0]
1111 if (!name) throw 'missing name'
lib/pull-request.jsView
@@ -33,9 +33,9 @@
3333 module.exports = function pullRequest(argv) {
3434 if (argv.help || argv._.length > 0) return require('./help')('pull-requests')
3535
3636 var head = splitEnd(argv.head || argv.h)
37- var headRepoId = u.getRemote(head[0] || u.getDefaultRemote())
37 + var headRepoId = u.getRemote(head[0])
3838 var headBranch = head[1] || u.getCurrentBranch()
3939 if (!headRepoId || !headBranch) throw 'unable to find head'
4040
4141 var text = argv.message || argv.m
lib/pull-requests.jsView
@@ -7,9 +7,9 @@
77 module.exports = function (argv) {
88 if (argv.help || argv._.length > 1) return require('./help')('pull-requests')
99
1010 process.stderr.write('Loading pull requests...\r')
11- var headRepo = u.repoId(u.getRemoteUrl(argv._[0])) || u.getDefaultRemote()
11 + var headRepo = u.getRemote(argv._[0])
1212 if (!headRepo) throw 'unable to find git-ssb head repo'
1313
1414 var open = u.issueStateBool(argv)
1515
lib/util.jsView
@@ -12,32 +12,29 @@
1212 var args = [].concat.apply([], arguments)
1313 return proc.spawnSync('git', args, {encoding: 'utf8'}).stdout.trim()
1414 }
1515
16-u.getRemoteUrl = function (name) {
17- if (!name) return
18- return u.gitSync('ls-remote', '--get-url', name)
19-}
20-
2116 u.getCurrentBranch = function () {
2217 return u.gitSync('symbolic-ref', '--short', 'HEAD')
2318 }
2419
25-u.getRemote = function (name) {
26- return u.repoId(name) || u.repoId(u.getRemoteUrl(name))
20 +function getRemoteUrl(name) {
21 + if (!name) return null
22 + return u.gitSync('ls-remote', '--get-url', name)
2723 }
2824
29-u.getDefaultRemote = function (name) {
30- return u.repoId(u.getRemoteUrl('origin'))
31- || u.repoId(u.getRemoteUrl('ssb'))
32-}
33-
34-u.repoId = function (id) {
35- if (!id) return
25 +function repoId(id) {
26 + if (!id) return null
3627 id = String(id).replace(/^ssb:\/*/, '')
3728 return ssbRef.isMsg(id) ? id : null
3829 }
3930
31 +u.getRemote = function (name) {
32 + return name
33 + ? repoId(name) || repoId(getRemoteUrl(name))
34 + : repoId(getRemoteUrl('origin')) || repoId(getRemoteUrl('ssb'))
35 +}
36 +
4037 u.getSbot = function (config, cb) {
4138 var keys = require('ssb-keys')
4239 .loadOrCreateSync(path.join(config.path, 'secret'))
4340 require('ssb-client')(keys, config, cb)

Built with git-ssb-web