Skip to content

Commit ab45451

Browse files
committed
Adding in the 'ls_remote' command
1 parent 41d9e3e commit ab45451

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

lib/git/base.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,21 @@ def write_and_commit_tree(opts = {})
504504
def update_ref(branch, commit)
505505
branch(branch).update_ref(commit)
506506
end
507-
508-
507+
508+
def ls_remote(location = nil, opts = {})
509+
tmp = self.lib.ls_remote(location, opts)
510+
if (opts[:tags])
511+
ret = []
512+
tmp.each { |line|
513+
split = line.split
514+
short_name = split[1].sub(/refs\/tags\//, '')
515+
obj = {:sha => split[0], :tag_ref => split[1], :name => short_name}
516+
ret.push obj
517+
}
518+
return ret
519+
end
520+
end
521+
509522
def ls_files(location=nil)
510523
self.lib.ls_files(location)
511524
end

lib/git/lib.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,14 @@ def diff_files
305305
def diff_index(treeish)
306306
diff_as_hash('diff-index', treeish)
307307
end
308-
308+
309+
def ls_remote(location = nil, opts = {})
310+
args = []
311+
args << (opts[:tags] ? '--tags' : '')
312+
args << location
313+
command_lines('ls-remote', args)
314+
end
315+
309316
def ls_files(location=nil)
310317
hsh = {}
311318
command_lines('ls-files', ['--stage', location]).each do |line|

tests/units/test_ls_remote.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env ruby
2+
3+
require File.dirname(__FILE__) + '/../test_helper'
4+
5+
class TestRemoteLs < Test::Unit::TestCase
6+
def setup
7+
set_file_paths
8+
end
9+
10+
def test_remote_ls_tags
11+
in_temp_dir do |path|
12+
r1 = Git.clone(@wbare, 'repo1')
13+
r2 = Git.clone(@wbare, 'repo2')
14+
15+
# setup
16+
r1.add_remote('r2', r2)
17+
r1.add_tag('foo_bar_baz')
18+
19+
tags = r1.ls_remote('r2', {:tags => true})
20+
tags.each { |t|
21+
assert_false t.has_value? 'foo_bar_baz'
22+
}
23+
24+
r1.push('origin', 'master', {:tags => true})
25+
r1.push('r2', 'master', {:tags => true})
26+
tags = r1.ls_remote('r2', {:tags => true})
27+
28+
found = false
29+
tags.each { |t|
30+
if t.has_value? 'foo_bar_baz'
31+
found = true
32+
end
33+
}
34+
assert found === true
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)