mgit 0.2.7 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b52e092a056bf8964c6d7661f186d151a1d66ec5
4
- data.tar.gz: d910c22cd816ae0fbf2565fb755f92b337986b85
3
+ metadata.gz: 72da3e471054578d574fab47f09886ebdf696676
4
+ data.tar.gz: 889b8f08aa19321f4162aceddb7e9b0e4beca58c
5
5
  SHA512:
6
- metadata.gz: 741ea187d1be95382071a051f0cae9a541ffc82370764e41572b383255fd7d07e1e05951abcd370b17f02d79f9941345cdee3a637199f60e294ff9b0ceb0cbf7
7
- data.tar.gz: e9835cc422832de5abb6ca17e7770bb7af423bb202882e6ca767d8b500232eac2b93bade7e8d9e4d7644b24fdd8da790419945defec9d2bf257184e42ed1af26
6
+ metadata.gz: fe550448650a1c9cc3530e1cf583423771a7630b4c11069051ba8743c269abdc2f1dbfbc91db07bcd31049d8c66dab4f036f64047797d650461ddadeb60bd675
7
+ data.tar.gz: 6ca1f337596f69e8ec7f223857c8b2b1715bed676c9a3dc47849a138e9c7c57f169700b54ccbc6c6acf1a029ae250643377f29963eeef4667c4d00f9340297c2
@@ -0,0 +1,104 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+
4
+ module MGit
5
+ module AppData
6
+
7
+ ####################
8
+ # Module interface #
9
+ ####################
10
+
11
+ def self.update
12
+ if AppDataVersion.active
13
+ AppDataVersion.updates.each { |u| u.migrate! }
14
+ else
15
+ AppDataVersion.latest.setup
16
+ end
17
+ end
18
+
19
+ def self.load(key, default = {})
20
+ AppDataVersion.latest.load(key, default)
21
+ end
22
+
23
+ def self.save!(key, value)
24
+ AppDataVersion.latest.save!(key, value)
25
+ end
26
+
27
+ #########################################
28
+ # Base class for data storage versions. #
29
+ #########################################
30
+
31
+ class AppDataVersion
32
+ @@versions = []
33
+
34
+ def self.inherited(version)
35
+ @@versions << version.new
36
+ super
37
+ end
38
+
39
+ def self.sorted
40
+ @@versions.sort_by { |v| v.version }
41
+ end
42
+
43
+ def self.updates
44
+ self.sorted.drop_while { |v| !v.active? }.drop(1)
45
+ end
46
+
47
+ def self.active
48
+ self.sorted.find { |v| v.active? }
49
+ end
50
+
51
+ def self.latest
52
+ self.sorted.last
53
+ end
54
+
55
+ include Comparable
56
+
57
+ def <=>(other)
58
+ version <=> other.version
59
+ end
60
+
61
+ [:version, :active?, :load, :save!, :migrate!].each do |meth|
62
+ define_method(meth) do
63
+ raise ImplementationError.new("AppDataVersion #{self.class.name} doesn't implement the #{meth.to_s} method.")
64
+ end
65
+ end
66
+ end
67
+
68
+ #######################################################################
69
+ # Original version, plain YAML file containing the repositories hash. #
70
+ #######################################################################
71
+
72
+ class LegacyAppData < AppDataVersion
73
+ def version
74
+ 0
75
+ end
76
+
77
+ def active?
78
+ File.file?(repofile)
79
+ end
80
+
81
+ def load(key, default)
82
+ raise ImplementationError.new('LegacyAppData::load called with unknown key.') if key != :repositories
83
+ repos = YAML.load_file(repofile)
84
+ repos ? repos : default
85
+ end
86
+
87
+ def save!(key, value)
88
+ raise ImplementationError.new('LegacyAppData::save! called with unknown key.') if key != :repositories
89
+ File.open(repofile, 'w') { |fd| fd.write value.to_yaml }
90
+ end
91
+
92
+ def setup
93
+ FileUtils.touch(repofile)
94
+ end
95
+
96
+ private
97
+
98
+ def repofile
99
+ XDG['CONFIG_HOME'].to_path.join('mgit.yml')
100
+ end
101
+ end
102
+
103
+ end
104
+ end
data/lib/mgit/cli.rb CHANGED
@@ -4,6 +4,11 @@ module MGit
4
4
 
5
5
  def start
6
6
  raise NoCommandError if ARGV.size == 0
7
+
8
+ # Initialize AppData and migrate if necessary.
9
+ AppData.update
10
+
11
+ # Run command, consuming its name from the list of arguments.
7
12
  command = Command.execute(ARGV.shift, ARGV)
8
13
  rescue UsageError => e
9
14
  perror e.to_s
data/lib/mgit/command.rb CHANGED
@@ -7,11 +7,7 @@ module MGit
7
7
 
8
8
  def self.execute(name, args)
9
9
  cmd = self.create(name)
10
-
11
- arity_min, arity_max = cmd.arity
12
- raise TooFewArgumentsError.new(cmd) if arity_min && args.size < arity_min
13
- raise TooManyArgumentsError.new(cmd) if arity_max && args.size > arity_max
14
-
10
+ cmd.check_arity(args)
15
11
  cmd.execute(args)
16
12
  end
17
13
 
@@ -33,6 +29,12 @@ module MGit
33
29
  end
34
30
  end
35
31
 
32
+ def check_arity(args)
33
+ arity_min, arity_max = self.arity
34
+ raise TooFewArgumentsError.new(self) if arity_min && args.size < arity_min
35
+ raise TooManyArgumentsError.new(self) if arity_max && args.size > arity_max
36
+ end
37
+
36
38
  [:arity, :usage, :help, :description].each do |meth|
37
39
  define_method(meth) do
38
40
  raise ImplementationError.new("Command #{self.class.name} doesn't implement the #{meth.to_s} method.")
@@ -0,0 +1,23 @@
1
+ module MGit
2
+ class ListCommand < Command
3
+ def execute(args)
4
+ t = []
5
+ Registry.each { |repo| t << [repo.name, repo.current_branch, repo.current_head] }
6
+ ptable t, :columns => [24, nil, nil]
7
+ end
8
+
9
+ def arity
10
+ [0, 0]
11
+ end
12
+
13
+ def usage
14
+ 'head'
15
+ end
16
+
17
+ def description
18
+ 'show repository HEADs'
19
+ end
20
+
21
+ register_command :head
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module MGit
2
+ class RemoveAllCommand < Command
3
+ def execute(args)
4
+ if agree('This will delete all repositories from mgit. Are you sure?'.red)
5
+ Registry.clean
6
+ end
7
+ end
8
+
9
+ def arity
10
+ [0, 0]
11
+ end
12
+
13
+ def usage
14
+ 'removeall'
15
+ end
16
+
17
+ def description
18
+ 'removes all repositories from mgit (resets mgit\'s store)'
19
+ end
20
+
21
+ register_command :removeall
22
+ register_alias :remove_all
23
+ end
24
+ end
data/lib/mgit/output.rb CHANGED
@@ -28,8 +28,9 @@ module MGit
28
28
  end
29
29
 
30
30
  def to_s
31
+ return '' if table.empty?
32
+
31
33
  cw = column_widths
32
-
33
34
  if options[:columns]
34
35
  options[:columns].each_with_index do |c, i|
35
36
  cw[i] = c if c
data/lib/mgit/registry.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'yaml'
2
-
3
1
  module MGit
4
2
  module Registry
5
3
  def self.all
@@ -34,18 +32,18 @@ module MGit
34
32
  self.save! repos
35
33
  end
36
34
 
37
- private
38
-
39
- def self.repofile
40
- XDG['CONFIG_HOME'].to_path.join('mgit.yml')
35
+ def self.clean
36
+ self.save!({})
41
37
  end
42
38
 
39
+ private
40
+
43
41
  def self.load
44
- File.exists?(self.repofile) ? YAML.load_file(self.repofile) : {}
42
+ AppData.load(:repositories)
45
43
  end
46
44
 
47
45
  def self.save!(repos)
48
- File.open(self.repofile, 'w') { |fd| fd.write repos.to_yaml }
46
+ AppData.save!(:repositories, repos)
49
47
  end
50
48
  end
51
49
  end
@@ -16,6 +16,10 @@ module MGit
16
16
  }
17
17
  end
18
18
 
19
+ def current_head
20
+ in_repo { `git rev-parse --verify --short HEAD`.strip }
21
+ end
22
+
19
23
  def remote_tracking_branches(upstream_exists_only = true)
20
24
  rb = remote_branches
21
25
 
data/lib/mgit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MGit
2
- VERSION = '0.2.7'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/mgit.rb CHANGED
@@ -3,6 +3,7 @@ require 'highline/import'
3
3
  require 'xdg'
4
4
 
5
5
  require 'mgit/version'
6
+ require 'mgit/appdata'
6
7
  require 'mgit/exceptions'
7
8
  require 'mgit/output'
8
9
  require 'mgit/registry'
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.7
4
+ version: 0.3.0
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-12-04 00:00:00.000000000 Z
11
+ date: 2013-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -77,14 +77,15 @@ files:
77
77
  - lib/mgit/output.rb
78
78
  - lib/mgit/repository.rb
79
79
  - lib/mgit/version.rb
80
- - lib/mgit/subcommand.rb
80
+ - lib/mgit/appdata.rb
81
81
  - lib/mgit/registry.rb
82
82
  - lib/mgit/exceptions.rb
83
83
  - lib/mgit/commands/list.rb
84
84
  - lib/mgit/commands/grep.rb
85
- - lib/mgit/commands/config.rb
85
+ - lib/mgit/commands/remove_all.rb
86
86
  - lib/mgit/commands/version.rb
87
87
  - lib/mgit/commands/fetch.rb
88
+ - lib/mgit/commands/head.rb
88
89
  - lib/mgit/commands/status.rb
89
90
  - lib/mgit/commands/remove.rb
90
91
  - lib/mgit/commands/help.rb
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  version: '0'
117
118
  requirements: []
118
119
  rubyforge_project:
119
- rubygems_version: 2.0.3
120
+ rubygems_version: 2.0.14
120
121
  signing_key:
121
122
  specification_version: 4
122
123
  summary: MGit meta repository tool
File without changes
@@ -1,5 +0,0 @@
1
- module MGit
2
- class Subcommand < Command
3
-
4
- end
5
- end