lib/braid/mirror.rb in braid-1.0.15 vs lib/braid/mirror.rb in braid-1.0.16

- old
+ new

@@ -1,8 +1,8 @@ module Braid class Mirror - ATTRIBUTES = %w(url branch squashed revision lock) + ATTRIBUTES = %w(url branch squashed revision lock remote_path) class UnknownType < BraidError def message "unknown type: #{super}" end @@ -30,11 +30,13 @@ path = (options['path'] || extract_path_from_url(url)).sub(/\/$/, '') raise PathRequired unless path squashed = !options['full'] - attributes = {'url' => url, 'branch' => branch, 'squashed' => squashed} + remote_path = options['remote_path'] + + attributes = {'url' => url, 'branch' => branch, 'squashed' => squashed, 'remote_path' => remote_path} self.new(path, attributes) end def ==(comparison) path == comparison.path && attributes == comparison.attributes @@ -57,13 +59,17 @@ else git.merge_base(commit, 'HEAD') == commit end end + def versioned_path(revision) + "#{revision}:#{self.remote_path}" + end + def diff fetch - remote_hash = git.rev_parse("#{base_revision}:") + remote_hash = git.rev_parse(versioned_path(base_revision)) local_hash = git.tree_hash(path) remote_hash != local_hash ? git.diff_tree(remote_hash, local_hash) : '' end def fetch @@ -93,14 +99,14 @@ private def method_missing(name, *args) if ATTRIBUTES.find { |attribute| name.to_s =~ /^(#{attribute})(=)?$/ } - unless $2 - attributes[$1] - else + if $2 attributes[$1] = args[0] + else + attributes[$1] end else raise NameError, "unknown attribute `#{name}'" end end @@ -111,10 +117,11 @@ chunk.split("\n", 2).map { |value| value.strip } end hash = nil local_commits.each do |local_commit| local_tree = git.tree_hash(path, local_commit) - if match = remote_hashes.find { |_, remote_tree| local_tree == remote_tree } + match = remote_hashes.find { |_, remote_tree| local_tree == remote_tree } + if match hash = match[0] break end end hash