gitable 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,32 +1,75 @@
1
- require 'addressable/uri'
2
-
3
- module Gitable
4
- class URI < Addressable::URI
5
- SCP_URI_REGEXP = /^([^:\/?#]+):([^?#]*)$/
6
-
7
- def self.parse(uri)
8
- return uri if uri.nil? || uri.kind_of?(self)
9
-
10
- # addressable::URI.parse always returns an instance of Addressable::URI.
11
- add = super(uri) # >:(
12
-
13
- scan = uri.scan(SCP_URI_REGEXP)
14
- fragments = scan[0]
15
- authority = fragments && fragments[0]
16
-
17
- if add.host.nil? && authority
18
- Gitable::ScpURI.new(
19
- :authority => authority,
20
- :path => add.path
21
- )
22
- else
23
- new(add.omit(:password,:query,:fragment).to_hash)
24
- end
25
- end
26
-
27
- # guesses a project name
28
- def project_name
29
- basename.sub(/\.git$/,'')
30
- end
31
- end
32
- end
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
@@ -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
- describe_uri "rsync://host.xz/path/to/repo.git/" do
93
- it { subject.to_s.should == @uri }
94
- it_sets expected.merge({
95
- :scheme => "rsync",
96
- :project_name => "repo"
97
- })
98
- end
99
-
100
- describe_uri "rsync://host.xz/path/to/repo.git/" do
101
- it { subject.to_s.should == @uri }
102
- it_sets expected.merge({
103
- :scheme => "rsync",
104
- })
105
- end
106
-
107
- describe_uri "http://host.xz/path/to/repo.git/" do
108
- it { subject.to_s.should == @uri }
109
- it_sets expected.merge({
110
- :scheme => "http",
111
- })
112
- end
113
-
114
- describe_uri "http://host.xz:8888/path/to/repo.git/" do
115
- it { subject.to_s.should == @uri }
116
- it_sets expected.merge({
117
- :scheme => "http",
118
- :port => 8888,
119
- })
120
- end
121
-
122
- describe_uri "https://host.xz/path/to/repo.git/" do
123
- it { subject.to_s.should == @uri }
124
- it_sets expected.merge({
125
- :scheme => "https",
126
- })
127
- end
128
-
129
- describe_uri "https://host.xz:8888/path/to/repo.git/" do
130
- it { subject.to_s.should == @uri }
131
- it_sets expected.merge({
132
- :scheme => "https",
133
- :port => 8888,
134
- })
135
- end
136
-
137
- describe_uri "git://host.xz/path/to/repo.git/" do
138
- it { subject.to_s.should == @uri }
139
- it_sets expected.merge({
140
- :scheme => "git",
141
- })
142
- end
143
-
144
- describe_uri "git://host.xz:8888/path/to/repo.git/" do
145
- it { subject.to_s.should == @uri }
146
- it_sets expected.merge({
147
- :scheme => "git",
148
- :port => 8888,
149
- })
150
- end
151
-
152
- describe_uri "git://host.xz/~user/path/to/repo.git/" do
153
- it { subject.to_s.should == @uri }
154
- it_sets expected.merge({
155
- :scheme => "git",
156
- :path => "/~user/path/to/repo.git/",
157
- })
158
- end
159
-
160
- describe_uri "git://host.xz:8888/~user/path/to/repo.git/" do
161
- it { subject.to_s.should == @uri }
162
- it_sets expected.merge({
163
- :scheme => "git",
164
- :path => "/~user/path/to/repo.git/",
165
- :port => 8888,
166
- })
167
- end
168
-
169
- describe_uri "ssh://host.xz/path/to/repo.git/" do
170
- it { subject.to_s.should == @uri }
171
- it_sets expected.merge({
172
- :scheme => "ssh",
173
- })
174
- end
175
-
176
- describe_uri "ssh://user@host.xz/path/to/repo.git/" do
177
- it { subject.to_s.should == @uri }
178
- it_sets expected.merge({
179
- :scheme => "ssh",
180
- :user => "user",
181
- })
182
- end
183
-
184
- describe_uri "ssh://host.xz/path/to/repo.git/" do
185
- it { subject.to_s.should == @uri }
186
- it_sets expected.merge({
187
- :scheme => "ssh",
188
- })
189
- end
190
-
191
- describe_uri "ssh://host.xz:8888/path/to/repo.git/" do
192
- it { subject.to_s.should == @uri }
193
- it_sets expected.merge({
194
- :scheme => "ssh",
195
- :port => 8888,
196
- })
197
- end
198
-
199
- describe_uri "ssh://user@host.xz/path/to/repo.git/" do
200
- it { subject.to_s.should == @uri }
201
- it_sets expected.merge({
202
- :user => "user",
203
- :scheme => "ssh",
204
- })
205
- end
206
-
207
- describe_uri "ssh://user@host.xz:8888/path/to/repo.git/" do
208
- it { subject.to_s.should == @uri }
209
- it_sets expected.merge({
210
- :scheme => "ssh",
211
- :user => "user",
212
- :port => 8888,
213
- })
214
- end
215
-
216
- describe_uri "ssh://host.xz/~user/path/to/repo.git/" do
217
- it { subject.to_s.should == @uri }
218
- it_sets expected.merge({
219
- :scheme => "ssh",
220
- :user => nil,
221
- :path => "/~user/path/to/repo.git/",
222
- })
223
- end
224
-
225
- describe_uri "ssh://user@host.xz/~user/path/to/repo.git/" do
226
- it { subject.to_s.should == @uri }
227
- it_sets expected.merge({
228
- :scheme => "ssh",
229
- :user => "user",
230
- :path => "/~user/path/to/repo.git/",
231
- })
232
- end
233
-
234
- describe_uri "ssh://host.xz/~/path/to/repo.git" do
235
- it { subject.to_s.should == @uri }
236
- it_sets expected.merge({
237
- :scheme => "ssh",
238
- :path => "/~/path/to/repo.git",
239
- })
240
- end
241
-
242
- describe_uri "ssh://user@host.xz/~/path/to/repo.git" do
243
- it { subject.to_s.should == @uri }
244
- it_sets expected.merge({
245
- :scheme => "ssh",
246
- :user => "user",
247
- :path => "/~/path/to/repo.git",
248
- })
249
- end
250
-
251
- describe_uri "host.xz:/path/to/repo.git/" do
252
- it { subject.to_s.should == @uri }
253
- it_sets expected.merge({
254
- :scheme => nil,
255
- :user => nil,
256
- :path => "/path/to/repo.git/",
257
- })
258
- end
259
-
260
- describe_uri "user@host.xz:/path/to/repo.git/" do
261
- it { subject.to_s.should == @uri }
262
- it_sets expected.merge({
263
- :scheme => nil,
264
- :user => "user",
265
- :path => "/path/to/repo.git/",
266
- })
267
- end
268
-
269
- describe_uri "host.xz:~user/path/to/repo.git/" do
270
- it { subject.to_s.should == @uri }
271
- it_sets expected.merge({
272
- :scheme => nil,
273
- :user => nil,
274
- :path => "~user/path/to/repo.git/",
275
- })
276
- end
277
-
278
- describe_uri "user@host.xz:~user/path/to/repo.git/" do
279
- it { subject.to_s.should == @uri }
280
- it_sets expected.merge({
281
- :scheme => nil,
282
- :user => "user",
283
- :path => "~user/path/to/repo.git/",
284
- })
285
- end
286
-
287
- describe_uri "host.xz:path/to/repo.git" do
288
- it { subject.to_s.should == @uri }
289
- it_sets expected.merge({
290
- :scheme => nil,
291
- :user => nil,
292
- :path => "path/to/repo.git",
293
- })
294
- end
295
-
296
- describe_uri "user@host.xz:path/to/repo.git" do
297
- it { subject.to_s.should == @uri }
298
- it_sets expected.merge({
299
- :scheme => nil,
300
- :user => "user",
301
- :path => "path/to/repo.git",
302
- })
303
- end
304
-
305
- describe_uri "/path/to/repo.git/" do
306
- it { subject.to_s.should == @uri }
307
- it_sets expected.merge({
308
- :scheme => nil,
309
- :host => nil,
310
- :path => "/path/to/repo.git/",
311
- })
312
- end
313
-
314
- describe_uri "file:///path/to/repo.git/" do
315
- it { subject.to_s.should == @uri }
316
- it_sets expected.merge({
317
- :scheme => "file",
318
- :host => "", # I don't really like this but it doesn't hurt anything.
319
- :path => "/path/to/repo.git/",
320
- })
321
- end
322
-
323
- describe_uri "ssh://git@github.com/martinemde/gitable.git" do
324
- it { subject.to_s.should == @uri }
325
- it_sets({
326
- :scheme => "ssh",
327
- :user => "git",
328
- :password => nil,
329
- :host => "github.com",
330
- :port => nil,
331
- :path => "/martinemde/gitable.git",
332
- :fragment => nil,
333
- :basename => "gitable.git",
334
- })
335
- end
336
-
337
- describe_uri "http://github.com/martinemde/gitable.git" do
338
- it { subject.to_s.should == @uri }
339
- it_sets({
340
- :scheme => "http",
341
- :user => nil,
342
- :password => nil,
343
- :host => "github.com",
344
- :port => nil,
345
- :path => "/martinemde/gitable.git",
346
- :fragment => nil,
347
- :basename => "gitable.git",
348
- })
349
- end
350
-
351
- describe_uri "git://github.com/martinemde/gitable.git" do
352
- it { subject.to_s.should == @uri }
353
- it_sets({
354
- :scheme => "git",
355
- :user => nil,
356
- :password => nil,
357
- :host => "github.com",
358
- :port => nil,
359
- :path => "/martinemde/gitable.git",
360
- :fragment => nil,
361
- :basename => "gitable.git",
362
- })
363
- end
364
-
365
- describe_uri "git@github.com:martinemde/gitable.git" do
366
- it { subject.to_s.should == @uri }
367
- it_sets({
368
- :scheme => nil,
369
- :user => "git",
370
- :password => nil,
371
- :host => "github.com",
372
- :port => nil,
373
- :path => "martinemde/gitable.git",
374
- :fragment => nil,
375
- :basename => "gitable.git",
376
- :project_name => "gitable",
377
- })
378
- end
379
- end
380
- end
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