Permalink
Browse files

fixes strider#345 and fixes #5

  • Loading branch information...
1 parent ee5631e commit cacec5eb85f419aab5d7ea1cedd919fdd1045f15 @jaredly jaredly committed Feb 2, 2014
Showing with 64 additions and 8 deletions.
  1. +2 −3 config/config.html
  2. +31 −4 lib/index.js
  3. +2 −1 package.json
  4. +29 −0 test/test_lib.js
View
@@ -3,7 +3,6 @@
<input required
type="text"
ng-model="config.url"
- ng-pattern="/git:\/\/.+?/"
placeholder="git://example.com/my/repo.git">
</label>
<div class="auth-type">
@@ -21,11 +20,11 @@
<div class="row-fluid">
<div class="span6">
<label>Private Key</label>
- <textarea ng-required="config.auth.type === 'ssh'" ng-model="config.auth.privkey"></textarea>
+ <textarea ng-model="config.auth.privkey"></textarea>
</div>
<div class="span6">
<label>Public Key</label>
- <textarea ng-required="config.auth.type === 'ssh'" ng-model="config.auth.pubkey"></textarea>
+ <textarea ng-model="config.auth.pubkey"></textarea>
</div>
</div>
</div>
View
@@ -26,15 +26,42 @@ function gitUrl(config) {
return (config.auth.type === 'ssh' ? sshUrl : httpsUrl)(config)
}
+/**
+ * TODO: validate all git urls. Currently only http(s):// and ssh are
+ * supported.
+ *
+ * List from http://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a
+ * ssh://[user@]host.xz[:port]/path/to/repo.git/
+ * git://host.xz[:port]/path/to/repo.git/
+ * http[s]://host.xz[:port]/path/to/repo.git/
+ * ftp[s]://host.xz[:port]/path/to/repo.git/
+ * rsync://host.xz/path/to/repo.git/
+ */
+
function sshUrl(config) {
- var base = config.url.split('//')[1]
- , url = shellEscape('git@' + base.replace('/', ':'))
+ var base = config.url
+ if (base.indexOf('ssh://') === 0) {
+ return [base, base]
+ }
+ if (base.indexOf('//') !== -1) {
+ base = base.split('//')[1]
+ }
+ if (base.indexOf('@') === -1) {
+ base = 'git@' + base
+ }
+ if (base.indexOf(':') === -1) {
+ base = base.replace('/', ':')
+ }
+ var url = shellEscape(base)
return [url, url]
}
function httpsUrl(config) {
- var base = config.url.split('//')[1]
- , url = 'https://' + config.auth.username + ':' + config.auth.password + '@' + base
+ var base = config.url
+ if (base.indexOf('//') !== -1) {
+ base = base.split('//')[1]
+ }
+ var url = 'https://' + config.auth.username + ':' + config.auth.password + '@' + base
, safe = 'https://[username]:[password]@' + base
return [url, safe]
}
View
@@ -35,6 +35,7 @@
},
"devDependencies": {
"jshint": "~2.3.0",
- "mocha": "~1.13.0"
+ "mocha": "~1.13.0",
+ "expect.js": "~0.2.0"
}
}
View
@@ -0,0 +1,29 @@
+
+var expect = require('expect.js')
+ , lib = require('../lib')
+
+describe('lib functions', function () {
+ describe('.sshUrl', function () {
+ it('should preserve a full scp ssh url', function () {
+ var url = 'git@git.git:git/git.git'
+ expect(lib.sshUrl({url: url})[0]).to.equal(url)
+ })
+
+ it('should sshify a git url', function () {
+ var url = 'git://one.com/two.git'
+ , ssh = 'git@one.com:two.git'
+ expect(lib.sshUrl({url: url})[0]).to.equal(ssh)
+ })
+
+ it('should preserve an ssh:// url', function () {
+ var url = 'ssh://user@host.com:20/one/two.git'
+ expect(lib.sshUrl({url: url})[0]).to.equal(url)
+ })
+
+ it('should preserve an ssh:// url with no port', function () {
+ var url = 'ssh://user@host.com/one/two.git'
+ expect(lib.sshUrl({url: url})[0]).to.equal(url)
+ })
+ })
+})
+

0 comments on commit cacec5e

Please sign in to comment.