Commits

Yuya Nishihara committed 6004ae6

add support for paths command

  • Participants
  • Parent commits 385cc17

Comments (0)

Files changed (2)

lib/hglib/commander.rb

                          :pull, :push, :recover, :remove, :rename, :revert,
                          :rollback, :tag, :unbundle, :update, :verify)
     # TODO: bisect, bookmarks, branch, export, grep, identify
-    # paths, phase, resolve, serve, showconfig, status, summary
+    # phase, resolve, serve, showconfig, status, summary
 
     # Fetches line-by-line annotation of files
     def annotate(*pats)  #:yields: changeid, line_content
       changesets
     end
 
+    # Fetches aliases for remote repositories as Hash map.
+    #
+    # Unlinke Mercurial's +paths+ command, this does not support +name+
+    # parameter by intention. Use paths[name] instead.
+    def paths
+      aliases = {}
+      raw_command_with_buffer ChunkBuffer.new, 'paths' do |line|
+        name, url = line.split(' = ', 2)
+        raise OutputParseError, 'unparsable paths output' unless url
+        aliases[name] = url
+      end
+      aliases
+    end
+
     # Fetches the root path of the target repository
     def root
       raw_command('root').chop

test/test_commander.rb

     end
   end
 
+  def test_paths
+    open 'mergedrepo' do |hg|
+      aliases = hg.paths
+      assert_equal %w|default|, aliases.keys
+      assert_equal 'multiheadsrepo', aliases['default'].split('/')[-1]
+    end
+  end
+
+  def test_paths_empty
+    open 'multiheadsrepo' do |hg|
+      aliases = hg.paths
+      assert aliases.empty?
+    end
+  end
+
   def test_root
     open 'emptyrepo' do |hg|
       assert_equal File.expand_path(hg.client_path), File.expand_path(hg.root)