2020-10-10 14:16:11 +02:00
|
|
|
# typed: true
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-23 06:00:17 +02:00
|
|
|
require "system_command"
|
|
|
|
|
2016-12-10 14:20:47 +00:00
|
|
|
module Utils
|
2020-08-23 06:00:17 +02:00
|
|
|
# Helper functions for querying SVN information.
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
module Svn
|
|
|
|
module_function
|
2017-08-24 01:30:29 +05:30
|
|
|
|
2020-08-23 06:00:17 +02:00
|
|
|
def available?
|
|
|
|
version.present?
|
|
|
|
end
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2020-08-23 06:00:17 +02:00
|
|
|
def version
|
|
|
|
return @version if defined?(@version)
|
2020-08-11 18:53:13 +01:00
|
|
|
|
2020-08-23 06:00:17 +02:00
|
|
|
stdout, _, status = system_command(HOMEBREW_SHIMS_PATH/"scm/svn", args: ["--version"], print_stderr: false)
|
|
|
|
@version = status.success? ? stdout.chomp[/svn, version (\d+(?:\.\d+)*)/, 1] : nil
|
|
|
|
end
|
2020-08-11 18:53:13 +01:00
|
|
|
|
2020-08-23 06:00:17 +02:00
|
|
|
def remote_exists?(url)
|
|
|
|
return true unless available?
|
2016-12-10 14:20:47 +00:00
|
|
|
|
2020-08-23 06:00:17 +02:00
|
|
|
# OK to unconditionally trust here because we're just checking if
|
|
|
|
# a URL exists.
|
|
|
|
quiet_system "svn", "ls", url, "--depth", "empty",
|
|
|
|
"--non-interactive", "--trust-server-cert"
|
|
|
|
end
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2020-08-23 06:00:17 +02:00
|
|
|
def clear_version_cache
|
|
|
|
remove_instance_variable(:@version) if defined?(@version)
|
|
|
|
end
|
2016-12-10 14:20:47 +00:00
|
|
|
end
|
|
|
|
end
|