Skip to content

Adding in the 'ls_remote' command #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Adding in the 'ls_remote' command
  • Loading branch information
iphands committed Feb 6, 2014
commit ab454510d68142c178dd04d4cfe4706c954cd11e
17 changes: 15 additions & 2 deletions lib/git/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,21 @@ def write_and_commit_tree(opts = {})
def update_ref(branch, commit)
branch(branch).update_ref(commit)
end



def ls_remote(location = nil, opts = {})
tmp = self.lib.ls_remote(location, opts)
if (opts[:tags])
ret = []
tmp.each { |line|
split = line.split
short_name = split[1].sub(/refs\/tags\//, '')
obj = {:sha => split[0], :tag_ref => split[1], :name => short_name}
ret.push obj
}
return ret
end
end

def ls_files(location=nil)
self.lib.ls_files(location)
end
Expand Down
9 changes: 8 additions & 1 deletion lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,14 @@ def diff_files
def diff_index(treeish)
diff_as_hash('diff-index', treeish)
end


def ls_remote(location = nil, opts = {})
args = []
args << (opts[:tags] ? '--tags' : '')
args << location
command_lines('ls-remote', args)
end

def ls_files(location=nil)
hsh = {}
command_lines('ls-files', ['--stage', location]).each do |line|
Expand Down
37 changes: 37 additions & 0 deletions tests/units/test_ls_remote.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../test_helper'

class TestRemoteLs < Test::Unit::TestCase
def setup
set_file_paths
end

def test_remote_ls_tags
in_temp_dir do |path|
r1 = Git.clone(@wbare, 'repo1')
r2 = Git.clone(@wbare, 'repo2')

# setup
r1.add_remote('r2', r2)
r1.add_tag('foo_bar_baz')

tags = r1.ls_remote('r2', {:tags => true})
tags.each { |t|
assert_false t.has_value? 'foo_bar_baz'
}

r1.push('origin', 'master', {:tags => true})
r1.push('r2', 'master', {:tags => true})
tags = r1.ls_remote('r2', {:tags => true})

found = false
tags.each { |t|
if t.has_value? 'foo_bar_baz'
found = true
end
}
assert found === true
end
end
end