Class: MultiRepo::CloneCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/multirepo/commands/clone-command.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#ensure_in_work_tree, #ensure_multirepo_enabled, #ensure_multirepo_tracked, #install_hooks, #multirepo_enabled_dependencies, report_error, #uninstall_hooks, #update_gitconfig

Constructor Details

#initialize(argv) ⇒ CloneCommand

Returns a new instance of CloneCommand.



20
21
22
23
24
25
26
# File 'lib/multirepo/commands/clone-command.rb', line 20

def initialize(argv)
  @url = argv.shift_argument
  @name = argv.shift_argument
  @ref_name = argv.shift_argument || "master"
  @here = argv.flag?("here")
  super
end

Class Method Details

.optionsObject



11
12
13
14
15
16
17
18
# File 'lib/multirepo/commands/clone-command.rb', line 11

def self.options
  [
    ['<url>', 'The repository to clone.'],
    ['<name>', 'The name of the containing folder that will be created.'],
    ['[<refname>]', 'The branch, tag or commit id to checkout. Checkout will use "master" if unspecified.'],
    ['[--here]', 'Checkout directly in the current directory instead of creating a new directory to put repos in'],
  ].concat(super)
end

Instance Method Details

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/multirepo/commands/clone-command.rb', line 34

def run
  Console.log_step("Cloning #{@url} ...")

  fail MultiRepoException, "A directory named #{@name} already exists" if Dir.exist?(@name)

  main_repo_path = @here ? "#{@name}" : "#{@name}/#{@name}"
  main_repo = Repo.new(main_repo_path)
  
  # Recursively create the directory where we'll clone the main repo
  FileUtils.mkpath(main_repo_path)
  
  # Clone the specified remote in the just-created directory
  fail MultiRepoException, "Could not clone repo from #{@url}" unless main_repo.clone(@url)
  
  # Checkout the specified main repo ref so that install reads the proper config file
  unless main_repo.checkout(@ref_name)
    fail MultiRepoException, "Couldn't perform checkout of main repo #{@ref_name}!"
  end
  
  Console.log_substep("Checked out main repo #{@ref_name}")
  
  # Make sure the ref we just checked out is tracked by multirepo
  unless Utils.multirepo_tracked?(main_repo_path)
    fail MultiRepoException, "Ref #{@ref_name} is not tracked by multirepo"
  end
  
  # Install
  original_path = Dir.pwd
  Dir.chdir(main_repo_path)
  install_command = InstallCommand.new(CLAide::ARGV.new([]))
  install_command.full_install
  Dir.chdir(original_path)
  
  Console.log_step("Done!")
end

#validate!Object



28
29
30
31
32
# File 'lib/multirepo/commands/clone-command.rb', line 28

def validate!
  super
  help! "You must specify a repository to clone" unless @url
  help! "You must specify a containing folder name" unless @name
end