gitable 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/.gitignore +25 -23
- data/Gemfile +20 -16
- data/LICENSE +20 -20
- data/README.rdoc +41 -20
- data/Rakefile +75 -67
- data/VERSION.yml +1 -1
- data/gitable.gemspec +7 -4
- data/lib/gitable.rb +5 -4
- data/lib/gitable/scp_uri.rb +37 -31
- data/lib/gitable/uri.rb +75 -32
- data/spec/gitable_spec.rb +427 -380
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +9 -9
- metadata +15 -6
data/lib/gitable/uri.rb
CHANGED
@@ -1,32 +1,75 @@
|
|
1
|
-
require 'addressable/uri'
|
2
|
-
|
3
|
-
module Gitable
|
4
|
-
class URI < Addressable::URI
|
5
|
-
SCP_URI_REGEXP =
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
1
|
+
require 'addressable/uri'
|
2
|
+
|
3
|
+
module Gitable
|
4
|
+
class URI < Addressable::URI
|
5
|
+
SCP_URI_REGEXP = %r|^([^:/?#]+):([^?#]*)$|
|
6
|
+
|
7
|
+
##
|
8
|
+
# Parse a git repository uri into a URI object.
|
9
|
+
#
|
10
|
+
# @param [Addressable::URI, #to_str] uri URI of a git repository.
|
11
|
+
#
|
12
|
+
# @return [Gitable::URI, nil] the URI object or nil if nil was passed in.
|
13
|
+
#
|
14
|
+
# @raise [TypeError] The uri must respond to #to_str.
|
15
|
+
# @raise [Gitable::URI::InvalidURIError] When the uri is *total* rubbish.
|
16
|
+
#
|
17
|
+
def self.parse(uri)
|
18
|
+
return uri if uri.nil? || uri.kind_of?(self)
|
19
|
+
|
20
|
+
# addressable::URI.parse always returns an instance of Addressable::URI.
|
21
|
+
add = super # >:(
|
22
|
+
|
23
|
+
scan = uri.scan(SCP_URI_REGEXP)
|
24
|
+
fragments = scan[0]
|
25
|
+
authority = fragments && fragments[0]
|
26
|
+
|
27
|
+
if add.host.nil? && authority
|
28
|
+
Gitable::ScpURI.new(
|
29
|
+
:authority => authority,
|
30
|
+
:path => add.path
|
31
|
+
)
|
32
|
+
else
|
33
|
+
new(add.omit(:password,:query,:fragment).to_hash)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Attempts to make a copied url bar into a git repo uri
|
39
|
+
#
|
40
|
+
# First line of defense is for urls without .git as a basename:
|
41
|
+
# * Change the scheme from http:// to git://
|
42
|
+
# * Add .git to the basename
|
43
|
+
#
|
44
|
+
# @param [Addressable::URI, #to_str] uri URI of a git repository.
|
45
|
+
#
|
46
|
+
# @return [Gitable::URI, nil] the URI object or nil if nil was passed in.
|
47
|
+
#
|
48
|
+
# @raise [TypeError] The uri must respond to #to_str.
|
49
|
+
# @raise [Gitable::URI::InvalidURIError] When the uri is *total* rubbish.
|
50
|
+
#
|
51
|
+
def self.heuristic_parse(uri)
|
52
|
+
return uri if uri.nil? || uri.kind_of?(self)
|
53
|
+
|
54
|
+
add = super
|
55
|
+
return add if add.extname == "git"
|
56
|
+
add.scheme = "git" if add.scheme == "http"
|
57
|
+
unless add.basename.nil?
|
58
|
+
# replace the last occurance of the basename with basename.git
|
59
|
+
# please tell me if there's a better way (besides rindex/slice/insert)
|
60
|
+
rpath = add.path.reverse
|
61
|
+
rbase = add.basename.reverse
|
62
|
+
add.path = rpath.sub(%r|#{Regexp.escape(rbase)}|,"tig."+rbase).reverse
|
63
|
+
end
|
64
|
+
add
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# Tries to guess the project name of the repository.
|
69
|
+
#
|
70
|
+
# @return [String] Project name without .git
|
71
|
+
def project_name
|
72
|
+
basename.sub(/\.git$/,'')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/spec/gitable_spec.rb
CHANGED
@@ -1,380 +1,427 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Gitable::URI do
|
4
|
-
before do
|
5
|
-
@uri = "ssh://git@github.com/martinemde/gitable.git"
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.describe_uri(uri, &block)
|
9
|
-
describe "with uri: #{uri.inspect}" do
|
10
|
-
before { @uri = uri }
|
11
|
-
subject { Gitable::URI.parse(@uri) }
|
12
|
-
URIChecker.new(self, &block)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class URIChecker
|
17
|
-
def initialize(example_group, &block)
|
18
|
-
@example_group = example_group
|
19
|
-
instance_eval(&block)
|
20
|
-
end
|
21
|
-
|
22
|
-
def it_sets(parts)
|
23
|
-
parts.each do |part, value|
|
24
|
-
it "sets #{part} to #{value.inspect}" do
|
25
|
-
subject.send(part).should == value
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def method_missing(*args, &block)
|
31
|
-
@example_group.send(*args, &block)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Valid Git URIs according to git-clone documentation at this url:
|
36
|
-
# http://www.kernel.org/pub/software/scm/git/docs/git-clone.html#_git_urls_a_id_urls_a
|
37
|
-
#
|
38
|
-
# rsync://host.xz/path/to/repo.git/
|
39
|
-
# http://host.xz[:port]/path/to/repo.git/
|
40
|
-
# https://host.xz[:port]/path/to/repo.git/
|
41
|
-
# git://host.xz[:port]/path/to/repo.git/
|
42
|
-
# git://host.xz[:port]/~user/path/to/repo.git/
|
43
|
-
# ssh://[user@]host.xz[:port]/path/to/repo.git/
|
44
|
-
# ssh://[user@]host.xz/path/to/repo.git/
|
45
|
-
# ssh://[user@]host.xz/~user/path/to/repo.git/
|
46
|
-
# ssh://[user@]host.xz/~/path/to/repo.git
|
47
|
-
#
|
48
|
-
# (from the git docs)
|
49
|
-
# SSH is the default transport protocol over the network. You can optionally specify which user to log-in as, and an alternate, scp-like syntax is also supported. Both syntaxes support username expansion, as does the native git protocol, but only the former supports port specification. The following three are identical to the last three above, respectively:
|
50
|
-
#
|
51
|
-
# [user@]host.xz:/path/to/repo.git/
|
52
|
-
# [user@]host.xz:~user/path/to/repo.git/
|
53
|
-
# [user@]host.xz:path/to/repo.git
|
54
|
-
#
|
55
|
-
# To sync with a local directory, you can use:
|
56
|
-
#
|
57
|
-
# /path/to/repo.git/
|
58
|
-
# file:///path/to/repo.git/
|
59
|
-
#
|
60
|
-
expected = {
|
61
|
-
:user => nil,
|
62
|
-
:password => nil,
|
63
|
-
:host => "host.xz",
|
64
|
-
:port => nil,
|
65
|
-
:path => "/path/to/repo.git/",
|
66
|
-
:basename => "repo.git",
|
67
|
-
:query => nil,
|
68
|
-
:fragment => nil,
|
69
|
-
:project_name => "repo"
|
70
|
-
}
|
71
|
-
|
72
|
-
describe ".parse" do
|
73
|
-
it "returns a Gitable::URI" do
|
74
|
-
Gitable::URI.parse(@uri).should be_a_kind_of(Gitable::URI)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "returns nil when passed a nil uri" do
|
78
|
-
Gitable::URI.parse(nil).should be_nil
|
79
|
-
end
|
80
|
-
|
81
|
-
it "returns the same uri when passed a Gitable::URI" do
|
82
|
-
gitable = Gitable::URI.parse(@uri)
|
83
|
-
Gitable::URI.parse(gitable).should be_eql(gitable)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "raises a TypeError on bad type" do
|
87
|
-
lambda {
|
88
|
-
Gitable::URI.parse(5)
|
89
|
-
}.should raise_error(TypeError)
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
:
|
133
|
-
:port => 8888,
|
134
|
-
})
|
135
|
-
end
|
136
|
-
|
137
|
-
describe_uri "
|
138
|
-
it { subject.to_s.should == @uri }
|
139
|
-
it_sets expected.merge({
|
140
|
-
:scheme => "
|
141
|
-
})
|
142
|
-
end
|
143
|
-
|
144
|
-
describe_uri "
|
145
|
-
it { subject.to_s.should == @uri }
|
146
|
-
it_sets expected.merge({
|
147
|
-
:scheme => "
|
148
|
-
:port => 8888,
|
149
|
-
})
|
150
|
-
end
|
151
|
-
|
152
|
-
describe_uri "git://host.xz
|
153
|
-
it { subject.to_s.should == @uri }
|
154
|
-
it_sets expected.merge({
|
155
|
-
:scheme => "git",
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
:
|
188
|
-
})
|
189
|
-
end
|
190
|
-
|
191
|
-
describe_uri "ssh://host.xz
|
192
|
-
it { subject.to_s.should == @uri }
|
193
|
-
it_sets expected.merge({
|
194
|
-
:scheme => "ssh",
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
:user => "user",
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
}
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
}
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
}
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
:
|
331
|
-
:
|
332
|
-
:
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
:
|
341
|
-
:
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
:
|
355
|
-
:
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
:
|
369
|
-
:
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
:
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Gitable::URI do
|
4
|
+
before do
|
5
|
+
@uri = "ssh://git@github.com/martinemde/gitable.git"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.describe_uri(uri, &block)
|
9
|
+
describe "with uri: #{uri.inspect}" do
|
10
|
+
before { @uri = uri }
|
11
|
+
subject { Gitable::URI.parse(@uri) }
|
12
|
+
URIChecker.new(self, &block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class URIChecker
|
17
|
+
def initialize(example_group, &block)
|
18
|
+
@example_group = example_group
|
19
|
+
instance_eval(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def it_sets(parts)
|
23
|
+
parts.each do |part, value|
|
24
|
+
it "sets #{part} to #{value.inspect}" do
|
25
|
+
subject.send(part).should == value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing(*args, &block)
|
31
|
+
@example_group.send(*args, &block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Valid Git URIs according to git-clone documentation at this url:
|
36
|
+
# http://www.kernel.org/pub/software/scm/git/docs/git-clone.html#_git_urls_a_id_urls_a
|
37
|
+
#
|
38
|
+
# rsync://host.xz/path/to/repo.git/
|
39
|
+
# http://host.xz[:port]/path/to/repo.git/
|
40
|
+
# https://host.xz[:port]/path/to/repo.git/
|
41
|
+
# git://host.xz[:port]/path/to/repo.git/
|
42
|
+
# git://host.xz[:port]/~user/path/to/repo.git/
|
43
|
+
# ssh://[user@]host.xz[:port]/path/to/repo.git/
|
44
|
+
# ssh://[user@]host.xz/path/to/repo.git/
|
45
|
+
# ssh://[user@]host.xz/~user/path/to/repo.git/
|
46
|
+
# ssh://[user@]host.xz/~/path/to/repo.git
|
47
|
+
#
|
48
|
+
# (from the git docs)
|
49
|
+
# SSH is the default transport protocol over the network. You can optionally specify which user to log-in as, and an alternate, scp-like syntax is also supported. Both syntaxes support username expansion, as does the native git protocol, but only the former supports port specification. The following three are identical to the last three above, respectively:
|
50
|
+
#
|
51
|
+
# [user@]host.xz:/path/to/repo.git/
|
52
|
+
# [user@]host.xz:~user/path/to/repo.git/
|
53
|
+
# [user@]host.xz:path/to/repo.git
|
54
|
+
#
|
55
|
+
# To sync with a local directory, you can use:
|
56
|
+
#
|
57
|
+
# /path/to/repo.git/
|
58
|
+
# file:///path/to/repo.git/
|
59
|
+
#
|
60
|
+
expected = {
|
61
|
+
:user => nil,
|
62
|
+
:password => nil,
|
63
|
+
:host => "host.xz",
|
64
|
+
:port => nil,
|
65
|
+
:path => "/path/to/repo.git/",
|
66
|
+
:basename => "repo.git",
|
67
|
+
:query => nil,
|
68
|
+
:fragment => nil,
|
69
|
+
:project_name => "repo"
|
70
|
+
}
|
71
|
+
|
72
|
+
describe ".parse" do
|
73
|
+
it "returns a Gitable::URI" do
|
74
|
+
Gitable::URI.parse(@uri).should be_a_kind_of(Gitable::URI)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns nil when passed a nil uri" do
|
78
|
+
Gitable::URI.parse(nil).should be_nil
|
79
|
+
end
|
80
|
+
|
81
|
+
it "returns the same uri when passed a Gitable::URI" do
|
82
|
+
gitable = Gitable::URI.parse(@uri)
|
83
|
+
Gitable::URI.parse(gitable).should be_eql(gitable)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "raises a TypeError on bad type" do
|
87
|
+
lambda {
|
88
|
+
Gitable::URI.parse(5)
|
89
|
+
}.should raise_error(TypeError)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "raises an Gitable::URI::InvalidURIError on a bad uri" do
|
93
|
+
lambda {
|
94
|
+
Gitable::URI.parse("http://")
|
95
|
+
}.should raise_error(Gitable::URI::InvalidURIError)
|
96
|
+
end
|
97
|
+
|
98
|
+
describe_uri "rsync://host.xz/path/to/repo.git/" do
|
99
|
+
it { subject.to_s.should == @uri }
|
100
|
+
it_sets expected.merge({
|
101
|
+
:scheme => "rsync",
|
102
|
+
:project_name => "repo"
|
103
|
+
})
|
104
|
+
end
|
105
|
+
|
106
|
+
describe_uri "rsync://host.xz/path/to/repo.git/" do
|
107
|
+
it { subject.to_s.should == @uri }
|
108
|
+
it_sets expected.merge({
|
109
|
+
:scheme => "rsync",
|
110
|
+
})
|
111
|
+
end
|
112
|
+
|
113
|
+
describe_uri "http://host.xz/path/to/repo.git/" do
|
114
|
+
it { subject.to_s.should == @uri }
|
115
|
+
it_sets expected.merge({
|
116
|
+
:scheme => "http",
|
117
|
+
})
|
118
|
+
end
|
119
|
+
|
120
|
+
describe_uri "http://host.xz:8888/path/to/repo.git/" do
|
121
|
+
it { subject.to_s.should == @uri }
|
122
|
+
it_sets expected.merge({
|
123
|
+
:scheme => "http",
|
124
|
+
:port => 8888,
|
125
|
+
})
|
126
|
+
end
|
127
|
+
|
128
|
+
describe_uri "http://12.34.56.78:8888/path/to/repo.git/" do
|
129
|
+
it { subject.to_s.should == @uri }
|
130
|
+
it_sets expected.merge({
|
131
|
+
:scheme => "http",
|
132
|
+
:host => "12.34.56.78",
|
133
|
+
:port => 8888,
|
134
|
+
})
|
135
|
+
end
|
136
|
+
|
137
|
+
describe_uri "https://host.xz/path/to/repo.git/" do
|
138
|
+
it { subject.to_s.should == @uri }
|
139
|
+
it_sets expected.merge({
|
140
|
+
:scheme => "https",
|
141
|
+
})
|
142
|
+
end
|
143
|
+
|
144
|
+
describe_uri "https://host.xz:8888/path/to/repo.git/" do
|
145
|
+
it { subject.to_s.should == @uri }
|
146
|
+
it_sets expected.merge({
|
147
|
+
:scheme => "https",
|
148
|
+
:port => 8888,
|
149
|
+
})
|
150
|
+
end
|
151
|
+
|
152
|
+
describe_uri "git+ssh://host.xz/path/to/repo.git/" do
|
153
|
+
it { subject.to_s.should == @uri }
|
154
|
+
it_sets expected.merge({
|
155
|
+
:scheme => "git+ssh",
|
156
|
+
})
|
157
|
+
end
|
158
|
+
|
159
|
+
describe_uri "git://host.xz/path/to/repo.git/" do
|
160
|
+
it { subject.to_s.should == @uri }
|
161
|
+
it_sets expected.merge({
|
162
|
+
:scheme => "git",
|
163
|
+
})
|
164
|
+
end
|
165
|
+
|
166
|
+
describe_uri "git://host.xz:8888/path/to/repo.git/" do
|
167
|
+
it { subject.to_s.should == @uri }
|
168
|
+
it_sets expected.merge({
|
169
|
+
:scheme => "git",
|
170
|
+
:port => 8888,
|
171
|
+
})
|
172
|
+
end
|
173
|
+
|
174
|
+
describe_uri "git://host.xz/~user/path/to/repo.git/" do
|
175
|
+
it { subject.to_s.should == @uri }
|
176
|
+
it_sets expected.merge({
|
177
|
+
:scheme => "git",
|
178
|
+
:path => "/~user/path/to/repo.git/",
|
179
|
+
})
|
180
|
+
end
|
181
|
+
|
182
|
+
describe_uri "git://host.xz:8888/~user/path/to/repo.git/" do
|
183
|
+
it { subject.to_s.should == @uri }
|
184
|
+
it_sets expected.merge({
|
185
|
+
:scheme => "git",
|
186
|
+
:path => "/~user/path/to/repo.git/",
|
187
|
+
:port => 8888,
|
188
|
+
})
|
189
|
+
end
|
190
|
+
|
191
|
+
describe_uri "ssh://host.xz/path/to/repo.git/" do
|
192
|
+
it { subject.to_s.should == @uri }
|
193
|
+
it_sets expected.merge({
|
194
|
+
:scheme => "ssh",
|
195
|
+
})
|
196
|
+
end
|
197
|
+
|
198
|
+
describe_uri "ssh://user@host.xz/path/to/repo.git/" do
|
199
|
+
it { subject.to_s.should == @uri }
|
200
|
+
it_sets expected.merge({
|
201
|
+
:scheme => "ssh",
|
202
|
+
:user => "user",
|
203
|
+
})
|
204
|
+
end
|
205
|
+
|
206
|
+
describe_uri "ssh://host.xz/path/to/repo.git/" do
|
207
|
+
it { subject.to_s.should == @uri }
|
208
|
+
it_sets expected.merge({
|
209
|
+
:scheme => "ssh",
|
210
|
+
})
|
211
|
+
end
|
212
|
+
|
213
|
+
describe_uri "ssh://host.xz:8888/path/to/repo.git/" do
|
214
|
+
it { subject.to_s.should == @uri }
|
215
|
+
it_sets expected.merge({
|
216
|
+
:scheme => "ssh",
|
217
|
+
:port => 8888,
|
218
|
+
})
|
219
|
+
end
|
220
|
+
|
221
|
+
describe_uri "ssh://user@host.xz/path/to/repo.git/" do
|
222
|
+
it { subject.to_s.should == @uri }
|
223
|
+
it_sets expected.merge({
|
224
|
+
:user => "user",
|
225
|
+
:scheme => "ssh",
|
226
|
+
})
|
227
|
+
end
|
228
|
+
|
229
|
+
describe_uri "ssh://user@host.xz:8888/path/to/repo.git/" do
|
230
|
+
it { subject.to_s.should == @uri }
|
231
|
+
it_sets expected.merge({
|
232
|
+
:scheme => "ssh",
|
233
|
+
:user => "user",
|
234
|
+
:port => 8888,
|
235
|
+
})
|
236
|
+
end
|
237
|
+
|
238
|
+
describe_uri "ssh://host.xz/~user/path/to/repo.git/" do
|
239
|
+
it { subject.to_s.should == @uri }
|
240
|
+
it_sets expected.merge({
|
241
|
+
:scheme => "ssh",
|
242
|
+
:user => nil,
|
243
|
+
:path => "/~user/path/to/repo.git/",
|
244
|
+
})
|
245
|
+
end
|
246
|
+
|
247
|
+
describe_uri "ssh://user@host.xz/~user/path/to/repo.git/" do
|
248
|
+
it { subject.to_s.should == @uri }
|
249
|
+
it_sets expected.merge({
|
250
|
+
:scheme => "ssh",
|
251
|
+
:user => "user",
|
252
|
+
:path => "/~user/path/to/repo.git/",
|
253
|
+
})
|
254
|
+
end
|
255
|
+
|
256
|
+
describe_uri "ssh://host.xz/~/path/to/repo.git" do
|
257
|
+
it { subject.to_s.should == @uri }
|
258
|
+
it_sets expected.merge({
|
259
|
+
:scheme => "ssh",
|
260
|
+
:path => "/~/path/to/repo.git",
|
261
|
+
})
|
262
|
+
end
|
263
|
+
|
264
|
+
describe_uri "ssh://user@host.xz/~/path/to/repo.git" do
|
265
|
+
it { subject.to_s.should == @uri }
|
266
|
+
it_sets expected.merge({
|
267
|
+
:scheme => "ssh",
|
268
|
+
:user => "user",
|
269
|
+
:path => "/~/path/to/repo.git",
|
270
|
+
})
|
271
|
+
end
|
272
|
+
|
273
|
+
describe_uri "host.xz:/path/to/repo.git/" do
|
274
|
+
it { subject.to_s.should == @uri }
|
275
|
+
it_sets expected.merge({
|
276
|
+
:scheme => nil,
|
277
|
+
:user => nil,
|
278
|
+
:path => "/path/to/repo.git/",
|
279
|
+
})
|
280
|
+
end
|
281
|
+
|
282
|
+
describe_uri "user@host.xz:/path/to/repo.git/" do
|
283
|
+
it { subject.to_s.should == @uri }
|
284
|
+
it_sets expected.merge({
|
285
|
+
:scheme => nil,
|
286
|
+
:user => "user",
|
287
|
+
:path => "/path/to/repo.git/",
|
288
|
+
})
|
289
|
+
end
|
290
|
+
|
291
|
+
describe_uri "host.xz:~user/path/to/repo.git/" do
|
292
|
+
it { subject.to_s.should == @uri }
|
293
|
+
it_sets expected.merge({
|
294
|
+
:scheme => nil,
|
295
|
+
:user => nil,
|
296
|
+
:path => "~user/path/to/repo.git/",
|
297
|
+
})
|
298
|
+
end
|
299
|
+
|
300
|
+
describe_uri "user@host.xz:~user/path/to/repo.git/" do
|
301
|
+
it { subject.to_s.should == @uri }
|
302
|
+
it_sets expected.merge({
|
303
|
+
:scheme => nil,
|
304
|
+
:user => "user",
|
305
|
+
:path => "~user/path/to/repo.git/",
|
306
|
+
})
|
307
|
+
end
|
308
|
+
|
309
|
+
describe_uri "host.xz:path/to/repo.git" do
|
310
|
+
it { subject.to_s.should == @uri }
|
311
|
+
it_sets expected.merge({
|
312
|
+
:scheme => nil,
|
313
|
+
:user => nil,
|
314
|
+
:path => "path/to/repo.git",
|
315
|
+
})
|
316
|
+
end
|
317
|
+
|
318
|
+
describe_uri "user@host.xz:path/to/repo.git" do
|
319
|
+
it { subject.to_s.should == @uri }
|
320
|
+
it_sets expected.merge({
|
321
|
+
:scheme => nil,
|
322
|
+
:user => "user",
|
323
|
+
:path => "path/to/repo.git",
|
324
|
+
})
|
325
|
+
end
|
326
|
+
|
327
|
+
describe_uri "/path/to/repo.git/" do
|
328
|
+
it { subject.to_s.should == @uri }
|
329
|
+
it_sets expected.merge({
|
330
|
+
:scheme => nil,
|
331
|
+
:host => nil,
|
332
|
+
:path => "/path/to/repo.git/",
|
333
|
+
})
|
334
|
+
end
|
335
|
+
|
336
|
+
describe_uri "file:///path/to/repo.git/" do
|
337
|
+
it { subject.to_s.should == @uri }
|
338
|
+
it_sets expected.merge({
|
339
|
+
:scheme => "file",
|
340
|
+
:host => "", # I don't really like this but it doesn't hurt anything.
|
341
|
+
:path => "/path/to/repo.git/",
|
342
|
+
})
|
343
|
+
end
|
344
|
+
|
345
|
+
describe_uri "ssh://git@github.com/martinemde/gitable.git" do
|
346
|
+
it { subject.to_s.should == @uri }
|
347
|
+
it_sets({
|
348
|
+
:scheme => "ssh",
|
349
|
+
:user => "git",
|
350
|
+
:password => nil,
|
351
|
+
:host => "github.com",
|
352
|
+
:port => nil,
|
353
|
+
:path => "/martinemde/gitable.git",
|
354
|
+
:fragment => nil,
|
355
|
+
:basename => "gitable.git",
|
356
|
+
})
|
357
|
+
end
|
358
|
+
|
359
|
+
describe_uri "http://github.com/martinemde/gitable.git" do
|
360
|
+
it { subject.to_s.should == @uri }
|
361
|
+
it_sets({
|
362
|
+
:scheme => "http",
|
363
|
+
:user => nil,
|
364
|
+
:password => nil,
|
365
|
+
:host => "github.com",
|
366
|
+
:port => nil,
|
367
|
+
:path => "/martinemde/gitable.git",
|
368
|
+
:fragment => nil,
|
369
|
+
:basename => "gitable.git",
|
370
|
+
})
|
371
|
+
end
|
372
|
+
|
373
|
+
describe_uri "git://github.com/martinemde/gitable.git" do
|
374
|
+
it { subject.to_s.should == @uri }
|
375
|
+
it_sets({
|
376
|
+
:scheme => "git",
|
377
|
+
:user => nil,
|
378
|
+
:password => nil,
|
379
|
+
:host => "github.com",
|
380
|
+
:port => nil,
|
381
|
+
:path => "/martinemde/gitable.git",
|
382
|
+
:fragment => nil,
|
383
|
+
:basename => "gitable.git",
|
384
|
+
})
|
385
|
+
end
|
386
|
+
|
387
|
+
describe_uri "git@github.com:martinemde/gitable.git" do
|
388
|
+
it { subject.to_s.should == @uri }
|
389
|
+
it_sets({
|
390
|
+
:scheme => nil,
|
391
|
+
:user => "git",
|
392
|
+
:password => nil,
|
393
|
+
:host => "github.com",
|
394
|
+
:port => nil,
|
395
|
+
:path => "martinemde/gitable.git",
|
396
|
+
:fragment => nil,
|
397
|
+
:basename => "gitable.git",
|
398
|
+
:project_name => "gitable",
|
399
|
+
})
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
describe ".heuristic_parse" do
|
404
|
+
it "returns a Gitable::URI" do
|
405
|
+
uri = "http://github.com/martinemde/gitable"
|
406
|
+
Gitable::URI.heuristic_parse(uri).should be_a_kind_of(Gitable::URI)
|
407
|
+
end
|
408
|
+
|
409
|
+
it "guesses git://github.com/martinemde/gitable.git if I pass in the url bar" do
|
410
|
+
uri = "http://github.com/martinemde/gitable"
|
411
|
+
gitable = Gitable::URI.heuristic_parse(uri)
|
412
|
+
gitable.to_s.should == "git://github.com/martinemde/gitable.git"
|
413
|
+
end
|
414
|
+
|
415
|
+
it "isn't upset by trailing slashes" do
|
416
|
+
uri = "http://github.com/martinemde/gitable/"
|
417
|
+
gitable = Gitable::URI.heuristic_parse(uri)
|
418
|
+
gitable.to_s.should == "git://github.com/martinemde/gitable.git/"
|
419
|
+
end
|
420
|
+
|
421
|
+
it "handles URIs with the name of the project in the path twice" do
|
422
|
+
uri = "http://gitorious.org/project/project"
|
423
|
+
gitable = Gitable::URI.heuristic_parse(uri)
|
424
|
+
gitable.to_s.should == "git://gitorious.org/project/project.git"
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end
|