File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -367,6 +367,18 @@ def ls_files(location=nil)
367
367
hsh
368
368
end
369
369
370
+ def ls_remote ( location = nil )
371
+ Hash . new { |h , k | h [ k ] = { } } . tap do |hsh |
372
+ command_lines ( 'ls-remote' , [ location ] , false ) . each do |line |
373
+ ( sha , info ) = line . split ( "\t " )
374
+ ( ref , type , name ) = info . split ( '/' , 3 )
375
+ type ||= 'head'
376
+ type = 'branches' if type == 'heads'
377
+ value = { :ref => ref , :sha => sha }
378
+ hsh [ type ] . update ( name . nil? ? value : { name => value } )
379
+ end
380
+ end
381
+ end
370
382
371
383
def ignored_files
372
384
command_lines ( 'ls-files' , [ '--others' , '-i' , '--exclude-standard' ] )
Original file line number Diff line number Diff line change @@ -149,6 +149,23 @@ def test_ls_tree
149
149
assert ( tree [ 'tree' ] )
150
150
end
151
151
152
+ def test_ls_remote
153
+ in_temp_dir do |path |
154
+ lib = Git ::Lib . new
155
+ ls = lib . ls_remote ( @wbare )
156
+
157
+ assert_equal ( %w( gitsearch1 v2.5 v2.6 v2.7 v2.8 ) , ls [ 'tags' ] . keys )
158
+ assert_equal ( "935badc874edd62a8629aaf103418092c73f0a56" , ls [ 'tags' ] [ 'gitsearch1' ] [ :sha ] )
159
+
160
+ assert_equal ( %w( git_grep master test test_branches test_object ) , ls [ 'branches' ] . keys )
161
+ assert_equal ( "5e392652a881999392c2757cf9b783c5d47b67f7" , ls [ 'branches' ] [ 'master' ] [ :sha ] )
162
+
163
+ assert_equal ( "HEAD" , ls [ 'head' ] [ :ref ] )
164
+ assert_equal ( "5e392652a881999392c2757cf9b783c5d47b67f7" , ls [ 'head' ] [ :sha ] )
165
+ assert_equal ( nil , ls [ 'head' ] [ :name ] )
166
+ end
167
+ end
168
+
152
169
153
170
# options this will accept
154
171
# :treeish
You can’t perform that action at this time.
0 commit comments