mgit 0.0.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.
data/bin/mgit ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mgit'
4
+
5
+ MGit::CLI.new.start
data/lib/mgit.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'highline/import'
2
+
3
+ require 'mgit/version'
4
+ require 'mgit/exceptions'
5
+ require 'mgit/repository'
6
+
7
+ require 'mgit/cli'
8
+ require 'mgit/command'
9
+ Dir["#{File.expand_path('../mgit/commands', __FILE__)}/*.rb"].each { |file| require file }
10
+
11
+ module MGit
12
+ end
data/lib/mgit/cli.rb ADDED
@@ -0,0 +1,11 @@
1
+ module MGit
2
+ class CLI
3
+ def start
4
+ raise NoCommandError if ARGV.size == 0
5
+ command = Command.create(ARGV.shift.downcase.to_sym)
6
+ command.execute(ARGV)
7
+ rescue UsageError => e
8
+ $stderr.puts e
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module MGit
2
+ class Command
3
+ @@commands = {}
4
+ @@aliases = {}
5
+
6
+ def self.create(cmd)
7
+ c = @@commands[cmd] || @@aliases[cmd]
8
+ if c
9
+ c.new
10
+ else
11
+ raise UnknownCommandError.new(cmd)
12
+ end
13
+ end
14
+
15
+ def self.register_command(cmd)
16
+ @@commands[cmd] = self
17
+ end
18
+
19
+ def self.register_alias(cmd)
20
+ @@aliases[cmd] = self
21
+ end
22
+
23
+ def self.list
24
+ '[' + @@commands.keys.join(', ') + ']'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module MGit
2
+ class AddCommand < Command
3
+ def execute(args)
4
+ raise TooFewArgumentsError.new(self) if args.size == 0
5
+ raise TooManyArgumentsError.new(self) if args.size > 2
6
+
7
+ path = File.expand_path(args[0])
8
+ raise CommandUsageError.new('First argument must be a path to a git repository.', self) unless is_git_dir?(path)
9
+
10
+ name = (args.size == 2) ? args[1] : (ask('Name of the repository? ') { |q| q.default = File.basename(path) })
11
+
12
+ Repository.add(name, path)
13
+ end
14
+
15
+ def usage
16
+ 'add <path_to_git_repository> [name]'
17
+ end
18
+
19
+ register_command :add
20
+
21
+ private
22
+
23
+ def is_git_dir?(path)
24
+ File.directory?(path) && (File.directory?(File.join(path, '.git')) || File.file?(File.join(path, 'HEAD')))
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ module MGit
2
+ class FetchCommand < Command
3
+ def execute(args)
4
+ raise TooManyArgumentsError.new(self) if args.size != 0
5
+
6
+ Repository.chdir_each do |name, path|
7
+ `git remote`.split.each do |remote|
8
+ puts "Fetching #{remote} in repository #{name}..."
9
+ `git fetch #{remote}`
10
+ end
11
+ end
12
+ end
13
+
14
+ def usage
15
+ 'fetch'
16
+ end
17
+
18
+ register_command :fetch
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module MGit
2
+ class ListCommand < Command
3
+ def execute(args)
4
+ raise TooManyArgumentsError.new(self) if args.size != 0
5
+
6
+ Repository.each do |name, path|
7
+ puts "#{name} => #{path}"
8
+ end
9
+ end
10
+
11
+ def usage
12
+ 'list'
13
+ end
14
+
15
+ register_command :list
16
+ register_alias :ls
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ require 'set'
2
+
3
+ module MGit
4
+ class StatusCommand < Command
5
+ def execute(args)
6
+ raise TooManyArgumentsError.new(self) if args.size != 0
7
+
8
+ Repository.chdir_each do |name, path|
9
+ nc = 36
10
+ display = (name.size > nc) ? (name[0..(nc - 3)] + '...') : name.ljust(nc, ' ')
11
+ puts "#{display} => [#{flags.to_a.join(', ')}]"
12
+ end
13
+ end
14
+
15
+ def usage
16
+ 'status'
17
+ end
18
+
19
+ register_command :status
20
+ register_alias :st
21
+
22
+ private
23
+
24
+ def flags
25
+ flags = Set.new
26
+ status = `git status --short --branch --ignore-submodules`.split("\n")
27
+ status.each do |s|
28
+ case s.split[0]
29
+ when 'A'
30
+ flags << 'Index'
31
+ when 'M'
32
+ flags << 'Dirty'
33
+ when '??'
34
+ flags << 'Untracked'
35
+ when '##'
36
+ if(m = /## (\w+)\.\.\.([\w,\/]+) \[(\w+) (\d+)\]/.match(s))
37
+ flags << "#{m[3].capitalize} #{m[2]} by #{m[4]}"
38
+ end
39
+ end
40
+ end
41
+
42
+ flags
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,42 @@
1
+ module MGit
2
+ class UsageError < StandardError
3
+ def initialize(error, usage)
4
+ @error = error
5
+ @usage = usage
6
+ end
7
+
8
+ def to_s
9
+ @error + "\n" + @usage
10
+ end
11
+ end
12
+
13
+ class NoCommandError < UsageError
14
+ def initialize
15
+ super('No commands given.', 'Usage: mgit <command> [parameters]')
16
+ end
17
+ end
18
+
19
+ class UnknownCommandError < UsageError
20
+ def initialize(cmd)
21
+ super("Unknown command '#{cmd}'.", "Command may be one of: #{Command.list}")
22
+ end
23
+ end
24
+
25
+ class CommandUsageError < UsageError
26
+ def initialize(error, cmd)
27
+ super(error, "Usage: mgit #{cmd.usage}")
28
+ end
29
+ end
30
+
31
+ class TooFewArgumentsError < CommandUsageError
32
+ def initialize(cmd)
33
+ super('Too few arguments.', cmd)
34
+ end
35
+ end
36
+
37
+ class TooManyArgumentsError < CommandUsageError
38
+ def initialize(cmd)
39
+ super('Too many arguments.', cmd)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,33 @@
1
+ require 'yaml'
2
+
3
+ module MGit
4
+ module Repository
5
+ def self.all
6
+ File.exists?(self.repofile) ? YAML.load_file(self.repofile) : {}
7
+ end
8
+
9
+ def self.each(&block)
10
+ self.all.each(&block)
11
+ end
12
+
13
+ def self.chdir_each
14
+ self.all.each do |name, path|
15
+ Dir.chdir(path) do
16
+ yield name, path
17
+ end
18
+ end
19
+ end
20
+
21
+ def self.add(name, path)
22
+ repos = self.all
23
+ repos[name] = path
24
+ File.open(self.repofile, 'w') { |fd| fd.write repos.to_yaml }
25
+ end
26
+
27
+ private
28
+
29
+ def self.repofile
30
+ File.join(Dir.home, '.config/mgit.yml')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module MGit
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mgit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - FlavourSys Technology GmbH
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: highline
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: M[eta]Git let's you manage multiple git repositories simultaneously
31
+ email: technology@flavoursys.com
32
+ executables:
33
+ - mgit
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/mgit.rb
38
+ - lib/mgit/repository.rb
39
+ - lib/mgit/version.rb
40
+ - lib/mgit/exceptions.rb
41
+ - lib/mgit/commands/list.rb
42
+ - lib/mgit/commands/fetch.rb
43
+ - lib/mgit/commands/status.rb
44
+ - lib/mgit/commands/add.rb
45
+ - lib/mgit/command.rb
46
+ - lib/mgit/cli.rb
47
+ - bin/mgit
48
+ homepage: http://github.com/flavoursys/mgit
49
+ licenses:
50
+ - MIT
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.23
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: MGit meta repository tool
73
+ test_files: []