gill 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.rdoc +7 -6
- data/lib/gill/cli.rb +40 -13
- data/lib/gill/config.rb +93 -24
- data/lib/gill/core_extension/symbol.rb +12 -0
- data/lib/gill/exceptions/cache_error.rb +0 -1
- data/lib/gill/exceptions/category_missing.rb +0 -1
- data/lib/gill/exceptions/directory_error.rb +0 -1
- data/lib/gill/exceptions/repository_error.rb +0 -1
- data/lib/gill/exceptions/repository_missing.rb +0 -1
- data/lib/gill/exceptions/syntax_error.rb +0 -1
- data/lib/gill/gill.rb +16 -2
- data/lib/gill/git.rb +61 -34
- data/lib/gill/helper.rb +61 -20
- data/lib/gill/import.rb +86 -10
- data/lib/gill/remove.rb +16 -4
- data/lib/gill/version.rb +5 -1
- data/lib/gill.rb +1 -0
- data/spec/gill_spec.rb +4 -0
- data/spec/git_spec.rb +33 -7
- data/spec/remove_spec.rb +26 -0
- metadata +9 -6
data/{LICENSE → LICENSE.txt}
RENAMED
File without changes
|
data/README.rdoc
CHANGED
@@ -24,12 +24,13 @@ Gill Usage:
|
|
24
24
|
Gill - Git, Clone, Cleanliness.
|
25
25
|
Usage: gill git://host/repository.git#category/sub-category/...
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
-l, --list List all cloned repositories.
|
28
|
+
-p, --path Ouput the path of a repository. e.g. --path gill
|
29
|
+
-r, --remove Remove repository. e.g. -r category#repository
|
30
|
+
-u, --update Update repository. e.g. -u *gill*
|
31
|
+
-i, --import Import untracked repositories.
|
32
|
+
-h, --help This help summary page.
|
33
|
+
-v, --version Version number
|
33
34
|
|
34
35
|
|
35
36
|
Cloning a git repository with gill:
|
data/lib/gill/cli.rb
CHANGED
@@ -11,13 +11,24 @@ require 'gill/exceptions'
|
|
11
11
|
module Gill
|
12
12
|
|
13
13
|
module CLI
|
14
|
+
# Include The Gill Helper Methods
|
14
15
|
include Helper
|
15
16
|
|
17
|
+
#
|
18
|
+
# CLI.Pull
|
19
|
+
#
|
20
|
+
# @param [String] args Repository, folder name and/or repository name.
|
21
|
+
#
|
16
22
|
def CLI.pull(args)
|
17
23
|
begin
|
24
|
+
require 'rubygems'
|
25
|
+
require 'bundler'
|
18
26
|
uri = Parse.new(args)
|
19
27
|
git = Git.new(uri.category, uri.folder, uri.repo)
|
20
28
|
git.clone
|
29
|
+
rescue LoadError
|
30
|
+
STDERR.puts "Count not load the bundler gem. Install it with 'gem install bundler'."
|
31
|
+
exit -1
|
21
32
|
rescue TypeError => e
|
22
33
|
STDERR.puts "Error: #{e}"
|
23
34
|
rescue => e
|
@@ -40,7 +51,9 @@ module Gill
|
|
40
51
|
end
|
41
52
|
end
|
42
53
|
|
54
|
+
#
|
43
55
|
# Update a gill repository.
|
56
|
+
#
|
44
57
|
def CLI.update(repo_name)
|
45
58
|
begin
|
46
59
|
git = Git.new(false, repo_name, false)
|
@@ -55,18 +68,24 @@ module Gill
|
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
71
|
+
#
|
58
72
|
# List all gill cloned repositories.
|
73
|
+
#
|
59
74
|
def CLI.list
|
60
75
|
Gill.config.list_entries
|
61
76
|
exit -1
|
62
77
|
end
|
63
78
|
|
79
|
+
#
|
64
80
|
# Remove a gill cloned repository.
|
81
|
+
#
|
82
|
+
# @param [String] args The category and repository name to remove.
|
83
|
+
#
|
65
84
|
def CLI.remove(args)
|
66
85
|
begin
|
67
|
-
|
68
|
-
|
69
|
-
|
86
|
+
# Raise exception if the params are not seperated by a `#`.
|
87
|
+
raise(SyntaxError, "Invalid Syntax. Arguments must be separated by `#`") unless args =~ /\#/
|
88
|
+
Remove.new(args).remove_repo
|
70
89
|
|
71
90
|
rescue => e
|
72
91
|
STDERR.puts "Error: #{e}"
|
@@ -89,15 +108,20 @@ module Gill
|
|
89
108
|
CLI.list
|
90
109
|
end
|
91
110
|
|
92
|
-
@opts.on('-
|
111
|
+
@opts.on('-p ','--path ','Ouput the path of a repository. e.g. --path gill') do |repo_name|
|
112
|
+
Gill.config.find_repo_paths_by_name(repo_name)
|
113
|
+
exit -1
|
114
|
+
end
|
115
|
+
|
116
|
+
@opts.on('-r ','--remove ','Remove repository. e.g. -r category#repository') do |remove|
|
93
117
|
CLI.remove(remove)
|
94
118
|
end
|
95
119
|
|
96
|
-
@opts.on('-u ', '--update ','Update repository.
|
120
|
+
@opts.on('-u ', '--update ','Update repository. e.g. -u *gill*') do |update|
|
97
121
|
CLI.update(update)
|
98
122
|
end
|
99
123
|
|
100
|
-
@opts.on('-i','--import','Import untracked
|
124
|
+
@opts.on('-i','--import','Import untracked repositories.') do |import|
|
101
125
|
CLI.import
|
102
126
|
end
|
103
127
|
|
@@ -111,23 +135,26 @@ module Gill
|
|
111
135
|
end
|
112
136
|
|
113
137
|
begin
|
114
|
-
|
115
138
|
@args = @opts.parse!(args)
|
116
139
|
usage if @args.empty? || @args[0].nil?
|
117
140
|
CLI.pull(@args[0])
|
118
141
|
rescue OptionParser::MissingArgument => e
|
119
|
-
|
120
|
-
|
121
|
-
|
142
|
+
STDERR.puts e.message
|
143
|
+
STDOUT.puts @opts
|
144
|
+
STDOUT.puts "\n"
|
122
145
|
exit -1
|
123
146
|
rescue OptionParser::InvalidOption => e
|
124
|
-
|
125
|
-
|
126
|
-
|
147
|
+
STDERR.puts e.message
|
148
|
+
STDOUT.puts @opts
|
149
|
+
STDOUT.puts "\n"
|
127
150
|
exit -1
|
128
151
|
end
|
129
152
|
end
|
130
153
|
|
154
|
+
#
|
155
|
+
# Gill usage.
|
156
|
+
# @return [String] Gill Usage Information.
|
157
|
+
#
|
131
158
|
def usage
|
132
159
|
STDOUT.puts "#{@opts}\n"
|
133
160
|
exit -1
|
data/lib/gill/config.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module Gill
|
2
2
|
|
3
|
-
FROZENKEYS = [:version, :categories].freeze
|
4
|
-
|
5
3
|
module Settings
|
6
4
|
|
7
5
|
class Config
|
@@ -9,67 +7,112 @@ module Gill
|
|
9
7
|
|
10
8
|
attr_reader :home, :config_path, :cache_path, :settings, :cache, :repos
|
11
9
|
|
10
|
+
#
|
11
|
+
# Initialize Gill Configuration
|
12
|
+
#
|
13
|
+
# @param [String] home_path Override the default user home path.
|
14
|
+
#
|
12
15
|
def initialize(home_path=nil)
|
13
16
|
@home = home_path || File.expand_path('~')
|
14
17
|
@settings_path = File.join(@home, '.gillrc')
|
15
18
|
@cache_path = File.join(@home, '.gillcache')
|
19
|
+
Dir.chdir(@home)
|
16
20
|
file_check!
|
17
21
|
version_check!
|
18
22
|
check_default_folders!
|
19
23
|
self
|
20
24
|
end
|
21
25
|
|
26
|
+
#
|
27
|
+
# Gill File Check
|
28
|
+
#
|
22
29
|
def file_check!
|
23
|
-
|
24
30
|
if File.exists?(@settings_path)
|
25
31
|
load_gill_settings
|
26
32
|
else
|
27
33
|
setup_gill_settings
|
28
34
|
end
|
29
|
-
|
30
35
|
if File.exists?(@cache_path)
|
31
36
|
load_gill_cache
|
32
37
|
else
|
33
38
|
setup_gill_cache
|
34
39
|
end
|
35
|
-
|
36
40
|
end
|
37
41
|
|
42
|
+
#
|
43
|
+
# Gill Categories
|
44
|
+
#
|
45
|
+
# @return [Hash] Gill Category Hash
|
46
|
+
#
|
38
47
|
def categories
|
39
48
|
@repos = @cache[:categories]
|
40
49
|
end
|
41
50
|
|
51
|
+
#
|
52
|
+
# Gill Source Path
|
53
|
+
#
|
54
|
+
# @return [String] Source Path
|
55
|
+
#
|
42
56
|
def source_path
|
43
57
|
@source_path = @settings[:source]
|
44
58
|
end
|
45
59
|
|
60
|
+
#
|
61
|
+
# Cache Path
|
62
|
+
#
|
63
|
+
# @return [String] Gill Cache Path
|
64
|
+
#
|
46
65
|
def cache_path
|
47
66
|
@source_path = @settings[:cache]
|
48
67
|
end
|
49
68
|
|
69
|
+
#
|
70
|
+
# Gill Settings Path
|
71
|
+
#
|
72
|
+
# @return [String] Gill Settings Path
|
73
|
+
#
|
50
74
|
def settings_path
|
51
75
|
@settings_path = @settings[:settings]
|
52
76
|
end
|
53
77
|
|
78
|
+
#
|
79
|
+
# Gill Default Path
|
80
|
+
#
|
81
|
+
# @return [String] Gill Default Clone Path
|
82
|
+
#
|
54
83
|
def default_path
|
55
84
|
@default_path = @settings[:default]
|
56
85
|
end
|
57
86
|
|
87
|
+
#
|
88
|
+
# Write Settings
|
89
|
+
#
|
90
|
+
# @param [Hash] settings Hash To Write To The Gill Settings
|
91
|
+
#
|
58
92
|
def write_settings(settings)
|
59
93
|
File.open(@settings_path, 'w') do |out|
|
60
94
|
YAML.dump(settings, out)
|
61
95
|
end
|
62
96
|
end
|
63
97
|
|
98
|
+
#
|
99
|
+
# Write Cache
|
100
|
+
#
|
101
|
+
# @param [Hash] cache Hash To Write To The Gill Cache
|
102
|
+
#
|
64
103
|
def write_cache(cache)
|
65
104
|
File.open(@cache_path, 'w') do |out|
|
66
105
|
YAML.dump(cache, out)
|
67
106
|
end
|
68
107
|
end
|
69
108
|
|
109
|
+
#
|
110
|
+
# List Gill Cloned Repos
|
111
|
+
#
|
112
|
+
#
|
70
113
|
def list_entries
|
71
114
|
STDERR.puts green("\n*** Listing Cloned Repositories ***\n")
|
72
|
-
categories.each do |category,repos|
|
115
|
+
categories.sort.each do |category,repos|
|
73
116
|
STDERR.puts "\t#{category}:"
|
74
117
|
repos.each do |repo|
|
75
118
|
STDERR.puts "\t #{green(repo[0])} => " + "#{repo[1][:repo]}"
|
@@ -78,23 +121,30 @@ module Gill
|
|
78
121
|
end
|
79
122
|
end
|
80
123
|
|
124
|
+
#
|
125
|
+
# Clean Cache
|
126
|
+
#
|
127
|
+
# Check the gill cache on load for missing
|
128
|
+
# values and remove.
|
129
|
+
#
|
81
130
|
def clean_cache
|
82
131
|
@clean_cache = Gill.config.cache
|
83
|
-
|
132
|
+
|
84
133
|
@clean_cache[:categories].each do |key,value|
|
85
|
-
|
86
134
|
value.each do |k,v|
|
87
135
|
@clean_cache[:categories][key.to_sym].delete(k.to_sym) unless File.directory?(v[:path].to_s)
|
88
136
|
end
|
89
|
-
|
90
137
|
@clean_cache[:categories].delete(key.to_sym) if @clean_cache[:categories][key.to_sym].empty?
|
91
|
-
|
92
138
|
end
|
93
|
-
|
139
|
+
|
94
140
|
write_cache(@clean_cache)
|
95
|
-
|
96
141
|
end
|
97
142
|
|
143
|
+
#
|
144
|
+
# Gill Paths
|
145
|
+
#
|
146
|
+
# @return [Array] Array Of Gill Repo Paths
|
147
|
+
#
|
98
148
|
def paths
|
99
149
|
@paths = []
|
100
150
|
Gill.config.categories.each do |key,value|
|
@@ -104,25 +154,44 @@ module Gill
|
|
104
154
|
end
|
105
155
|
@paths
|
106
156
|
end
|
157
|
+
|
158
|
+
#
|
159
|
+
# Find Repo
|
160
|
+
#
|
161
|
+
# @param [String] repo_name Repository Name
|
162
|
+
#
|
163
|
+
# @return [String] Repository Path
|
164
|
+
#
|
165
|
+
def find_repo_paths_by_name(repo_name)
|
166
|
+
Gill.config.categories.each do |key,value|
|
167
|
+
value.each do |k,v|
|
168
|
+
STDOUT.puts "#{k} => #{green(v[:path])}" if repo_name =~ /#{k.to_s}/
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
107
172
|
|
108
173
|
private
|
109
174
|
|
110
175
|
def version_check!
|
111
176
|
unless current_settings_version && current_cache_version
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
ask("Would you like to update them now?", :default => true) do
|
116
|
-
remove_gill_configuration_files
|
117
|
-
file_check!
|
118
|
-
version_check!
|
119
|
-
end
|
120
|
-
|
177
|
+
update_gill_settings
|
178
|
+
update_gill_cache
|
121
179
|
end
|
122
180
|
end
|
123
181
|
|
182
|
+
def update_gill_cache
|
183
|
+
update_cache = @cache
|
184
|
+
update_cache[:version] = VERSION
|
185
|
+
write_cache(update_cache)
|
186
|
+
end
|
187
|
+
|
188
|
+
def update_gill_settings
|
189
|
+
update_settings = @settings
|
190
|
+
update_settings[:version] = VERSION
|
191
|
+
write_settings(update_settings)
|
192
|
+
end
|
193
|
+
|
124
194
|
def remove_gill_configuration_files
|
125
|
-
STDOUT.puts red("NOTICE: If you modified any paths in the .gillrc you will have to reconfigure them.\n")
|
126
195
|
FileUtils.rm_rf(@cache_path)
|
127
196
|
FileUtils.rm_rf(@settings_path)
|
128
197
|
end
|
@@ -164,8 +233,8 @@ module Gill
|
|
164
233
|
end
|
165
234
|
|
166
235
|
def check_default_folders!
|
167
|
-
FileUtils.
|
168
|
-
FileUtils.
|
236
|
+
FileUtils.mkdir_p(source_path)
|
237
|
+
FileUtils.mkdir_p(default_path)
|
169
238
|
end
|
170
239
|
|
171
240
|
end
|
data/lib/gill/gill.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'pathname'
|
3
3
|
require 'yaml'
|
4
|
-
require 'pp'
|
5
|
-
|
6
4
|
require 'gill/cli'
|
7
5
|
|
8
6
|
module Gill
|
@@ -11,15 +9,31 @@ module Gill
|
|
11
9
|
include CLI
|
12
10
|
end
|
13
11
|
|
12
|
+
#
|
13
|
+
# Gill config setter method
|
14
|
+
#
|
15
|
+
# @param [Object] config Settings::Config Object
|
16
|
+
#
|
14
17
|
def Gill.config=(config=nil)
|
15
18
|
@config = config
|
16
19
|
end
|
17
20
|
|
21
|
+
#
|
22
|
+
# Gill config getter method
|
23
|
+
#
|
24
|
+
# @return [Object] Settings::Config Object
|
25
|
+
#
|
18
26
|
def Gill.config
|
19
27
|
return @config if defined?(@config)
|
20
28
|
Gill.config = Settings::Config.new
|
21
29
|
end
|
22
30
|
|
31
|
+
#
|
32
|
+
# Setup
|
33
|
+
#
|
34
|
+
# Load the gill configuration
|
35
|
+
# files and parse options.
|
36
|
+
#
|
23
37
|
def Gill.setup
|
24
38
|
Gill.config
|
25
39
|
Gill.config.clean_cache
|
data/lib/gill/git.rb
CHANGED
@@ -1,83 +1,110 @@
|
|
1
1
|
module Gill
|
2
2
|
|
3
|
+
#
|
4
|
+
# GIT ENV Variables that interfere with paths
|
5
|
+
#
|
6
|
+
ENV_BLACKLIST = %w(GIT_DIR GIT_INDEX_FILE GIT_WORK_TREE)
|
7
|
+
|
3
8
|
class Git
|
4
9
|
include Helper
|
5
10
|
include Settings
|
6
11
|
|
7
12
|
attr_reader :category, :category_path, :repo_name, :repo_path
|
8
13
|
|
14
|
+
#
|
15
|
+
# Initialize New Git Object
|
16
|
+
#
|
17
|
+
# @param [String] category Repo Category
|
18
|
+
#
|
19
|
+
# @param [String] repo_name Repo Name
|
20
|
+
#
|
21
|
+
# @param [String] repo_uri Repo URI
|
22
|
+
#
|
9
23
|
def initialize(category,repo_name,repo_uri)
|
10
24
|
|
11
25
|
@repo_uri, @category, @repo_name = repo_uri, category, repo_name
|
12
26
|
|
13
|
-
|
14
|
-
|
15
|
-
else
|
16
|
-
@category = basename(Gill.config.default_path).to_s
|
17
|
-
@category_path = File.join(Gill.config.source_path, @category)
|
18
|
-
end
|
27
|
+
@category ||= File.basename(Gill.config.default_path)
|
28
|
+
@category_path = File.join(Gill.config.source_path, @category)
|
19
29
|
|
20
30
|
if @repo_name
|
21
31
|
@repo_path = File.join(@category_path, @repo_name)
|
22
32
|
else
|
23
33
|
@repo_path = @category_path
|
24
34
|
end
|
25
|
-
|
26
|
-
# Used for updating cloned repositories.
|
27
|
-
@matches = []
|
28
35
|
end
|
29
36
|
|
37
|
+
#
|
38
|
+
# Update Cache
|
39
|
+
#
|
40
|
+
# Update the gill cache of a successful clone
|
41
|
+
#
|
42
|
+
# and write changes to the Gill global cache.
|
43
|
+
#
|
30
44
|
def update_cache
|
31
45
|
cache = Gill.config.cache
|
32
46
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
47
|
+
cache[:categories][@category.to_sym] ||= {}
|
48
|
+
cache[:categories][@category.to_sym].merge!(
|
49
|
+
@repo_name.to_sym => {
|
50
|
+
:repo => @repo_uri,
|
51
|
+
:path => @repo_path
|
52
|
+
}
|
53
|
+
)
|
38
54
|
|
39
55
|
Gill.config.write_cache(cache)
|
40
56
|
end
|
41
57
|
|
58
|
+
#
|
42
59
|
# Create the repository category folder if it does not exist.
|
43
60
|
#
|
44
61
|
# @param [Boolean] make_folder
|
45
62
|
# Pass false to ignore the creation of the passed gill folder
|
46
63
|
#
|
47
64
|
def build_category_folder
|
48
|
-
|
49
|
-
|
65
|
+
FileUtils.mkdir_p(@category_path)
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Bundle
|
70
|
+
#
|
71
|
+
# @param [String] path Repository Path
|
72
|
+
#
|
73
|
+
def bundle_from_gemfile(path)
|
74
|
+
Dir.chdir(path) do
|
75
|
+
return unless File.exists?('Gemfile')
|
76
|
+
ask "Would you like to `bundle install`?", :default => true do
|
77
|
+
system('bundle install')
|
78
|
+
end
|
50
79
|
end
|
51
80
|
end
|
52
|
-
|
81
|
+
|
82
|
+
#
|
83
|
+
# Update/Bundle Repository
|
84
|
+
#
|
53
85
|
def update
|
54
|
-
|
55
|
-
paths = Dir[File.join(Gill.config.source_path,'**',@repo_name)]
|
56
|
-
|
86
|
+
paths = Dir[File.join(Gill.config.source_path,'**',@repo_name)]
|
57
87
|
paths.each do |path|
|
58
|
-
|
59
88
|
if Gill.config.paths.include?(path)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
89
|
+
ask "Update #{basename(path)} => #{green(path)}?", :default => true do
|
90
|
+
Dir.chdir(path) do
|
91
|
+
system('git', 'pull', 'origin', 'master')
|
92
|
+
bundle_from_gemfile(path)
|
93
|
+
end
|
64
94
|
end
|
65
|
-
|
66
95
|
end
|
67
|
-
|
68
96
|
end
|
69
97
|
end
|
70
98
|
|
71
99
|
#
|
72
100
|
# Clone the passed repository uri name.
|
73
101
|
#
|
74
|
-
def clone
|
75
|
-
if File.directory?(@repo_path)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
102
|
+
def clone(bundle_install=true)
|
103
|
+
raise(DirectoryError, "destination path '#{@repo_path}' already exists and is not an empty directory.") if File.directory?(@repo_path)
|
104
|
+
build_category_folder
|
105
|
+
ENV_BLACKLIST.each(&(ENV.method(:delete)))
|
106
|
+
update_cache if system('git', 'clone', @repo_uri, @repo_path)
|
107
|
+
bundle_from_gemfile(@repo_path) if bundle_install
|
81
108
|
end
|
82
109
|
|
83
110
|
|
data/lib/gill/helper.rb
CHANGED
@@ -1,35 +1,76 @@
|
|
1
1
|
module Gill
|
2
|
-
|
2
|
+
|
3
3
|
module Helper
|
4
|
-
|
4
|
+
|
5
|
+
#
|
6
|
+
# Green
|
7
|
+
#
|
8
|
+
# @param [String] msg Message to format.
|
9
|
+
#
|
10
|
+
# @return [String] Green Colored String
|
11
|
+
#
|
5
12
|
def green(msg)
|
6
13
|
"\e[32m#{msg}\e[0m"
|
7
14
|
end
|
8
|
-
|
15
|
+
|
16
|
+
#
|
17
|
+
# Blue
|
18
|
+
#
|
19
|
+
# @param [String] msg Message to format.
|
20
|
+
#
|
21
|
+
# @return [String] Blue Colored String
|
22
|
+
#
|
9
23
|
def blue(msg)
|
10
24
|
"\e[34m#{msg}\e[0m"
|
11
25
|
end
|
12
|
-
|
26
|
+
|
27
|
+
#
|
28
|
+
# Red
|
29
|
+
#
|
30
|
+
# @param [String] msg Message to format.
|
31
|
+
#
|
32
|
+
# @return [String] Red Colored String
|
33
|
+
#
|
13
34
|
def red(msg)
|
14
35
|
"\e[31m#{msg}\e[0m"
|
15
36
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
37
|
+
|
38
|
+
#
|
39
|
+
# Basename
|
40
|
+
#
|
41
|
+
# @param [String] path Path to extract the basename from
|
42
|
+
#
|
43
|
+
# @return [Object] Pathname Object
|
44
|
+
#
|
22
45
|
def basename(path)
|
23
46
|
Pathname.new(path).basename
|
24
47
|
end
|
25
|
-
|
48
|
+
|
49
|
+
#
|
50
|
+
# Parent Name
|
51
|
+
#
|
52
|
+
# @param [String] path Path to extract the parent folder name from
|
53
|
+
#
|
54
|
+
# @return [String] Parent Folder Name
|
55
|
+
#
|
26
56
|
def parent(path)
|
27
57
|
Pathname.new(path).parent
|
28
58
|
end
|
29
|
-
|
59
|
+
|
60
|
+
#
|
61
|
+
# Empty Folder?
|
62
|
+
#
|
63
|
+
# @param [String] folder Path to folder
|
64
|
+
#
|
65
|
+
# @return [true,false] Return true if the folder is empty.
|
66
|
+
#
|
30
67
|
def folder_empty?(folder)
|
31
|
-
|
32
|
-
|
68
|
+
if File.exists?(folder)
|
69
|
+
return true unless Dir.enum_for(:foreach, folder).any? {|n| /\A\.\.?\z/ !~ n}
|
70
|
+
return false
|
71
|
+
else
|
72
|
+
return false
|
73
|
+
end
|
33
74
|
end
|
34
75
|
|
35
76
|
# Prompt the use for input
|
@@ -38,17 +79,17 @@ module Gill
|
|
38
79
|
# Message to prompt for user input.
|
39
80
|
#
|
40
81
|
# @param [Hash] options
|
41
|
-
#
|
82
|
+
#
|
42
83
|
# @option options [Symbol, String] :default
|
43
84
|
# The default option for a return.
|
44
85
|
#
|
45
86
|
def ask(msg, options={})
|
46
87
|
default = options[:default] || false
|
47
|
-
|
88
|
+
|
48
89
|
if default
|
49
|
-
STDOUT.print "#{msg} [Y/n] "
|
90
|
+
STDOUT.print "#{green("INFO")} #{msg} [Y/n] "
|
50
91
|
else
|
51
|
-
STDOUT.print "#{msg} [y/N] "
|
92
|
+
STDOUT.print "#{green("INFO")} #{msg} [y/N] "
|
52
93
|
end
|
53
94
|
input = STDIN.gets.chomp
|
54
95
|
STDOUT.flush
|
@@ -63,7 +104,7 @@ module Gill
|
|
63
104
|
end
|
64
105
|
end
|
65
106
|
end
|
66
|
-
|
107
|
+
|
67
108
|
end
|
68
109
|
|
69
|
-
end
|
110
|
+
end
|
data/lib/gill/import.rb
CHANGED
@@ -12,6 +12,11 @@ module Gill
|
|
12
12
|
STDOUT.puts "Please wait..."
|
13
13
|
end
|
14
14
|
|
15
|
+
#
|
16
|
+
# Import
|
17
|
+
#
|
18
|
+
# @param [String] path Override Default Import Path
|
19
|
+
#
|
15
20
|
def import(path=nil)
|
16
21
|
|
17
22
|
if path.nil?
|
@@ -23,16 +28,30 @@ module Gill
|
|
23
28
|
search_folder(folder)
|
24
29
|
end
|
25
30
|
|
26
|
-
|
31
|
+
#
|
32
|
+
# Find Repo
|
33
|
+
#
|
34
|
+
# @param [String] path Folder Path
|
35
|
+
#
|
36
|
+
# @param [String] repo_name Repository Name
|
37
|
+
#
|
38
|
+
# @param [Object] parent Pathname Parent Pbject
|
39
|
+
#
|
40
|
+
def find_repo(path,repo_name,parent)
|
27
41
|
|
28
42
|
if has_git_folder?(path)
|
29
|
-
check_move_import(basename(parent.path),
|
43
|
+
check_move_import(basename(parent.path), repo_name, path) if has_git_config?(path)
|
30
44
|
else
|
31
45
|
import(path)
|
32
46
|
end
|
33
47
|
|
34
48
|
end
|
35
49
|
|
50
|
+
#
|
51
|
+
# Search Folder
|
52
|
+
#
|
53
|
+
# @param [String] folder Folder Path
|
54
|
+
#
|
36
55
|
def search_folder(folder)
|
37
56
|
current_folder = Dir.new(folder)
|
38
57
|
|
@@ -44,14 +63,28 @@ module Gill
|
|
44
63
|
|
45
64
|
end
|
46
65
|
|
66
|
+
#
|
67
|
+
# Check, Move & import
|
68
|
+
#
|
69
|
+
# @param [String] basename Basename Of The Repository Path
|
70
|
+
#
|
71
|
+
# @param [String] repo_name Repository Name
|
72
|
+
#
|
73
|
+
# @param [Object] path Pathname Parent Object
|
74
|
+
#
|
47
75
|
def check_move_import(basename,repo_name,path)
|
48
76
|
git_uri = git_uri_for(path)
|
49
77
|
|
50
78
|
if repo_in_root(basename)
|
79
|
+
prompt = "Do you want to move #{basename(Gill.config.source_path)}/#{basename(repo_name)} to",
|
80
|
+
"#{basename(Gill.config.source_path)}/#{basename(Gill.config.default_path)}/#{basename(repo_name)}?"
|
51
81
|
|
52
|
-
ask
|
82
|
+
ask prompt, :default => false do
|
53
83
|
move_root_repos_to_default_path(path,File.join(Gill.config.source_path, basename(Gill.config.default_path), repo_name))
|
54
|
-
add(basename(Gill.config.default_path),repo_name,git_uri,
|
84
|
+
add(basename(Gill.config.default_path),repo_name,git_uri,
|
85
|
+
File.join(Gill.config.source_path,
|
86
|
+
basename(Gill.config.default_path),
|
87
|
+
repo_name))
|
55
88
|
end
|
56
89
|
|
57
90
|
else
|
@@ -60,15 +93,35 @@ module Gill
|
|
60
93
|
|
61
94
|
end
|
62
95
|
|
96
|
+
#
|
97
|
+
# Has Git?
|
98
|
+
#
|
99
|
+
# @param [String] path Folder Path
|
100
|
+
#
|
101
|
+
# @return [true,false] Retrun true if the .git folder is found.
|
102
|
+
#
|
63
103
|
def has_git_config?(path)
|
64
104
|
return true if File.exist?(File.join(path, '.git', 'config'))
|
65
105
|
false
|
66
106
|
end
|
67
107
|
|
68
|
-
|
69
|
-
|
108
|
+
#
|
109
|
+
# Move Repository
|
110
|
+
#
|
111
|
+
# @param [String] source Repository Source Path
|
112
|
+
# @param [String] destination Repository Destination Path
|
113
|
+
#
|
114
|
+
def move_root_repos_to_default_path(source,destination)
|
115
|
+
FileUtils.mv(source,destination)
|
70
116
|
end
|
71
117
|
|
118
|
+
#
|
119
|
+
# Git URI For Path
|
120
|
+
#
|
121
|
+
# @param [String] path Repository Path
|
122
|
+
#
|
123
|
+
# @return [String] Return the git uri for a path.
|
124
|
+
#
|
72
125
|
def git_uri_for(path)
|
73
126
|
File.open(File.join(path, '.git', 'config'), 'r') do |file|
|
74
127
|
@git_uri = file.read[/url\s+\=\s+(\S+)/m,1]
|
@@ -77,16 +130,23 @@ module Gill
|
|
77
130
|
@git_uri
|
78
131
|
end
|
79
132
|
|
133
|
+
#
|
134
|
+
# Add Repository
|
135
|
+
#
|
136
|
+
# @param [String] category Repository Category
|
137
|
+
#
|
138
|
+
# @param [String] repo_name Repository Name
|
139
|
+
#
|
140
|
+
# @param [String] git_uri Repository URI
|
141
|
+
#
|
142
|
+
# @param [String] path Repository Path
|
143
|
+
#
|
80
144
|
def add(category,repo_name,git_uri,path)
|
81
|
-
|
82
145
|
if @updated_cache[:categories].has_key?(category.to_s.downcase.to_sym)
|
83
|
-
|
84
146
|
@updated_cache[:categories][category.to_s.downcase.to_sym].merge!({repo_name.to_sym => {:repo => git_uri, :path => path}})
|
85
|
-
|
86
147
|
else
|
87
148
|
@updated_cache[:categories][category.to_s.downcase.to_sym] = { repo_name.to_sym => { :repo => git_uri, :path => path }}
|
88
149
|
end
|
89
|
-
|
90
150
|
end
|
91
151
|
|
92
152
|
def update_cache
|
@@ -94,11 +154,27 @@ module Gill
|
|
94
154
|
Gill.config.write_cache(@updated_cache)
|
95
155
|
end
|
96
156
|
|
157
|
+
#
|
158
|
+
# Repository In Root
|
159
|
+
#
|
160
|
+
# @param [String] folder Folder Path
|
161
|
+
#
|
162
|
+
# @return [true,false] Return true if the Repository
|
163
|
+
# is in the root dir.
|
164
|
+
#
|
97
165
|
def repo_in_root(folder)
|
98
166
|
return true if folder.to_s == basename(Gill.config.source_path).to_s
|
99
167
|
false
|
100
168
|
end
|
101
169
|
|
170
|
+
#
|
171
|
+
# Has Git Folder
|
172
|
+
#
|
173
|
+
# @param [String] path Folder Path
|
174
|
+
#
|
175
|
+
# @return [true,false] Return true if the folder
|
176
|
+
# path contains a .git folder.
|
177
|
+
#
|
102
178
|
def has_git_folder?(path)
|
103
179
|
temp = Dir.new(path)
|
104
180
|
|
data/lib/gill/remove.rb
CHANGED
@@ -4,6 +4,13 @@ module Gill
|
|
4
4
|
include Helper
|
5
5
|
include Settings
|
6
6
|
|
7
|
+
attr_reader :category, :category_path, :repo_name, :repo_path
|
8
|
+
|
9
|
+
#
|
10
|
+
# Initialize New Remove Object
|
11
|
+
#
|
12
|
+
# @param [String] args Arguments - Path,RepoName,Category
|
13
|
+
#
|
7
14
|
def initialize(args)
|
8
15
|
@args = args.split(/\#/)
|
9
16
|
@category, @repo_name = @args.first, @args.last
|
@@ -12,7 +19,12 @@ module Gill
|
|
12
19
|
@parent_folders = []
|
13
20
|
end
|
14
21
|
|
15
|
-
|
22
|
+
#
|
23
|
+
# Remove Repo
|
24
|
+
#
|
25
|
+
# @param [true,false] force Forcefully remove a repository.
|
26
|
+
#
|
27
|
+
def remove_repo(force=false)
|
16
28
|
remove_repository_files if category_exists? && repo_exists?
|
17
29
|
end
|
18
30
|
|
@@ -23,12 +35,13 @@ module Gill
|
|
23
35
|
end
|
24
36
|
|
25
37
|
def cached_repo_path
|
26
|
-
Gill.config.categories[@category.to_sym][@repo_name.to_sym][:path]
|
38
|
+
return Gill.config.categories[@category.to_sym][@repo_name.to_sym][:path] if Gill.config.categories.has_key?(@category.to_sym)
|
39
|
+
raise(CategoryMissing, red("Unknown Category: #{@category}"))
|
27
40
|
end
|
28
41
|
|
29
42
|
def category_exists?
|
30
43
|
return true if File.directory?(@category_path)
|
31
|
-
if Gill.config.categories.has_key?(@
|
44
|
+
if Gill.config.categories.has_key?(@category.to_sym)
|
32
45
|
return true if File.directory?(cached_repo_path)
|
33
46
|
end
|
34
47
|
raise(CategoryMissing, red("Unknown Category: #{@category}"))
|
@@ -72,5 +85,4 @@ module Gill
|
|
72
85
|
end
|
73
86
|
|
74
87
|
end
|
75
|
-
|
76
88
|
end
|
data/lib/gill/version.rb
CHANGED
data/lib/gill.rb
CHANGED
data/spec/gill_spec.rb
CHANGED
data/spec/git_spec.rb
CHANGED
@@ -7,13 +7,7 @@ describe Git do
|
|
7
7
|
Gill.config = Settings::Config.new('/tmp')
|
8
8
|
@uri = Parse.new('git://github.com/mephux/gill.git')
|
9
9
|
@git = Git.new(@uri.category, @uri.folder, @uri.repo)
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
after(:all) do
|
14
|
-
FileUtils.rm_rf('/tmp/source')
|
15
|
-
FileUtils.rm_rf('/tmp/.gillrc')
|
16
|
-
FileUtils.rm_rf('/tmp/.gillcache')
|
10
|
+
@git.clone(false)
|
17
11
|
end
|
18
12
|
|
19
13
|
it "should parse the empty category name as false" do
|
@@ -43,5 +37,37 @@ describe Git do
|
|
43
37
|
it "should have a repo path of /tmp/source/misc/gill" do
|
44
38
|
@git.repo_path.should == '/tmp/source/misc/gill'
|
45
39
|
end
|
40
|
+
|
41
|
+
it "should create a new folder for the cloned repo" do
|
42
|
+
File.should exist(File.join(Gill.config.default_path, @uri.folder))
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should create a GemFile" do
|
46
|
+
File.should exist(File.join(Gill.config.default_path, @uri.folder, 'Gemfile'))
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should delete GIT_DIR from ENV" do
|
50
|
+
ENV['GIT_DIR'].should be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should delete GIT_INDEX_FILE from ENV" do
|
54
|
+
ENV['GIT_INDEX_FILE'].should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should delete GIT_WORK_TREE from ENV" do
|
58
|
+
ENV['GIT_WORK_TREE'].should be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not propegate GIT_DIR" do
|
62
|
+
`echo $GIT_DIR`.strip.should be_empty
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should not propegate GIT_INDEX_FILE" do
|
66
|
+
`echo $GIT_INDEX_FILE`.strip.should be_empty
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should not propegate GIT_WORK_TREE" do
|
70
|
+
`echo $GIT_WORK_TREE`.strip.should be_empty
|
71
|
+
end
|
46
72
|
|
47
73
|
end
|
data/spec/remove_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "gill/gill"
|
3
|
+
|
4
|
+
describe Remove do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
Gill.config = Settings::Config.new('/tmp')
|
8
|
+
@remove = Remove.new('misc#gill')
|
9
|
+
@remove.remove_repo(true)
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
FileUtils.rm_rf('/tmp/source')
|
14
|
+
FileUtils.rm_rf('/tmp/.gillrc')
|
15
|
+
FileUtils.rm_rf('/tmp/.gillcache')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse the remove category name as misc" do
|
19
|
+
@remove.category.should == 'misc'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should parse the repo_path as /tmp/source/misc/gill" do
|
23
|
+
@remove.repo_path.should == '/tmp/source/misc/gill'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 1.0.0
|
9
|
+
version: 1.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dustin Willis Webber
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-26 00:00:00 -04:00
|
18
18
|
default_executable: gill
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -25,7 +25,7 @@ executables:
|
|
25
25
|
extensions: []
|
26
26
|
|
27
27
|
extra_rdoc_files:
|
28
|
-
- LICENSE
|
28
|
+
- LICENSE.txt
|
29
29
|
- README.rdoc
|
30
30
|
files:
|
31
31
|
- .gitignore
|
@@ -33,13 +33,14 @@ files:
|
|
33
33
|
- .yardopts
|
34
34
|
- Gemfile
|
35
35
|
- Gemfile.lock
|
36
|
-
- LICENSE
|
36
|
+
- LICENSE.txt
|
37
37
|
- README.rdoc
|
38
38
|
- Rakefile
|
39
39
|
- bin/gill
|
40
40
|
- lib/gill.rb
|
41
41
|
- lib/gill/cli.rb
|
42
42
|
- lib/gill/config.rb
|
43
|
+
- lib/gill/core_extension/symbol.rb
|
43
44
|
- lib/gill/exceptions.rb
|
44
45
|
- lib/gill/exceptions/argument_error.rb
|
45
46
|
- lib/gill/exceptions/cache_error.rb
|
@@ -59,6 +60,7 @@ files:
|
|
59
60
|
- spec/config_spec.rb
|
60
61
|
- spec/gill_spec.rb
|
61
62
|
- spec/git_spec.rb
|
63
|
+
- spec/remove_spec.rb
|
62
64
|
- spec/spec.opts
|
63
65
|
- spec/spec_helper.rb
|
64
66
|
has_rdoc: yard
|
@@ -75,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
77
|
requirements:
|
76
78
|
- - ">="
|
77
79
|
- !ruby/object:Gem::Version
|
78
|
-
hash:
|
80
|
+
hash: 2163447694756148579
|
79
81
|
segments:
|
80
82
|
- 0
|
81
83
|
version: "0"
|
@@ -98,4 +100,5 @@ test_files:
|
|
98
100
|
- spec/config_spec.rb
|
99
101
|
- spec/gill_spec.rb
|
100
102
|
- spec/git_spec.rb
|
103
|
+
- spec/remove_spec.rb
|
101
104
|
- spec/spec_helper.rb
|