lib/braid/mirror.rb in realityforge-braid-0.9.4 vs lib/braid/mirror.rb in realityforge-braid-0.9.5
- old
+ new
@@ -7,11 +7,11 @@
"unknown type: #{super}"
end
end
class PathRequired < BraidError
def message
- "path is required"
+ 'path is required'
end
end
include Operations::VersionControl
@@ -23,20 +23,20 @@
end
def self.new_from_options(url, options = {})
url = url.sub(/\/$/, '')
- branch = options["branch"] || "master"
+ branch = options['branch'] || 'master'
- unless path = options["path"] || extract_path_from_url(url)
+ unless path = options['path'] || extract_path_from_url(url)
raise PathRequired
end
remote = "#{branch}/braid/#{path}"
- squashed = !options["full"]
+ squashed = !options['full']
- attributes = {"url" => url, "remote" => remote, "branch" => branch, "squashed" => squashed}
+ attributes = {'url' => url, 'remote' => remote, 'branch' => branch, 'squashed' => squashed}
self.new(path, attributes)
end
def ==(comparison)
path == comparison.path && attributes == comparison.attributes
@@ -55,18 +55,19 @@
# `test z$(git merge-base A B) = z$(git rev-parse --verify A)`
commit = git.rev_parse(commit)
if squashed?
!!base_revision && git.merge_base(commit, base_revision) == commit
else
- git.merge_base(commit, "HEAD") == commit
+ git.merge_base(commit, 'HEAD') == commit
end
end
def diff
+ fetch
remote_hash = git.rev_parse("#{base_revision}:")
local_hash = git.tree_hash(path)
- remote_hash != local_hash ? git.diff_tree(remote_hash, local_hash) : ""
+ remote_hash != local_hash ? git.diff_tree(remote_hash, local_hash) : ''
end
def fetch
git_cache.fetch(url) if cached?
git.fetch(remote)
@@ -87,14 +88,14 @@
def cached_url
git_cache.path(url)
end
def remote
- if (attributes["remote"] && attributes["remote"] =~ /^braid\//)
- attributes["remote"] = "#{branch}/#{attributes["remote"]}"
+ if (attributes['remote'] && attributes['remote'] =~ /^braid\//)
+ attributes['remote'] = "#{branch}/#{attributes['remote']}"
else
- attributes["remote"]
+ attributes['remote']
end
end
private
@@ -109,12 +110,12 @@
raise NameError, "unknown attribute `#{name}'"
end
end
def inferred_revision
- local_commits = git.rev_list("HEAD", "-- #{path}").split("\n")
- remote_hashes = git.rev_list("--pretty=format:\"%T\"", remote).split("commit ").map do |chunk|
+ local_commits = git.rev_list('HEAD', "-- #{path}").split("\n")
+ remote_hashes = git.rev_list("--pretty=format:\"%T\"", remote).split('commit ').map do |chunk|
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)
@@ -128,15 +129,12 @@
def self.extract_path_from_url(url)
return nil unless url
name = File.basename(url)
- if File.extname(name) == ".git"
+ if File.extname(name) == '.git'
# strip .git
name[0..-5]
- elsif name == "trunk"
- # use parent
- File.basename(File.dirname(url))
else
name
end
end
end