Class: MGit::AddCommand
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
#arity ⇒ Object
15
16
17
|
# File 'lib/mgit/commands/add.rb', line 15
def arity
[1, 2]
end
|
#description ⇒ Object
23
24
25
|
# File 'lib/mgit/commands/add.rb', line 23
def description
'add a repository to mgit'
end
|
#execute(args) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/mgit/commands/add.rb', line 3
def execute(args)
path = File.expand_path(args[0])
fail CommandUsageError.new('First argument must be a path to a directory.', self) unless File.directory?(path)
fail CommandUsageError.new('First argument must be a path to a git repository.', self) unless git_dir?(path)
fail CommandUsageError.new('Sorry, mgit can not handle bare repositories.', self) if bare?(path)
name = (args.size == 2) ? args[1] : File.basename(path)
fail CommandUsageError.new("Repository named #{name} already exists with different path.", self) unless new_or_same?(name, path)
Registry.add(name, path)
end
|
#usage ⇒ Object
19
20
21
|
# File 'lib/mgit/commands/add.rb', line 19
def usage
'add <path_to_git_repository> [name]'
end
|