diff --git a/README.md b/README.md index aa211006..a2ec0d4c 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,11 @@ Here are the operations that need read permission only. g.show() g.show('HEAD') g.show('v2.8', 'README.md') + + Git.ls_remote('https://github.com/schacon/ruby-git.git') # returns a hash containing the available references of the repo. + Git.ls_remote('/path/to/local/repo') + Git.ls_remote() # same as Git.ls_remote('.') + ``` And here are the operations that will need to write to your git repository. diff --git a/git.gemspec b/git.gemspec index 9dad6b6d..958f144b 100644 --- a/git.gemspec +++ b/git.gemspec @@ -29,6 +29,7 @@ Gem::Specification.new do |s| 'lib/git.rb', 'lib/git/author.rb', 'lib/git/base.rb', + 'lib/git/base/factory.rb', 'lib/git/branch.rb', 'lib/git/branches.rb', 'lib/git/config.rb', diff --git a/lib/git.rb b/lib/git.rb index 7ad1957e..1992dc1d 100644 --- a/lib/git.rb +++ b/lib/git.rb @@ -139,6 +139,15 @@ def self.global_config(name = nil, value = nil) def self.init(working_dir = '.', options = {}) Base.init(working_dir, options) end + + # returns a Hash containing information about the references + # of the target repository + # + # @param [String|NilClass] location the target repository location or nil for '.' + # @return [{String=>Hash}] the available references of the target repo. + def self.ls_remote(location=nil) + Git::Lib.new.ls_remote(location) + end # open an existing git working directory # diff --git a/lib/git/lib.rb b/lib/git/lib.rb index a74072d3..a0c25de6 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -393,6 +393,7 @@ def ls_files(location=nil) end def ls_remote(location=nil) + location ||= '.' Hash.new{ |h,k| h[k] = {} }.tap do |hsh| command_lines('ls-remote', [location], false).each do |line| (sha, info) = line.split("\t")