File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -304,6 +304,18 @@ def ls_files(location=nil)
304
304
hsh
305
305
end
306
306
307
+ def ls_remote ( location = nil )
308
+ Hash . new { |h , k | h [ k ] = { } } . tap do |hsh |
309
+ command_lines ( 'ls-remote' , [ location ] , false ) . each do |line |
310
+ ( sha , info ) = line . split ( "\t " )
311
+ ( ref , type , name ) = info . split ( '/' , 3 )
312
+ type ||= 'head'
313
+ type = 'branches' if type == 'heads'
314
+ value = { :ref => ref , :sha => sha }
315
+ hsh [ type ] . update ( name . nil? ? value : { name => value } )
316
+ end
317
+ end
318
+ end
307
319
308
320
def ignored_files
309
321
command_lines ( 'ls-files' , [ '--others' , '-i' , '--exclude-standard' ] )
Original file line number Diff line number Diff line change @@ -137,6 +137,23 @@ def test_ls_tree
137
137
assert ( tree [ 'tree' ] )
138
138
end
139
139
140
+ def test_ls_remote
141
+ in_temp_dir do |path |
142
+ lib = Git ::Lib . new
143
+ ls = lib . ls_remote ( @wbare )
144
+
145
+ assert_equal ( %w( gitsearch1 v2.5 v2.6 v2.7 v2.8 ) , ls [ 'tags' ] . keys )
146
+ assert_equal ( "935badc874edd62a8629aaf103418092c73f0a56" , ls [ 'tags' ] [ 'gitsearch1' ] [ :sha ] )
147
+
148
+ assert_equal ( %w( git_grep master test test_branches test_object ) , ls [ 'branches' ] . keys )
149
+ assert_equal ( "5e392652a881999392c2757cf9b783c5d47b67f7" , ls [ 'branches' ] [ 'master' ] [ :sha ] )
150
+
151
+ assert_equal ( "HEAD" , ls [ 'head' ] [ :ref ] )
152
+ assert_equal ( "5e392652a881999392c2757cf9b783c5d47b67f7" , ls [ 'head' ] [ :sha ] )
153
+ assert_equal ( nil , ls [ 'head' ] [ :name ] )
154
+ end
155
+ end
156
+
140
157
141
158
# options this will accept
142
159
# :treeish
@@ -165,4 +182,4 @@ def test_grep
165
182
assert_equal ( 2 , match . size )
166
183
end
167
184
168
- end
185
+ end
You can’t perform that action at this time.
0 commit comments