Class: MGit::CloneCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/mgit/commands/clone.rb

Instance Method Summary collapse

Methods inherited from Command

#check_arity, create, execute, instance_each, list, load_commands, register_alias, register_command, require_commands_from_directory

Methods included from Output

#perror, #pinfo, #psystem, #ptable, #pwarn

Instance Method Details

#arityObject



17
18
19
# File 'lib/mgit/commands/clone.rb', line 17

def arity
  [1, nil]
end

#descriptionObject



25
26
27
# File 'lib/mgit/commands/clone.rb', line 25

def description
  'clone repository and add to mgit'
end

#execute(args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mgit/commands/clone.rb', line 3

def execute(args)
  log = System.git("clone #{args.join(' ')}", raise: true)

  m = [log.stdout, log.stderr].find do |l|
    f = l.split("\n").first
    f && f.start_with?('Cloning into')
  end

  d = /Cloning into '(.*)'/.match(m)
  fail 'Failed to determine repository directory.' unless d

  Command.execute('add', [d[1]])
end

#usageObject



21
22
23
# File 'lib/mgit/commands/clone.rb', line 21

def usage
  'clone [options] <url> [<directory>]'
end