mgit 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/mgit/cli.rb +3 -2
- data/lib/mgit/command.rb +24 -8
- data/lib/mgit/commands/add.rb +11 -4
- data/lib/mgit/commands/clone.rb +32 -0
- data/lib/mgit/commands/fetch.rb +4 -2
- data/lib/mgit/commands/ffmerge.rb +4 -2
- data/lib/mgit/commands/foreach.rb +4 -2
- data/lib/mgit/commands/grep.rb +4 -3
- data/lib/mgit/commands/help.rb +4 -2
- data/lib/mgit/commands/list.rb +4 -2
- data/lib/mgit/commands/log.rb +4 -0
- data/lib/mgit/commands/remove.rb +4 -3
- data/lib/mgit/commands/status.rb +4 -2
- data/lib/mgit/commands/version.rb +4 -1
- data/lib/mgit/exceptions.rb +10 -0
- data/lib/mgit/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjEzMDA0N2Y1ODg5MDZmMmJiYmY4YTMxNjkwOGY4NGE2NTVmYWE2Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjA2NTMwODQ0MGQ5YjA1MmM1ZDhhOWMxYTY0MmY0ZjM0ZDQxN2NhOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzMwMDJmODQ1YTMyOTEyZjg3NmQwODY4ZjhiNWYwOTMxYmVjMDhjMDU3MjJh
|
10
|
+
NGYwNTNhYzA3NTRmZGQ0MTMwZmRhYTFmMGFjNTM1OGY4MjExYjUyY2VjZTg2
|
11
|
+
YTc1YmI5M2MxZDBkZWE2YTc5ZDE2MzI0YmJjOWQ5NjMxZTgzOTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTIwMWFiMWIzMDQ2NjE4Nzk0YjQ5OWFhMTFiMmU0MmMxZWY4YTk3YmI1MTFl
|
14
|
+
MDI3OTE5NzNmMDhlMDliOGVhODRjNzU1MTcyM2M0NGVhZDdiZjcyNmE4NzNh
|
15
|
+
NDQ1YjNmYTA4ZDQ3NDE5Yzc2OWJmMGViNWI5YTViNTFiN2U1MjQ=
|
data/lib/mgit/cli.rb
CHANGED
@@ -2,10 +2,11 @@ module MGit
|
|
2
2
|
class CLI
|
3
3
|
def start
|
4
4
|
raise NoCommandError if ARGV.size == 0
|
5
|
-
command = Command.
|
6
|
-
command.execute(ARGV)
|
5
|
+
command = Command.execute(ARGV.shift, ARGV)
|
7
6
|
rescue UsageError => e
|
8
7
|
$stderr.puts e
|
8
|
+
rescue GitError => e
|
9
|
+
$stderr.puts e
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
data/lib/mgit/command.rb
CHANGED
@@ -3,14 +3,14 @@ module MGit
|
|
3
3
|
@@commands = {}
|
4
4
|
@@aliases = {}
|
5
5
|
|
6
|
-
def self.
|
7
|
-
cmd =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
def self.execute(name, args)
|
7
|
+
cmd = self.create(name)
|
8
|
+
|
9
|
+
arity_min, arity_max = cmd.arity
|
10
|
+
raise TooFewArgumentsError.new(cmd) if arity_min && args.size < arity_min
|
11
|
+
raise TooManyArgumentsError.new(cmd) if arity_max && args.size > arity_max
|
12
|
+
|
13
|
+
cmd.execute(args)
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.register_command(cmd)
|
@@ -31,6 +31,10 @@ module MGit
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def arity
|
35
|
+
raise ImplementationError.new("Command #{self.class.name} doesn't implement the arity method.")
|
36
|
+
end
|
37
|
+
|
34
38
|
def usage
|
35
39
|
raise ImplementationError.new("Command #{self.class.name} doesn't implement the usage method.")
|
36
40
|
end
|
@@ -42,5 +46,17 @@ module MGit
|
|
42
46
|
def description
|
43
47
|
raise ImplementationError.new("Command #{self.class.name} doesn't implement the description method.")
|
44
48
|
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def self.create(cmd)
|
53
|
+
cmd = cmd.downcase.to_sym
|
54
|
+
klass = @@commands[cmd] || @@aliases[cmd]
|
55
|
+
if klass
|
56
|
+
klass.new
|
57
|
+
else
|
58
|
+
raise UnknownCommandError.new(cmd)
|
59
|
+
end
|
60
|
+
end
|
45
61
|
end
|
46
62
|
end
|
data/lib/mgit/commands/add.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
module MGit
|
2
2
|
class AddCommand < Command
|
3
3
|
def execute(args)
|
4
|
-
raise TooFewArgumentsError.new(self) if args.size == 0
|
5
|
-
raise TooManyArgumentsError.new(self) if args.size > 2
|
6
|
-
|
7
4
|
path = File.expand_path(args[0])
|
8
5
|
raise CommandUsageError.new('First argument must be a path to a git repository.', self) unless is_git_dir?(path)
|
9
6
|
|
10
7
|
name = (args.size == 2) ? args[1] : (ask('Name of the repository? ') { |q| q.default = File.basename(path) })
|
11
|
-
|
8
|
+
raise CommandUsageError.new("Repository named #{name} already exists with different path.", self) unless is_new_or_same?(name, path)
|
9
|
+
|
12
10
|
Registry.add(name, path)
|
13
11
|
end
|
14
12
|
|
13
|
+
def arity
|
14
|
+
[1, 2]
|
15
|
+
end
|
16
|
+
|
15
17
|
def usage
|
16
18
|
'add <path_to_git_repository> [name]'
|
17
19
|
end
|
@@ -24,6 +26,11 @@ module MGit
|
|
24
26
|
|
25
27
|
private
|
26
28
|
|
29
|
+
def is_new_or_same?(name, path)
|
30
|
+
repo = Registry.find { |r| r.name == name }
|
31
|
+
repo.nil? || repo.path == path
|
32
|
+
end
|
33
|
+
|
27
34
|
def is_git_dir?(path)
|
28
35
|
File.directory?(path) && (File.directory?(File.join(path, '.git')) || File.file?(File.join(path, 'HEAD')))
|
29
36
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module MGit
|
2
|
+
class CloneCommand < Command
|
3
|
+
def execute(args)
|
4
|
+
log = `git clone #{args.join(' ')}`
|
5
|
+
raise GitError.new('Clone command failed.') if $?.exitstatus != 0
|
6
|
+
|
7
|
+
m = /Cloning into '(.*)'/.match(log.split("\n").first)
|
8
|
+
puts m[1]
|
9
|
+
Command.execute('add', [m[1]])
|
10
|
+
end
|
11
|
+
|
12
|
+
def arity
|
13
|
+
[1, nil]
|
14
|
+
end
|
15
|
+
|
16
|
+
def usage
|
17
|
+
'clone [options] <url> [<directory>]'
|
18
|
+
end
|
19
|
+
|
20
|
+
def description
|
21
|
+
'clone repository and add to mgit'
|
22
|
+
end
|
23
|
+
|
24
|
+
register_command :clone
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def option?(arg)
|
29
|
+
arg.start_with?('-')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/mgit/commands/fetch.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module MGit
|
2
2
|
class FetchCommand < Command
|
3
3
|
def execute(args)
|
4
|
-
raise TooManyArgumentsError.new(self) if args.size != 0
|
5
|
-
|
6
4
|
Registry.chdir_each do |repo|
|
7
5
|
`git remote`.split.each do |remote|
|
8
6
|
puts "Fetching #{remote} in repository #{repo.name}...".yellow
|
@@ -11,6 +9,10 @@ module MGit
|
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
12
|
+
def arity
|
13
|
+
[nil, 0]
|
14
|
+
end
|
15
|
+
|
14
16
|
def usage
|
15
17
|
'fetch'
|
16
18
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module MGit
|
2
2
|
class FFMergeCommand < Command
|
3
3
|
def execute(args)
|
4
|
-
raise TooManyArgumentsError.new(self) if args.size != 0
|
5
|
-
|
6
4
|
Registry.chdir_each do |repo|
|
7
5
|
if repo.dirty?
|
8
6
|
puts "Skipping repository #{repo.name} since it's dirty.".red
|
@@ -20,6 +18,10 @@ module MGit
|
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
21
|
+
def arity
|
22
|
+
[nil, 0]
|
23
|
+
end
|
24
|
+
|
23
25
|
def usage
|
24
26
|
'ffmerge'
|
25
27
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module MGit
|
2
2
|
class ForEachCommand < Command
|
3
3
|
def execute(args)
|
4
|
-
raise TooFewArgumentsError.new(self) if args.size == 0
|
5
|
-
|
6
4
|
command = args.join(' ')
|
7
5
|
|
8
6
|
Registry.chdir_each do |repo|
|
@@ -13,6 +11,10 @@ module MGit
|
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
14
|
+
def arity
|
15
|
+
[1, nil]
|
16
|
+
end
|
17
|
+
|
16
18
|
def usage
|
17
19
|
'foreach <command...>'
|
18
20
|
end
|
data/lib/mgit/commands/grep.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
module MGit
|
2
2
|
class GrepCommand < Command
|
3
3
|
def execute(args)
|
4
|
-
raise TooFewArgumentsError.new(self) if args.size == 0
|
5
|
-
raise TooManyArgumentsError.new(self) if args.size > 1
|
6
|
-
|
7
4
|
ptrn = args[0]
|
8
5
|
|
9
6
|
Registry.chdir_each do |repo|
|
@@ -13,6 +10,10 @@ module MGit
|
|
13
10
|
end
|
14
11
|
end
|
15
12
|
|
13
|
+
def arity
|
14
|
+
[1, 1]
|
15
|
+
end
|
16
|
+
|
16
17
|
def usage
|
17
18
|
'grep <pattern>'
|
18
19
|
end
|
data/lib/mgit/commands/help.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module MGit
|
2
2
|
class HelpCommand < Command
|
3
3
|
def execute(args)
|
4
|
-
raise TooManyArgumentsError.new(self) if args.size > 1
|
5
|
-
|
6
4
|
if args.size == 0
|
7
5
|
puts "M[eta]Git - manage multiple git repositories at the same time"
|
8
6
|
puts
|
@@ -15,6 +13,10 @@ module MGit
|
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
16
|
+
def arity
|
17
|
+
[0, 1]
|
18
|
+
end
|
19
|
+
|
18
20
|
def usage
|
19
21
|
'help [command]'
|
20
22
|
end
|
data/lib/mgit/commands/list.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module MGit
|
2
2
|
class ListCommand < Command
|
3
3
|
def execute(args)
|
4
|
-
raise TooManyArgumentsError.new(self) if args.size != 0
|
5
|
-
|
6
4
|
Registry.each do |repo|
|
7
5
|
nc = 24
|
8
6
|
display = (repo.name.size > nc) ? (repo.name[0..(nc - 3)] + '...') : repo.name.ljust(nc, ' ')
|
@@ -10,6 +8,10 @@ module MGit
|
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
11
|
+
def arity
|
12
|
+
[nil, 0]
|
13
|
+
end
|
14
|
+
|
13
15
|
def usage
|
14
16
|
'list'
|
15
17
|
end
|
data/lib/mgit/commands/log.rb
CHANGED
data/lib/mgit/commands/remove.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
module MGit
|
2
2
|
class RemoveCommand < Command
|
3
3
|
def execute(args)
|
4
|
-
raise TooFewArgumentsError.new(self) if args.size == 0
|
5
|
-
raise TooManyArgumentsError.new(self) if args.size > 1
|
6
|
-
|
7
4
|
ptrn = args[0]
|
8
5
|
|
9
6
|
repo = Registry.find do |repo|
|
@@ -16,6 +13,10 @@ module MGit
|
|
16
13
|
puts "Removed repository #{repo.name}.".yellow
|
17
14
|
end
|
18
15
|
|
16
|
+
def arity
|
17
|
+
[1, 1]
|
18
|
+
end
|
19
|
+
|
19
20
|
def usage
|
20
21
|
'remove <name/path>'
|
21
22
|
end
|
data/lib/mgit/commands/status.rb
CHANGED
@@ -3,8 +3,6 @@ require 'set'
|
|
3
3
|
module MGit
|
4
4
|
class StatusCommand < Command
|
5
5
|
def execute(args)
|
6
|
-
raise TooManyArgumentsError.new(self) if args.size != 0
|
7
|
-
|
8
6
|
Registry.chdir_each do |repo|
|
9
7
|
nc = 36
|
10
8
|
display = (repo.name.size > nc) ? (repo.name[0..(nc - 3)] + '...') : repo.name.ljust(nc, ' ')
|
@@ -12,6 +10,10 @@ module MGit
|
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
13
|
+
def arity
|
14
|
+
[nil, 0]
|
15
|
+
end
|
16
|
+
|
15
17
|
def usage
|
16
18
|
'status'
|
17
19
|
end
|
data/lib/mgit/exceptions.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
module MGit
|
2
2
|
class ImplementationError < StandardError; end
|
3
3
|
|
4
|
+
class GitError < StandardError
|
5
|
+
def initialize(error)
|
6
|
+
@error = error
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
"Git error: #{@error}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
class UsageError < StandardError
|
5
15
|
def initialize(error, usage)
|
6
16
|
@error = error
|
data/lib/mgit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mgit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FlavourSys Technology GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/mgit/exceptions.rb
|
63
63
|
- lib/mgit/cli.rb
|
64
64
|
- lib/mgit/command.rb
|
65
|
+
- lib/mgit/commands/clone.rb
|
65
66
|
- lib/mgit/commands/add.rb
|
66
67
|
- lib/mgit/commands/list.rb
|
67
68
|
- lib/mgit/commands/help.rb
|