0
class ShellExecutionError < BraidError
0
+ def initialize(err = nil)
0
+ @err.to_s.split("\n").first
0
+ class VersionTooLow < BraidError
0
+ def initialize(command, version)
0
+ @version = version.to_s.split("\n").first
0
+ "#{@command} version too low: #{@version}"
0
+ class UnknownRevision < BraidError
0
+ "unknown revision: #{super}"
0
- class VersionError < BraidError
0
+ class LocalChangesPresent < BraidError
0
+ "local changes are present"
0
- # The command proxy is meant to encapsulate commands such as git, git svn and svn, that work with subcommands.
0
- # It is expected that subclasses override the command method, define a COMMAND constant and have a VersionTooLow exception.
0
+ # The command proxy is meant to encapsulate commands such as git, git-svn and svn, that work with subcommands.
0
+ def self.command; name.split('::').last.downcase; end # hax!
0
- status, out, err = exec!("#{self.class
::COMMAND} --version")
0
+ status, out, err = exec!("#{self.class
.command} --version")
0
out.sub(/^.* version/, "").strip
0
@@ -40,7 +68,7 @@ module Braid
0
def require_version!(required)
0
- require_version(required) || raise(
self.class::VersionTooLow, version)
0
+ require_version(required) || raise(
VersionTooLow.new(self.class.command, version))
0
@@ -50,7 +78,7 @@ module Braid
0
- exec!("#{command(arg)} #{args.join(' ')}".strip)[1]
# return stdout
0
+ exec!("#{command(arg)} #{args.join(' ')}".strip)[1]
.strip # return stdout
0
def method_missing(name, *args)
0
@@ -65,8 +93,8 @@ module Braid
0
status = Open4.popen4(cmd) do |pid, stdin, stdout, stderr|
0
- out = stdout.read.strip
0
- err = stderr.read.strip
0
@@ -81,18 +109,9 @@ module Braid
0
- class Git < CommandProxy
0
- class UnknownRevision < BraidError
0
- class LocalChangesPresent < BraidError
0
- class VersionTooLow < VersionError
0
- status, out, err = exec("git commit -m #{message.inspect} --no-verify")
0
+ def commit(message, *args)
0
+ status, out, err = exec("git commit -m #{message.inspect} --no-verify #{args.join(' ')}")
0
@@ -106,7 +125,7 @@ module Braid
0
# open4 messes with the pipes of index-pack
0
system("git fetch -n #{remote} &> /dev/null")
0
- raise ShellExecutionError
unless $? == 0
0
+ raise ShellExecutionError
, "could not fetch" unless $? == 0
0
@@ -200,40 +219,38 @@ module Braid
0
- status = Open4.popen4("git apply --index -") do |pid, stdin, stdout, stderr|
0
+ def apply(diff, *args)
0
+ status = Open4.popen4("git apply --index --whitespace=nowarn #{args.join(' ')} -") do |pid, stdin, stdout, stderr|
0
- raise ShellExecutionError
unless status == 0
0
+ raise ShellExecutionError
, err unless status == 0
0
- "#{
COMMAND} #{name.to_s.gsub('_', '-')}"
0
+ "#{
self.class.command} #{name.to_s.gsub('_', '-')}"
0
- class GitSvn < CommandProxy
0
- class UnknownRevision < BraidError
0
- class VersionTooLow < VersionError
0
+ def self.command; "git svn"; end
0
def commit_hash(remote, revision)
0
out = invoke(:log, "--show-commit --oneline", "-r #{revision}", remote)
0
- part = out.split(" | ")[1]
0
- raise UnknownRevision, "unknown revision: #{revision}" unless part
0
- Git.new.rev_parse(part) # FIXME ugly ugly ugly
0
+ part = out.to_s.split(" | ")[1]
0
+ raise UnknownRevision, "r#{revision}" unless part
0
+ Git.instance.rev_parse(part) # FIXME ugly ugly ugly
0
# open4 messes with the pipes of index-pack
0
system("git svn fetch #{remote} &> /dev/null")
0
+ raise ShellExecutionError, "could not fetch" unless $? == 0
0
@@ -244,13 +261,11 @@ module Braid
0
+ "#{
self.class.command} #{name}"
0
- class Svn < CommandProxy
0
def clean_revision(revision)
0
revision.to_i if revision
0
@@ -264,18 +279,19 @@ module Braid