mgit 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 522c90f1b3a1838184ab1732822d42c9620680e7
4
- data.tar.gz: 64747029b401daf6e77793068a3dcac64ff17915
3
+ metadata.gz: 712d93ce29c8c64e4b37cd820a6216205edd2746
4
+ data.tar.gz: da97e60a84ab1fc96fb272ad095f6b0eedaedc10
5
5
  SHA512:
6
- metadata.gz: ec1440f74ea09f063c36c8b40bf40948446a5c9f2898d5b172e66793c52635745ac200d6458e864442ee8c555d68a99482095f954c86cbbad08086af1b1839c8
7
- data.tar.gz: 818b07fa2a1761bfae74b78672c27b34834d4140cd182a27410b6bd15c971dae58cc446cabe747f90ffb65d995ffb9ab9099186ce335a017501c660a3e5189e3
6
+ metadata.gz: d2d964c20c6b1c1daef35f4774b008c965b60ec7c610d9228ff588ee452d854ee9ea6c71101649bf417606f14417e79b6fc168eb2908e4aa951433fdd3746c4c
7
+ data.tar.gz: 1f24ca99c54e9b41e0d8ce6d1231cd95c7aa3c23669f395f1ce1e98218632983ad6c07ab796ced72af18b6c80eaf61c72fecb6715b21bf503ed8ae5a27561d7b
data/lib/mgit/appdata.rb CHANGED
@@ -12,7 +12,7 @@ module MGit
12
12
  if AppDataVersion.active
13
13
  AppDataVersion.updates.each { |u| u.migrate! }
14
14
  else
15
- AppDataVersion.latest.setup
15
+ AppDataVersion.latest.setup!
16
16
  end
17
17
  end
18
18
 
@@ -78,21 +78,21 @@ module MGit
78
78
  File.file?(repofile)
79
79
  end
80
80
 
81
+ def setup!
82
+ FileUtils.touch(repofile)
83
+ end
84
+
81
85
  def load(key, default)
82
- raise ImplementationError.new('LegacyAppData::load called with unknown key.') if key != :repositories
86
+ raise ImplementationError.new("LegacyAppData::load called with unknown key #{key}.") if key != :repositories
83
87
  repos = YAML.load_file(repofile)
84
88
  repos ? repos : default
85
89
  end
86
90
 
87
91
  def save!(key, value)
88
- raise ImplementationError.new('LegacyAppData::save! called with unknown key.') if key != :repositories
92
+ raise ImplementationError.new("LegacyAppData::save! called with unknown key #{key}.") if key != :repositories
89
93
  File.open(repofile, 'w') { |fd| fd.write value.to_yaml }
90
94
  end
91
95
 
92
- def setup
93
- FileUtils.touch(repofile)
94
- end
95
-
96
96
  private
97
97
 
98
98
  def repofile
@@ -100,5 +100,67 @@ module MGit
100
100
  end
101
101
  end
102
102
 
103
+ class AppDataVersion1 < AppDataVersion
104
+ def version
105
+ 1
106
+ end
107
+
108
+ def active?
109
+ File.directory?(config_dir) && (load(:version, nil) == '1')
110
+ end
111
+
112
+ def migrate!
113
+ setup!
114
+
115
+ old_repofile = LegacyAppData.new.send(:repofile)
116
+ FileUtils.mv(old_repofile, repo_file) if File.file?(old_repofile)
117
+ end
118
+
119
+ def setup!
120
+ FileUtils.mkdir_p(config_dir)
121
+ File.open(config_file, 'w') { |fd| fd.write ({ :version => '1' }.to_yaml) }
122
+ FileUtils.touch(repo_file)
123
+ end
124
+
125
+ def load(key, default)
126
+ case key
127
+ when :repositories
128
+ repos = YAML.load_file(repo_file)
129
+ repos ? repos : default
130
+ when *Configuration::KEYS.keys, :version
131
+ config = YAML.load_file(config_file)
132
+ (config && config.has_key?(key)) ? config[key] : default
133
+ else
134
+ raise ImplementationError.new("AppDataVersion1::load called with unknown key #{key}.")
135
+ end
136
+ end
137
+
138
+ def save!(key, value)
139
+ case key
140
+ when :repositories
141
+ File.open(repo_file, 'w') { |fd| fd.write value.to_yaml }
142
+ when *Configuration::KEYS.keys
143
+ config = YAML.load_file(config_file)
144
+ config[key] = value
145
+ File.open(config_file, 'w') { |fd| fd.write config.to_yaml }
146
+ else
147
+ raise ImplementationError.new("AppDataVersion1::save! called with unknown key #{key}.")
148
+ end
149
+ end
150
+
151
+ private
152
+
153
+ def config_dir
154
+ XDG['CONFIG_HOME'].to_path.join('mgit')
155
+ end
156
+
157
+ def repo_file
158
+ File.join(config_dir, 'repositories.yml')
159
+ end
160
+
161
+ def config_file
162
+ File.join(config_dir, 'config.yml')
163
+ end
164
+ end
103
165
  end
104
166
  end
@@ -0,0 +1,26 @@
1
+ module MGit
2
+ class ConfigCommand < Command
3
+ def execute(args)
4
+ key = args[0]
5
+ value = args[1]
6
+
7
+ Configuration.set(key, value)
8
+ rescue ConfigurationError => e
9
+ raise CommandUsageError.new(e.to_s, self)
10
+ end
11
+
12
+ def arity
13
+ [2, 2]
14
+ end
15
+
16
+ def usage
17
+ 'config <key> <value>'
18
+ end
19
+
20
+ def description
21
+ 'configure MGit'
22
+ end
23
+
24
+ register_command :config
25
+ end
26
+ end
@@ -3,25 +3,11 @@ require 'open3'
3
3
  module MGit
4
4
  class FetchCommand < Command
5
5
  def execute(args)
6
+ thread_class = Configuration.threads ? Thread : NullThread
6
7
  threads = []
7
8
  Registry.each do |repo|
8
- threads << Thread.new do
9
- remotes, st = Open3.capture2('git remote', :chdir => repo.path)
10
-
11
- if st.exitstatus != 0
12
- perror "Failed to read remotes for repository #{repo.name}! Abort."
13
- Thread.exit
14
- end
15
-
16
- remotes.split.each do |remote|
17
- sout, st = Open3.capture2("git fetch #{remote}", :chdir => repo.path)
18
- if st.exitstatus == 0
19
- pinfo "Fetched #{remote} in repository #{repo.name}."
20
- else
21
- perror "Failed to fetch #{remote} in repository #{repo.name}! Abort."
22
- break
23
- end
24
- end
9
+ threads << thread_class.new do
10
+ fetch(repo)
25
11
  end
26
12
  end
27
13
 
@@ -41,5 +27,35 @@ module MGit
41
27
  end
42
28
 
43
29
  register_command :fetch
30
+
31
+ private
32
+
33
+ def fetch(repo)
34
+ remotes, st = Open3.capture2('git remote', :chdir => repo.path)
35
+
36
+ if st.exitstatus != 0
37
+ perror "Failed to read remotes for repository #{repo.name}! Abort."
38
+ Thread.exit
39
+ end
40
+
41
+ remotes.split.each do |remote|
42
+ sout, st = Open3.capture2("git fetch #{remote}", :chdir => repo.path)
43
+ if st.exitstatus == 0
44
+ pinfo "Fetched #{remote} in repository #{repo.name}."
45
+ else
46
+ perror "Failed to fetch #{remote} in repository #{repo.name}! Abort."
47
+ break
48
+ end
49
+ end
50
+ end
51
+
52
+ class NullThread
53
+ def initialize
54
+ yield
55
+ end
56
+
57
+ def join
58
+ end
59
+ end
44
60
  end
45
61
  end
@@ -0,0 +1,45 @@
1
+ module MGit
2
+ module Configuration
3
+ KEYS = {
4
+ :threads => {
5
+ :default => true,
6
+ :description => 'set to true if you want the fetch command to be threaded'
7
+ }
8
+ }
9
+
10
+ class << self
11
+ KEYS.each do |k, v|
12
+ define_method(k.to_s) do
13
+ AppData.load(k, v[:default])
14
+ end
15
+ end
16
+ end
17
+
18
+ def self.set(key, value)
19
+ case key
20
+ when 'threads'
21
+ unless ['true', 'false', 'on', 'off'].include?(value)
22
+ raise ConfigurationError.new("Illegal value for key threads.")
23
+ end
24
+
25
+ if ['true', 'on'].include?(value)
26
+ self.threads = true
27
+ else
28
+ self.threads = false
29
+ end
30
+ else
31
+ raise ConfigurationError.new("Unknown key: #{key}.")
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ class << self
38
+ KEYS.each do |k, v|
39
+ define_method("#{k.to_s}=") do |value|
40
+ AppData.save!(k, value)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -51,4 +51,6 @@ module MGit
51
51
  super('Too many arguments.', cmd)
52
52
  end
53
53
  end
54
+
55
+ class ConfigurationError < StandardError; end
54
56
  end
data/lib/mgit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MGit
2
- VERSION = '0.3.4'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/mgit.rb CHANGED
@@ -4,6 +4,7 @@ require 'xdg'
4
4
 
5
5
  require 'mgit/version'
6
6
  require 'mgit/appdata'
7
+ require 'mgit/configuration'
7
8
  require 'mgit/exceptions'
8
9
  require 'mgit/output'
9
10
  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.3.4
4
+ version: 0.4.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: 2014-01-09 00:00:00.000000000 Z
11
+ date: 2014-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -79,9 +79,11 @@ files:
79
79
  - lib/mgit/version.rb
80
80
  - lib/mgit/appdata.rb
81
81
  - lib/mgit/registry.rb
82
+ - lib/mgit/configuration.rb
82
83
  - lib/mgit/exceptions.rb
83
84
  - lib/mgit/commands/list.rb
84
85
  - lib/mgit/commands/grep.rb
86
+ - lib/mgit/commands/config.rb
85
87
  - lib/mgit/commands/remove_all.rb
86
88
  - lib/mgit/commands/statistics.rb
87
89
  - lib/mgit/commands/version.rb