public
Fork of mojombo/grit
Description: Grit is a Ruby library for extracting information from a git repository in an object oriented manner.
Homepage: http://grit.rubyforge.org/
Clone URL: git://github.com/technoweenie/grit.git
add alternates getter and setter
mojombo (author)
Thu Feb 14 20:06:11 -0800 2008
technoweenie (committer)
Sun Feb 17 23:19:01 -0800 2008
commit  3ea514188523ae9e8ecd603f760442f147042d6c
tree    d03ebb928ede2410e267dcd6e4464a1843d458ff
parent  f32458940ef496d61946d4e3d63bc5edd1ae0af7
...
245
246
247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
249
250
...
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
0
@@ -245,6 +245,35 @@ module Grit
0
       end
0
     end
0
     
0
+ # The list of alternates for this repo
0
+ #
0
+ # Returns Array[String] (pathnames of alternates)
0
+ def alternates
0
+ alternates_path = File.join(self.path, *%w{objects info alternates})
0
+
0
+ if File.exist?(alternates_path)
0
+ File.read(alternates_path).strip.split("\n")
0
+ else
0
+ []
0
+ end
0
+ end
0
+
0
+ # Sets the alternates
0
+ # +alts+ is the Array of String paths representing the alternates
0
+ #
0
+ # Returns nothing
0
+ def alternates=(alts)
0
+ alts.each do |alt|
0
+ unless File.exist?(alt)
0
+ raise "Could not set alternates. Alternate path #{alt} must exist"
0
+ end
0
+ end
0
+
0
+ File.open(File.join(self.path, *%w{objects info alternates}), 'w') do |f|
0
+ f.write alts.join("\n")
0
+ end
0
+ end
0
+
0
     # Pretty object inspection
0
     def inspect
0
       %Q{#<Grit::Repo "#{@path}">}
...
196
197
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
200
201
...
196
197
198
199
200
201
202
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
0
@@ -196,6 +196,51 @@ class TestRepo < Test::Unit::TestCase
0
     @r.disable_daemon_serve
0
   end
0
   
0
+ # alternates
0
+
0
+ def test_alternates_with_two_alternates
0
+ File.expects(:exist?).with('/Users/tom/dev/mojombo/grit/.git/objects/info/alternates').returns(true)
0
+ File.expects(:read).returns("/path/to/repo1/.git/objects\n/path/to/repo2.git/objects\n")
0
+
0
+ assert_equal ["/path/to/repo1/.git/objects", "/path/to/repo2.git/objects"], @r.alternates
0
+ end
0
+
0
+ def test_alternates_no_file
0
+ File.expects(:exist?).returns(false)
0
+
0
+ assert_equal [], @r.alternates
0
+ end
0
+
0
+ # alternates=
0
+
0
+ def test_alternates_setter_ok
0
+ alts = %w{/path/to/repo.git/objects /path/to/repo2.git/objects}
0
+
0
+ alts.each do |alt|
0
+ File.expects(:exist?).with(alt).returns(true)
0
+ end
0
+
0
+ File.any_instance.expects(:write).with(alts.join("\n"))
0
+
0
+ assert_nothing_raised do
0
+ @r.alternates = alts
0
+ end
0
+ end
0
+
0
+ def test_alternates_setter_bad
0
+ alts = %w{/path/to/repo.git/objects}
0
+
0
+ alts.each do |alt|
0
+ File.expects(:exist?).with(alt).returns(false)
0
+ end
0
+
0
+ File.any_instance.expects(:write).never
0
+
0
+ assert_raise RuntimeError do
0
+ @r.alternates = alts
0
+ end
0
+ end
0
+
0
   # inspect
0
   
0
   def test_inspect

Comments

    No one has commented yet.