lib/braid/operations.rb in evilchelu-braid-0.4.11 vs lib/braid/operations.rb in evilchelu-braid-0.4.12

- old
+ new

@@ -12,17 +12,18 @@ def message @err.to_s.split("\n").first end end class VersionTooLow < BraidError - def initialize(command, version) + def initialize(command, version, required) @command = command @version = version.to_s.split("\n").first + @required = required end def message - "#{@command} version too low: #{@version}" + "#{@command} version too low: #{@version}. #{@required} needed." end end class UnknownRevision < BraidError def message "unknown revision: #{super}" @@ -31,16 +32,26 @@ class LocalChangesPresent < BraidError def message "local changes are present" end end + class LocalCacheDirBroken < BraidError + def initialize(dir) + @dir = dir + end + def message + "Local cache '#{@dir}' needs to be recreated. Remove the directory and run the command again." + end + end + # The command proxy is meant to encapsulate commands such as git, git-svn and svn, that work with subcommands. class Proxy include Singleton def self.command; name.split('::').last.downcase; end # hax! + def self.verbose; Braid::Operations::VERBOSE ; end def version status, out, err = exec!("#{self.class.command} --version") out.sub(/^.* version/, "").strip end @@ -66,11 +77,11 @@ return actual.length >= required.length end def require_version!(required) - require_version(required) || raise(VersionTooLow.new(self.class.command, version)) + require_version(required) || raise(VersionTooLow.new(self.class.command, version, required)) end private def command(name) # stub @@ -90,10 +101,11 @@ previous_lang = ENV['LANG'] ENV['LANG'] = 'C' out, err = nil + puts "executing cmd(#{cmd})" if Proxy.verbose status = Open4.popen4(cmd) do |pid, stdin, stdout, stderr| out = stdout.read err = stderr.read end.exitstatus [status, out, err] @@ -127,11 +139,11 @@ end end def fetch(remote) # open4 messes with the pipes of index-pack - system("git fetch -n #{remote} &> /dev/null") + system("git fetch -n #{remote} 2>&1 >/dev/null") raise ShellExecutionError, "could not fetch" unless $? == 0 true end def checkout(treeish) @@ -252,11 +264,11 @@ Git.instance.rev_parse(part) # FIXME ugly ugly ugly end def fetch(remote) # open4 messes with the pipes of index-pack - system("git svn fetch #{remote} &> /dev/null") + system("git svn fetch #{remote} 2>&1 >/dev/null") raise ShellExecutionError, "could not fetch" unless $? == 0 true end def init(remote, path) @@ -284,18 +296,23 @@ end class GitCache < Proxy def init_or_fetch(url, dir) if File.exists? dir + # bail if the local cache was created with --no-checkout + if File.exists? "#{dir}/.git" + raise LocalCacheDirBroken.new(dir) + end + msg "Updating local cache of '#{url}' into '#{dir}'." FileUtils.cd(dir) do |d| status, out, err = exec!("git fetch") end else FileUtils.mkdir_p(Braid::LOCAL_CACHE_DIR) msg "Caching '#{url}' into '#{dir}'." - status, out, err = exec!("git clone --no-checkout #{url} #{dir}") + status, out, err = exec!("git clone --mirror #{url} #{dir}") end end end module VersionControl