Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,18 @@ def ls_files(location=nil)
hsh
end

def ls_remote(location=nil)
Hash.new{ |h,k| h[k] = {} }.tap do |hsh|
command_lines('ls-remote', [location], false).each do |line|
(sha, info) = line.split("\t")
(ref, type, name) = info.split('/', 3)
type ||= 'head'
type = 'branches' if type == 'heads'
value = {:ref => ref, :sha => sha}
hsh[type].update( name.nil? ? value : { name => value })
end
end
end

def ignored_files
command_lines('ls-files', ['--others', '-i', '--exclude-standard'])
Expand Down
19 changes: 18 additions & 1 deletion tests/units/test_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ def test_ls_tree
assert(tree['tree'])
end

def test_ls_remote
in_temp_dir do |path|
lib = Git::Lib.new
ls = lib.ls_remote(@wbare)

assert_equal(%w( gitsearch1 v2.5 v2.6 v2.7 v2.8 ), ls['tags'].keys)
assert_equal("935badc874edd62a8629aaf103418092c73f0a56", ls['tags']['gitsearch1'][:sha])

assert_equal(%w( git_grep master test test_branches test_object ), ls['branches'].keys)
assert_equal("5e392652a881999392c2757cf9b783c5d47b67f7", ls['branches']['master'][:sha])

assert_equal("HEAD", ls['head'][:ref])
assert_equal("5e392652a881999392c2757cf9b783c5d47b67f7", ls['head'][:sha])
assert_equal(nil, ls['head'][:name])
end
end


# options this will accept
# :treeish
Expand Down Expand Up @@ -165,4 +182,4 @@ def test_grep
assert_equal(2, match.size)
end

end
end