80 lines
2.3 KiB
Ruby
80 lines
2.3 KiB
Ruby
require_relative "svi/ansi"
|
|
require_relative "svi/cli"
|
|
require_relative "svi/config"
|
|
require_relative "svi/svn_runner"
|
|
require_relative "svi/util"
|
|
require_relative "svi/version"
|
|
require "svi/svi"
|
|
|
|
module Svi
|
|
class << self
|
|
|
|
def checkout(url)
|
|
checkout_directory = []
|
|
if url =~ %r{/([^/]+)/trunk$}
|
|
checkout_directory << $1
|
|
end
|
|
last_checkout_message = ""
|
|
checked_out_paths = []
|
|
clear_message = lambda do
|
|
if last_checkout_message.size > 0
|
|
clear = ""
|
|
lines = (last_checkout_message.size + C.screen_width - 1) / C.screen_width
|
|
if lines > 1
|
|
clear += Ansi.cursor_up(lines - 1)
|
|
end
|
|
clear += Ansi.cursor_back(999)
|
|
clear += Ansi.erase_cursor_to_eos
|
|
$stdout.write(clear)
|
|
last_checkout_message = ""
|
|
end
|
|
end
|
|
SvnRunner.run_svn("checkout", [url] + checkout_directory, allow_interactive: true) do |line|
|
|
if line =~ /^A.{4}(.*)$/
|
|
path = $1
|
|
checked_out_paths << path
|
|
clear_message[]
|
|
last_checkout_message = "Checking out #{path}..."
|
|
$stdout.write(last_checkout_message)
|
|
$stdout.flush
|
|
elsif line =~ /^\sU\s{3}/
|
|
# Ignore the 'U'pdate line of the checkout directory itself.
|
|
elsif line =~ /^Checked out revision (\d+)/
|
|
revision = $1
|
|
clear_message[]
|
|
n_files = 0
|
|
n_directories = 0
|
|
checked_out_paths.uniq.each do |path|
|
|
if File.directory?(path)
|
|
n_directories += 1
|
|
else
|
|
n_files += 1
|
|
end
|
|
end
|
|
$stdout.puts "Checked out revision #{revision}: #{n_files} file#{n_files == 1 ? '' : 's'}, #{n_directories} director#{n_directories == 1 ? 'y' : 'ies'}"
|
|
else
|
|
clear_message[]
|
|
$stdout.puts line
|
|
end
|
|
end
|
|
0
|
|
end
|
|
|
|
def status
|
|
config = Config.new
|
|
SvnRunner.run_svn("status", []) do |line|
|
|
if line =~ %r{^([ACDIMRX\?!~ ])[CM ][L ][\+ ][SX ][KOTB ]..(.+)$}
|
|
action, path = $1, $2
|
|
if action == "?" and Util.is_path_ignored?(path, config)
|
|
# Path is ignored
|
|
else
|
|
puts line
|
|
end
|
|
end
|
|
end
|
|
0
|
|
end
|
|
|
|
end
|
|
end
|