lib/braid/command.rb in braid-0.6.2 vs lib/braid/command.rb in braid-0.7.0
- old
+ new
@@ -12,14 +12,14 @@
klass = Commands.const_get(command.to_s.capitalize)
klass.new.run(*args)
rescue BraidError => error
case error
- when Operations::ShellExecutionError
- msg "Shell error: #{error.message}"
- else
- msg "Error: #{error.message}"
+ when Operations::ShellExecutionError
+ msg "Shell error: #{error.message}"
+ else
+ msg "Error: #{error.message}"
end
exit(1)
end
def self.msg(str)
@@ -37,95 +37,96 @@
def verbose?
Braid.verbose
end
private
- def setup_remote(mirror)
- Command.run(:setup, mirror.path)
- end
- def use_local_cache?
- Braid.use_local_cache
- end
+ def setup_remote(mirror)
+ Command.run(:setup, mirror.path)
+ end
- def self.verify_git_version!
- git.require_version!(REQUIRED_GIT_VERSION)
- end
+ def use_local_cache?
+ Braid.use_local_cache
+ end
- def bail_on_local_changes!
- git.ensure_clean!
- end
+ def self.verify_git_version!
+ git.require_version!(REQUIRED_GIT_VERSION)
+ end
- def with_reset_on_error
- work_head = git.head
+ def bail_on_local_changes!
+ git.ensure_clean!
+ end
- begin
- yield
- rescue => error
- msg "Resetting to '#{work_head[0, 7]}'."
- git.reset_hard(work_head)
- raise error
- end
- end
+ def with_reset_on_error
+ work_head = git.head
- def load_and_migrate_config
- config = Config.new
- unless config.valid?
- msg "Configuration is outdated. Migrating."
- bail_on_local_changes!
- config.migrate!
- git.commit("Upgrade .braids", "-- .braids")
- end
- config
+ begin
+ yield
+ rescue => error
+ msg "Resetting to '#{work_head[0, 7]}'."
+ git.reset_hard(work_head)
+ raise error
end
+ end
- def add_config_file
- git.add(CONFIG_FILE)
+ def load_and_migrate_config
+ config = Config.new
+ unless config.valid?
+ msg "Configuration is outdated. Migrating."
+ bail_on_local_changes!
+ config.migrate!
+ git.commit("Upgrade .braids", "-- .braids")
end
+ config
+ end
- def display_revision(mirror, revision = nil)
- revision ||= mirror.revision
- mirror.type == "svn" ? "r#{revision}" : "'#{revision[0, 7]}'"
- end
+ def add_config_file
+ git.add(CONFIG_FILE)
+ end
- def validate_new_revision(mirror, new_revision)
- unless new_revision
- unless mirror.type == "svn"
- return git.rev_parse(mirror.remote)
- else
- return svn.head_revision(mirror.url)
- end
- end
+ def display_revision(mirror, revision = nil)
+ revision ||= mirror.revision
+ mirror.type == "svn" ? "r#{revision}" : "'#{revision[0, 7]}'"
+ end
+ def validate_new_revision(mirror, new_revision)
+ unless new_revision
unless mirror.type == "svn"
- new_revision = git.rev_parse(new_revision)
+ return git.rev_parse(mirror.remote)
else
- new_revision = svn.clean_revision(new_revision)
+ return svn.head_revision(mirror.url)
end
- old_revision = mirror.revision
+ end
- if new_revision == old_revision
- raise InvalidRevision, "mirror is already at requested revision"
- end
+ unless mirror.type == "svn"
+ new_revision = git.rev_parse(new_revision)
+ else
+ new_revision = svn.clean_revision(new_revision)
+ end
+ old_revision = mirror.revision
- if mirror.type == "svn"
- if old_revision && new_revision < old_revision
- raise InvalidRevision, "local revision is higher than request revision"
- end
+ if new_revision == old_revision
+ raise InvalidRevision, "mirror is already at requested revision"
+ end
- if svn.head_revision(mirror.url) < new_revision
- raise InvalidRevision, "requested revision is higher than remote revision"
- end
+ if mirror.type == "svn"
+ if old_revision && new_revision < old_revision
+ raise InvalidRevision, "local revision is higher than request revision"
end
- new_revision
+ if svn.head_revision(mirror.url) < new_revision
+ raise InvalidRevision, "requested revision is higher than remote revision"
+ end
end
- def determine_target_revision(mirror, new_revision)
- unless mirror.type == "svn"
- git.rev_parse(new_revision)
- else
- git_svn.commit_hash(mirror.remote, new_revision)
- end
+ new_revision
+ end
+
+ def determine_target_revision(mirror, new_revision)
+ unless mirror.type == "svn"
+ git.rev_parse(new_revision)
+ else
+ git_svn.commit_hash(mirror.remote, new_revision)
end
+ end
end
end