revans-gitools 0.3.0 → 0.3.2
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/CHANGELOG.rdoc +6 -0
- data/README.markdown +18 -54
- data/lib/gitools.rb +1 -1
- data/lib/gitools/ci.rb +42 -6
- data/lib/gitools/parse.rb +20 -9
- data/lib/gitools/submodules.rb +214 -34
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
data/README.markdown
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# Git Tools
|
2
|
+
|
3
|
+
## Install
|
4
|
+
|
5
|
+
You can either clone this or do:
|
6
|
+
|
7
|
+
<pre>
|
8
|
+
gem sources -a http://gems.github.com
|
9
|
+
sudo gem install revans-gitools
|
10
|
+
</pre>
|
2
11
|
|
3
12
|
## How to use
|
4
13
|
|
@@ -21,60 +30,15 @@ Add the git submodules that you want to want to use in your application like so:
|
|
21
30
|
active_merchant: git://github.com/Shopify/active_merchant.git
|
22
31
|
</pre>
|
23
32
|
|
24
|
-
A couple of things, it needs to follow the structure above with the name submodules and defining each below it. Use the name
|
25
|
-
that you want the plugin to be named when checking out. Put the git location as the value.
|
26
|
-
|
27
|
-
Now, create a new Rake task in lib/tasks directory. I call mine submodules.rake. Here is what my file looks like:
|
28
|
-
|
29
|
-
<pre>
|
30
|
-
require 'gitools'
|
31
|
-
|
32
|
-
@configration = File.join(RAILS_ROOT, "config/submodules.yml")
|
33
|
-
|
34
|
-
namespace :git do
|
35
|
-
|
36
|
-
namespace :submodule do
|
37
|
-
|
38
|
-
desc "Remove Submodule cache"
|
39
|
-
task :remove, :submodule do |task, args|
|
40
|
-
GitTools::Submodule.remove(args.submodule)
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
namespace :update do
|
47
|
-
|
48
|
-
desc "Update all Submodules"
|
49
|
-
task :all => :environment do
|
50
|
-
GitTools::Submodule.update_all(@configration)
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
GitTools::Submodule.individual_tasks(@configration) do |name|
|
55
|
-
desc "Update #{name} submodule"
|
56
|
-
task name.to_sym => :environment do
|
57
|
-
GitTools::Submodule.submodule_update("#{name}")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
</pre>
|
65
|
-
|
66
|
-
|
67
|
-
## Command Line
|
68
|
-
|
69
|
-
When creating a new project, it would be nice to just write your submodule.yml file and then shoot a command off in the terminal and have all your submodules installed for you. Well, now you can! Just do:
|
70
|
-
|
71
|
-
<pre>
|
72
|
-
gitools all
|
73
|
-
</pre>
|
74
33
|
|
75
|
-
|
34
|
+
### Command Line
|
76
35
|
|
77
36
|
<pre>
|
78
|
-
gitools
|
79
|
-
|
37
|
+
gitools setup # init and update all git submodules
|
38
|
+
|
39
|
+
gitools add all # add all submodules
|
40
|
+
gitools add rails # add rails as a submodule
|
41
|
+
|
42
|
+
gitools update all # update all submodules
|
43
|
+
gitools update rails # update rails submodule
|
80
44
|
</pre>
|
data/lib/gitools.rb
CHANGED
data/lib/gitools/ci.rb
CHANGED
@@ -5,14 +5,50 @@ module GitTools
|
|
5
5
|
init = new
|
6
6
|
@options = options
|
7
7
|
@yaml = File.join(@options.yaml, 'config/submodules.yml')
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
|
9
|
+
|
10
|
+
case @options.command
|
11
|
+
when "setup"
|
12
|
+
GitTools::Submodule.setup
|
13
|
+
when "add"
|
14
|
+
case @options.library
|
15
|
+
when "all"
|
16
|
+
GitTools::Submodule.add_all(@yaml)
|
17
|
+
else
|
18
|
+
GitTools::Submodule.add(@yaml, @options.library) unless @options.library.nil? || @options.library.empty?
|
19
|
+
end
|
20
|
+
when "update"
|
21
|
+
case @options.library
|
22
|
+
when "all"
|
23
|
+
GitTools::Submodule.update_all(@yaml)
|
24
|
+
else
|
25
|
+
GitTools::Submodule.update(@options.library) unless @options.library.nil? || @options.library.empty?
|
26
|
+
end
|
12
27
|
else
|
13
|
-
|
28
|
+
puts "Your commands were invalid. See gitools' help: gitools -h"
|
29
|
+
exit(0)
|
14
30
|
end
|
31
|
+
|
32
|
+
rescue
|
33
|
+
puts "Your commands were invalid. See gitools' help: gitools -h"
|
34
|
+
exit(0)
|
15
35
|
end
|
36
|
+
|
37
|
+
|
38
|
+
|
16
39
|
|
17
40
|
end
|
18
|
-
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# API
|
45
|
+
#
|
46
|
+
# gitools setup # Should init and update all git submodules
|
47
|
+
# gitools add all # Should add all submodules
|
48
|
+
# gitools add rails # Should add rails as a submodule
|
49
|
+
# gitools update all # Should update all submodules
|
50
|
+
# gitools update rails # Should update rails submodule
|
51
|
+
|
52
|
+
# setup -> GitTools::Submodule.setup
|
53
|
+
# update -> GitTools::Submodule.update_all(@yaml) || GitTools::Submodule.update(@yaml, @options.library)
|
54
|
+
# add -> GitTools::Submodule.add_all(@yaml) || GitTools::Submodule.add(@yaml, @options.library)
|
data/lib/gitools/parse.rb
CHANGED
@@ -1,23 +1,29 @@
|
|
1
1
|
module GitTools
|
2
2
|
class Options
|
3
3
|
|
4
|
+
COMMANDS = ["update", "add", "setup"].freeze
|
5
|
+
|
4
6
|
def self.parse!(args)
|
5
7
|
options = OpenStruct.new
|
6
|
-
options.
|
8
|
+
options.command = args.first
|
9
|
+
options.library = args.last if args.size > 1
|
7
10
|
options.yaml = Dir.pwd
|
8
11
|
|
9
12
|
opts = OptionParser.new do |opts|
|
10
13
|
|
11
|
-
opts.banner = "\nGit Tools Usage
|
14
|
+
opts.banner = "\nGit Tools Usage\n"
|
12
15
|
opts.separator "You must be in your Application Root Directory when running this command."
|
16
|
+
opts.separator "There are a few basic commands:"
|
17
|
+
opts.separator ""
|
18
|
+
opts.separator "gitools setup will init and update your git submodules."
|
19
|
+
opts.separator "gitools update all will update all git submodules."
|
20
|
+
opts.separator "gitools update submodule_name will update just that given submodule."
|
21
|
+
opts.separator "gitools install all will do git submodule add for all submodules declared in your config/submodules.yml file."
|
22
|
+
opts.separator "gitools install submodule_name will do a git submodule add just for that submodule."
|
13
23
|
opts.separator ""
|
14
|
-
|
15
|
-
opts.on('-u', '--update', 'Update the Submodule instead of adding it.') do |ext|
|
16
|
-
options.update = ext
|
17
|
-
end
|
18
24
|
|
19
25
|
opts.on_tail('-v', '--version', "Show GitTools' current version.") do
|
20
|
-
puts "
|
26
|
+
puts "Git Tools is at version #{GitTools::Version}\n"
|
21
27
|
exit(0)
|
22
28
|
end
|
23
29
|
|
@@ -26,13 +32,18 @@ module GitTools
|
|
26
32
|
exit(0)
|
27
33
|
end
|
28
34
|
|
35
|
+
|
29
36
|
opts.on_tail do
|
30
|
-
if (options.library.nil? || options.library == '') &&
|
37
|
+
if (options.library.nil? || options.library == '') && options.command != "setup"
|
31
38
|
puts "\nYou need to tell me what you want library you want to add to git submodule."
|
32
39
|
puts "#{opts}\n"
|
33
40
|
exit(0)
|
41
|
+
elsif !COMMANDS.include?(options.command)
|
42
|
+
puts "\nOnly setup, update, and install are supported commands."
|
43
|
+
puts "#{opts}\n"
|
44
|
+
exit(0)
|
34
45
|
end
|
35
|
-
end
|
46
|
+
end
|
36
47
|
end # OptionParser
|
37
48
|
|
38
49
|
opts.parse!(args)
|
data/lib/gitools/submodules.rb
CHANGED
@@ -1,60 +1,240 @@
|
|
1
|
+
# module GitTools
|
2
|
+
#
|
3
|
+
# # TODO: Refactor Class
|
4
|
+
# class Submodule
|
5
|
+
#
|
6
|
+
# def self.update_all(yaml)
|
7
|
+
# @config = load_yaml(yaml)
|
8
|
+
# @config.each_key do |name|
|
9
|
+
# message(name) { submodule_update(name) }
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# def self.install_all(yaml)
|
14
|
+
# @config = load_yaml(yaml)
|
15
|
+
# @config.each { |plugin, repo| add(plugin, repo) }
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# def self.install_single(yaml, name)
|
19
|
+
# @config = load_yaml(yaml)
|
20
|
+
# add(name, @config[name])
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
#
|
24
|
+
# def self.update_single(yaml, name)
|
25
|
+
# @config = load_yaml(yaml)
|
26
|
+
# submodule_update(name)
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
#
|
30
|
+
# def self.add(name, repo)
|
31
|
+
# dir = name == "rails" ? "vendor/rails/" : "vendor/plugins/#{name}"
|
32
|
+
# system("git submodule add #{repo} #{dir}")
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# def self.checkout
|
36
|
+
# system("git submodule init")
|
37
|
+
# system("git submodule update")
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# def self.remove(submodule)
|
41
|
+
# system("git rm --cache vendor/plugins/#{submodule}")
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# def self.submodule_update(name)
|
45
|
+
# dir = name == "rails" ? "vendor/rails/" : "vendor/plugins/#{name}"
|
46
|
+
# system("cd #{dir} && git remote update && git merge origin/master")
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# def self.load_yaml(yaml)
|
50
|
+
# YAML::load(File.open(yaml))['submodules']
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
#
|
54
|
+
# def self.message(name, &block)
|
55
|
+
# puts "Updating #{name.to_s}"
|
56
|
+
# yield
|
57
|
+
# puts "\n"
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
#
|
61
|
+
# def self.individual_tasks(yaml, &block)
|
62
|
+
# @config = load_yaml(yaml)
|
63
|
+
# @config.each_key { |name| yield name }
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# end
|
69
|
+
|
70
|
+
|
71
|
+
|
1
72
|
module GitTools
|
2
73
|
|
3
|
-
# TODO: Refactor Class
|
4
74
|
class Submodule
|
5
75
|
|
6
|
-
|
7
|
-
|
8
|
-
@config.each_key do |name|
|
9
|
-
message(name) { submodule_update(name) }
|
10
|
-
end
|
11
|
-
end
|
76
|
+
attr_reader :config
|
77
|
+
|
12
78
|
|
13
|
-
|
14
|
-
|
15
|
-
|
79
|
+
# Initialize
|
80
|
+
#
|
81
|
+
# ==== Description
|
82
|
+
#
|
83
|
+
# Will load the YAML file given.
|
84
|
+
#
|
85
|
+
#
|
86
|
+
def initialize(yaml = nil)
|
87
|
+
@config = load_yaml(yaml) unless yaml.nil?
|
16
88
|
end
|
17
89
|
|
18
|
-
|
19
|
-
|
20
|
-
|
90
|
+
|
91
|
+
def self.setup
|
92
|
+
system("git submodule init")
|
93
|
+
system("git submodule update")
|
21
94
|
end
|
22
95
|
|
23
|
-
|
24
|
-
|
25
|
-
|
96
|
+
|
97
|
+
# Update All
|
98
|
+
#
|
99
|
+
# ==== Description
|
100
|
+
#
|
101
|
+
# This will update all the git submodules
|
102
|
+
# specified in the YAML file.
|
103
|
+
#
|
104
|
+
|
105
|
+
def self.update_all(yaml)
|
106
|
+
git = new(yaml)
|
107
|
+
git.config.each_key { |name| git.update_submodule(name) }
|
26
108
|
end
|
27
109
|
|
28
|
-
|
29
|
-
|
30
|
-
|
110
|
+
|
111
|
+
# Update
|
112
|
+
#
|
113
|
+
# ==== Description
|
114
|
+
#
|
115
|
+
# Updates a single submodule in the project
|
116
|
+
#
|
117
|
+
#
|
118
|
+
def self.update(name)
|
119
|
+
new.update_submodule(name)
|
31
120
|
end
|
32
121
|
|
33
|
-
|
34
|
-
|
122
|
+
|
123
|
+
# Add All
|
124
|
+
#
|
125
|
+
# ==== Description
|
126
|
+
#
|
127
|
+
# This will go through the YAML file and do
|
128
|
+
# git submodule add for each one.
|
129
|
+
#
|
130
|
+
#
|
131
|
+
def self.add_all(yaml)
|
132
|
+
git = new(yaml)
|
133
|
+
git.config.each { |name, repo| git.add_submodule(name, repo) }
|
35
134
|
end
|
36
135
|
|
37
|
-
|
38
|
-
|
39
|
-
|
136
|
+
|
137
|
+
# Add
|
138
|
+
#
|
139
|
+
# ==== Description
|
140
|
+
#
|
141
|
+
# Adds a single submodule to the project.
|
142
|
+
#
|
143
|
+
#
|
144
|
+
def self.add(yaml, name)
|
145
|
+
git = new(yaml)
|
146
|
+
git.add_submodule(name, git.config[name])
|
40
147
|
end
|
41
148
|
|
42
|
-
|
43
|
-
|
149
|
+
|
150
|
+
# Remove Cache
|
151
|
+
#
|
152
|
+
# ==== Description
|
153
|
+
#
|
154
|
+
# This will remove the submodule from git's cache
|
155
|
+
#
|
156
|
+
#
|
157
|
+
def self.remove_cache(name)
|
158
|
+
system("git rm --cache #{directory_to_install(name)}")
|
44
159
|
end
|
45
160
|
|
46
161
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
162
|
+
# Update
|
163
|
+
#
|
164
|
+
# ==== Description
|
165
|
+
#
|
166
|
+
# This can be used by the Class Methods for either updating
|
167
|
+
# a single submodule or all of the submodules listed in the
|
168
|
+
# YAML file.
|
169
|
+
#
|
170
|
+
#
|
171
|
+
def update_submodule(name)
|
172
|
+
message(name) { system("cd #{directory_to_install(name)} && git remote update && git merge origin/master") }
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
# Add
|
177
|
+
#
|
178
|
+
# ==== Description
|
179
|
+
#
|
180
|
+
# This can be used by the Class Methods for either adding
|
181
|
+
# a single submodule or all of them listed in the YAML
|
182
|
+
# file.
|
183
|
+
#
|
184
|
+
#
|
185
|
+
def add_submodule(name, repo)
|
186
|
+
message(name) { system("git submodule add #{repo} #{directory_to_install(name)}") }
|
51
187
|
end
|
188
|
+
|
52
189
|
|
190
|
+
|
191
|
+
private
|
192
|
+
|
53
193
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
194
|
+
# Load YAML
|
195
|
+
#
|
196
|
+
# ==== Description
|
197
|
+
#
|
198
|
+
# Loads the YAML file.
|
199
|
+
#
|
200
|
+
#
|
201
|
+
def load_yaml(yaml)
|
202
|
+
YAML::load(File.open(yaml))['submodules']
|
203
|
+
rescue
|
204
|
+
puts "The YAML file cannot be found."
|
205
|
+
exit(0)
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
# Directory to Install
|
210
|
+
#
|
211
|
+
# ==== Description
|
212
|
+
#
|
213
|
+
# This will determine if we have plugin or rails itself
|
214
|
+
# and return the directory in which we should work with.
|
215
|
+
#
|
216
|
+
# ==== Parameters
|
217
|
+
#
|
218
|
+
# * name => The name of the submodule to work with.
|
219
|
+
#
|
220
|
+
#
|
221
|
+
def directory_to_install(name)
|
222
|
+
name == "rails" ? "vendor/rails/" : "vendor/plugins/#{name}"
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
# Message
|
227
|
+
#
|
228
|
+
# ==== Description
|
229
|
+
#
|
230
|
+
# Displays a simple message of what is being updated/added.
|
231
|
+
#
|
232
|
+
#
|
233
|
+
def message(name, &block)
|
234
|
+
puts "-----#{name}-----\n"
|
235
|
+
yield
|
236
|
+
puts "\n"
|
237
|
+
end
|
58
238
|
|
59
239
|
end
|
60
240
|
|