Class: Makit::Cli::CloneRepositoryCommand

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/makit/cli/repository_commands.rb

Overview

Clone repository to local directory

Instance Method Summary collapse

Instance Method Details

#executeObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/makit/cli/repository_commands.rb', line 145

def execute
  clone_dir = Makit::Directories.get_clone_directory(git_repository)

  if Dir.exist?(clone_dir)
    puts "Repository already exists at: #{clone_dir}"
    return
  end

  puts "Cloning repository: #{git_repository} to #{clone_dir}"

  begin
    commands = Makit.clone(git_repository)

    if commands.any? && commands.last.exit_code != 0
      handle_clone_error(commands.last, clone_dir)
    elsif !Dir.exist?(clone_dir)
      warn "Clone operation completed but directory not found: #{clone_dir}"
      exit 1
    else
      puts "Successfully cloned repository to: #{clone_dir}"
    end
  rescue ArgumentError => e
    warn "Invalid repository URL: #{e.message}"
    exit 1
  rescue StandardError => e
    warn "Failed to clone repository: #{git_repository}"
    puts e.message
    exit 1
  end
end