class OhlohScm::GitSvn::Scm

Public Class Methods

new(core:, url:, branch_name:, username:, password:) click to toggle source
Calls superclass method OhlohScm::Scm::new
# File lib/ohloh_scm/git_svn/scm.rb, line 6
def initialize(core:, url:, branch_name:, username:, password:)
  super
  @branch_name = branch_name || :master
end

Public Instance Methods

accept_ssl_certificate_cmd() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 16
def accept_ssl_certificate_cmd
  File.expand_path('../../../.bin/accept_svn_ssl_certificate', __dir__)
end
pull(source_scm, callback) click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 11
def pull(source_scm, callback)
  @source_scm = source_scm
  convert_to_git(callback)
end
vcs_path() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 20
def vcs_path
  "#{url}/.git"
end

Private Instance Methods

accept_certificate_if_prompted() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 52
def accept_certificate_if_prompted
  # git svn does not support non iteractive and serv-certificate options
  # Permanently accept svn certificate when it prompts
  opts = username_and_password_opts
  run "#{accept_ssl_certificate_cmd} svn info #{opts} '#{@source_scm.url}'"
end
clean_up_disk() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 83
def clean_up_disk
  return unless  File.exist?(url)

  run "cd #{url} && find . -maxdepth 1 -not -name .git -not -name . -print0"\
        ' | xargs -0 rm -rf --'
end
clone() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 43
def clone
  prepare_dest_dir
  accept_certificate_if_prompted

  cmd = "#{password_prompt} git svn clone --quiet #{username_opts}"\
          " '#{@source_scm.url}' '#{url}'"
  run(cmd)
end
convert_to_git(callback) click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 26
def convert_to_git(callback)
  callback.update(0, 1)
  if FileTest.exist?(git_path)
    accept_certificate_if_prompted
    fetch
  else
    clone
  end

  clean_up_disk
  callback.update(1, 1)
end
fetch() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 78
def fetch
  cmd = "cd #{url} && git svn fetch"
  run(cmd)
end
git_path() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 39
def git_path
  File.join(url, '/.git')
end
password_prompt() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 65
def password_prompt
  password.to_s.empty? ? '' : "echo #{password} |"
end
prepare_dest_dir() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 73
def prepare_dest_dir
  FileUtils.mkdir_p(url)
  FileUtils.rm_rf(url)
end
username_and_password_opts() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 59
def username_and_password_opts
  username = username.to_s.empty? ? '' : "--username #{@source_scm.username}"
  password = password.to_s.empty? ? '' : "--password='#{@source_scm.password}'"
  "#{username} #{password}"
end
username_opts() click to toggle source
# File lib/ohloh_scm/git_svn/scm.rb, line 69
def username_opts
  username.to_s.empty? ? '' : "--username #{username}"
end