gill 1.0.0.rc.4 → 1.0.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.
- data/Gemfile +3 -1
- data/Gemfile.lock +26 -0
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.rdoc +10 -10
- data/bin/gill +1 -1
- data/lib/gill/cli.rb +138 -0
- data/lib/gill/config.rb +168 -25
- data/lib/gill/gill.rb +13 -156
- data/lib/gill/git.rb +42 -59
- data/lib/gill/helper.rb +28 -5
- data/lib/gill/import.rb +11 -9
- data/lib/gill/remove.rb +51 -88
- data/lib/gill/version.rb +1 -2
- data/spec/config_spec.rb +47 -0
- data/spec/gill_spec.rb +4 -2
- data/spec/git_spec.rb +47 -0
- data/spec/spec_helper.rb +15 -2
- metadata +15 -18
- data/gill.gemspec +0 -79
- data/lib/gill/config/cache.rb +0 -75
- data/lib/gill/config/setup.rb +0 -77
- data/spec/parse_spec.rb +0 -37
data/lib/gill/git.rb
CHANGED
@@ -1,72 +1,42 @@
|
|
1
|
-
require 'tempfile'
|
2
1
|
module Gill
|
3
2
|
|
4
3
|
class Git
|
5
|
-
# Include the gill cache convenience methods.
|
6
|
-
include Config::Cache
|
7
4
|
include Helper
|
5
|
+
include Settings
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# The category for the new cloned repository
|
13
|
-
#
|
14
|
-
# @param [String] folder
|
15
|
-
# The folder name in which the cloned repository will be stored
|
16
|
-
#
|
17
|
-
# @param [String] repo
|
18
|
-
# The git uri for the repository
|
19
|
-
#
|
20
|
-
def initialize(category,folder,repo)
|
7
|
+
attr_reader :category, :category_path, :repo_name, :repo_path
|
8
|
+
|
9
|
+
def initialize(category,repo_name,repo_uri)
|
21
10
|
|
22
|
-
@
|
11
|
+
@repo_uri, @category, @repo_name = repo_uri, category, repo_name
|
23
12
|
|
24
13
|
if @category
|
25
14
|
@category_path = File.join(Gill.config.source_path, @category)
|
26
15
|
else
|
27
|
-
|
28
|
-
# Set the category name to misc by default.
|
29
|
-
# TODO: Add the default repo sub-folder name to the gill configuration file.
|
30
|
-
@category = basename(Gill.config.default_path)
|
16
|
+
@category = basename(Gill.config.default_path).to_s
|
31
17
|
@category_path = File.join(Gill.config.source_path, @category)
|
32
18
|
end
|
33
19
|
|
34
|
-
if @
|
35
|
-
@
|
36
|
-
else
|
37
|
-
@folder_path = @category_path
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
# Update A Repository
|
43
|
-
#
|
44
|
-
# @param [String] branch
|
45
|
-
# The branch to git pull
|
46
|
-
#
|
47
|
-
def update(branch='master')
|
48
|
-
raise(CategoryMissing, "Unknown Category: `#{@folder}`") unless File.directory?(@category_path)
|
49
|
-
raise(RepositoryMissing, "Unknown Repository: `#{@folder}`") unless File.directory?(@folder_path)
|
50
|
-
Dir.chdir(@folder_path)
|
51
|
-
STDOUT.puts "Updating #{@folder} repository."
|
52
|
-
if system('git', 'pull', 'origin', branch)
|
53
|
-
STDOUT.puts "#{@folder.capitalize} updated successfully."
|
20
|
+
if @repo_name
|
21
|
+
@repo_path = File.join(@category_path, @repo_name)
|
54
22
|
else
|
55
|
-
|
23
|
+
@repo_path = @category_path
|
56
24
|
end
|
25
|
+
|
26
|
+
# Used for updating cloned repositories.
|
27
|
+
@matches = []
|
57
28
|
end
|
58
29
|
|
59
|
-
|
60
|
-
|
61
|
-
updated_cache = Gill.config.cache
|
30
|
+
def update_cache
|
31
|
+
cache = Gill.config.cache
|
62
32
|
|
63
|
-
if
|
64
|
-
|
33
|
+
if cache[:categories].has_key?(@category.to_sym)
|
34
|
+
cache[:categories][@category.to_sym] = cache[:categories][@category.to_sym].merge!({@repo_name.to_sym => { :repo => @repo_uri, :path => @repo_path }})
|
65
35
|
else
|
66
|
-
|
36
|
+
cache[:categories].merge!(@category.to_sym => { @repo_name.to_sym => { :repo => @repo_uri, :path => @repo_path }})
|
67
37
|
end
|
68
38
|
|
69
|
-
|
39
|
+
Gill.config.write_cache(cache)
|
70
40
|
end
|
71
41
|
|
72
42
|
# Create the repository category folder if it does not exist.
|
@@ -74,29 +44,42 @@ module Gill
|
|
74
44
|
# @param [Boolean] make_folder
|
75
45
|
# Pass false to ignore the creation of the passed gill folder
|
76
46
|
#
|
77
|
-
def
|
47
|
+
def build_category_folder
|
78
48
|
unless File.directory?(@category_path)
|
79
49
|
FileUtils.mkdir_p(@category_path)
|
80
50
|
end
|
81
51
|
end
|
52
|
+
|
53
|
+
def update
|
54
|
+
|
55
|
+
paths = Dir[File.join(Gill.config.source_path,'**',@repo_name)]
|
56
|
+
|
57
|
+
paths.each do |path|
|
58
|
+
|
59
|
+
if Gill.config.paths.include?(path)
|
60
|
+
|
61
|
+
ask "Update #{blue(basename(path))} => #{green(path)}?", :default => true do
|
62
|
+
Dir.chdir(path)
|
63
|
+
system('git', 'pull', 'origin', 'master')
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
82
70
|
|
83
71
|
#
|
84
72
|
# Clone the passed repository uri name.
|
85
73
|
#
|
86
74
|
def clone
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
raise(DirectoryError, "destination path '#{@folder_path}' already exists and is not an empty directory.")
|
91
|
-
|
75
|
+
if File.directory?(@repo_path)
|
76
|
+
raise(DirectoryError, red("destination path '#{@repo_path}' already exists and is not an empty directory."))
|
92
77
|
else
|
93
|
-
|
94
|
-
|
95
|
-
build_cache if system('git', 'clone', @repo, @folder_path)
|
96
|
-
|
78
|
+
build_category_folder
|
79
|
+
update_cache if system('git', 'clone', @repo_uri, @repo_path)
|
97
80
|
end
|
98
81
|
end
|
99
82
|
|
100
|
-
end
|
101
83
|
|
84
|
+
end
|
102
85
|
end
|
data/lib/gill/helper.rb
CHANGED
@@ -1,12 +1,35 @@
|
|
1
1
|
module Gill
|
2
|
+
|
2
3
|
module Helper
|
3
|
-
|
4
|
+
|
5
|
+
def green(msg)
|
6
|
+
"\e[32m#{msg}\e[0m"
|
7
|
+
end
|
8
|
+
|
9
|
+
def blue(msg)
|
10
|
+
"\e[34m#{msg}\e[0m"
|
11
|
+
end
|
12
|
+
|
13
|
+
def red(msg)
|
14
|
+
"\e[31m#{msg}\e[0m"
|
15
|
+
end
|
16
|
+
|
17
|
+
def gill_error(msg)
|
18
|
+
STDERR.puts red("#{msg}")
|
19
|
+
exit -1
|
20
|
+
end
|
21
|
+
|
4
22
|
def basename(path)
|
5
23
|
Pathname.new(path).basename
|
6
24
|
end
|
7
25
|
|
26
|
+
def parent(path)
|
27
|
+
Pathname.new(path).parent
|
28
|
+
end
|
29
|
+
|
8
30
|
def folder_empty?(folder)
|
9
|
-
Dir.enum_for(:foreach, folder).any? {|n| /\A\.\.?\z/ !~ n}
|
31
|
+
return true unless Dir.enum_for(:foreach, folder).any? {|n| /\A\.\.?\z/ !~ n}
|
32
|
+
false
|
10
33
|
end
|
11
34
|
|
12
35
|
# Prompt the use for input
|
@@ -34,13 +57,13 @@ module Gill
|
|
34
57
|
if input[/([Yy]|[Yy]es)$/i]
|
35
58
|
yield
|
36
59
|
elsif input[/([Nn]|[Nn]o)$/i]
|
37
|
-
|
60
|
+
return
|
38
61
|
else
|
39
62
|
yield if default
|
40
63
|
end
|
41
64
|
end
|
42
65
|
end
|
43
66
|
|
44
|
-
|
45
67
|
end
|
46
|
-
|
68
|
+
|
69
|
+
end
|
data/lib/gill/import.rb
CHANGED
@@ -4,11 +4,11 @@ module Gill
|
|
4
4
|
|
5
5
|
class Import
|
6
6
|
# Include the gill cache convenience methods.
|
7
|
-
include Config::Cache
|
8
7
|
include Helper
|
8
|
+
include Settings
|
9
9
|
|
10
10
|
def initialize
|
11
|
-
@updated_cache = Gill.config.cache
|
11
|
+
@updated_cache = Gill.config.cache
|
12
12
|
STDOUT.puts "Please wait..."
|
13
13
|
end
|
14
14
|
|
@@ -48,10 +48,12 @@ module Gill
|
|
48
48
|
git_uri = git_uri_for(path)
|
49
49
|
|
50
50
|
if repo_in_root(basename)
|
51
|
+
|
51
52
|
ask "Do you want to move #{basename(Gill.config.source_path)}/#{basename(repo_name)} to #{basename(Gill.config.source_path)}/#{basename(Gill.config.default_path)}/#{basename(repo_name)}?", :default => false do
|
52
|
-
move_root_repos_to_default_path(path,File.join(Gill.config.source_path,
|
53
|
-
add(basename(Gill.config.default_path),repo_name,git_uri,File.join(Gill.config.source_path,
|
53
|
+
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,File.join(Gill.config.source_path, basename(Gill.config.default_path), repo_name))
|
54
55
|
end
|
56
|
+
|
55
57
|
else
|
56
58
|
add(basename,repo_name,git_uri,path)
|
57
59
|
end
|
@@ -77,19 +79,19 @@ module Gill
|
|
77
79
|
|
78
80
|
def add(category,repo_name,git_uri,path)
|
79
81
|
|
80
|
-
if @updated_cache.has_key?(category.to_s.downcase.to_sym)
|
82
|
+
if @updated_cache[:categories].has_key?(category.to_s.downcase.to_sym)
|
81
83
|
|
82
|
-
@updated_cache[category.to_s.downcase.to_sym].merge!({repo_name.to_sym => {:repo => git_uri, :path => path}})
|
84
|
+
@updated_cache[:categories][category.to_s.downcase.to_sym].merge!({repo_name.to_sym => {:repo => git_uri, :path => path}})
|
83
85
|
|
84
86
|
else
|
85
|
-
@updated_cache[category.to_s.downcase.to_sym] = { repo_name.to_sym => { :repo => git_uri, :path => path }}
|
87
|
+
@updated_cache[:categories][category.to_s.downcase.to_sym] = { repo_name.to_sym => { :repo => git_uri, :path => path }}
|
86
88
|
end
|
87
89
|
|
88
90
|
end
|
89
91
|
|
90
92
|
def update_cache
|
91
|
-
STDOUT.puts "Import Completed Successfully."
|
92
|
-
|
93
|
+
STDOUT.puts green("Import Completed Successfully.")
|
94
|
+
Gill.config.write_cache(@updated_cache)
|
93
95
|
end
|
94
96
|
|
95
97
|
def repo_in_root(folder)
|
data/lib/gill/remove.rb
CHANGED
@@ -1,113 +1,76 @@
|
|
1
1
|
module Gill
|
2
2
|
|
3
3
|
class Remove
|
4
|
-
|
5
|
-
# include the cache methods
|
6
|
-
include Config::Cache
|
7
|
-
|
8
|
-
# include all helper methods
|
9
4
|
include Helper
|
5
|
+
include Settings
|
10
6
|
|
11
|
-
# Initialize a remove object.
|
12
|
-
#
|
13
|
-
# @param [String] args
|
14
|
-
# The string to be parsed for the remove object.
|
15
|
-
#
|
16
7
|
def initialize(args)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@
|
21
|
-
@
|
22
|
-
@folder = data.last
|
8
|
+
@args = args.split(/\#/)
|
9
|
+
@category, @repo_name = @args.first, @args.last
|
10
|
+
@category_path = File.join(Gill.config.source_path, @category)
|
11
|
+
@repo_path = File.join(@category_path, @repo_name)
|
12
|
+
@parent_folders = []
|
23
13
|
end
|
24
14
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def remove_cache
|
29
|
-
updated_cache = Gill.config.cache
|
30
|
-
|
31
|
-
if updated_cache[@category.to_sym]
|
32
|
-
updated_cache[@category.to_sym].delete(@folder.to_sym)
|
15
|
+
def remove_repo
|
16
|
+
remove_repository_files if category_exists? && repo_exists?
|
17
|
+
end
|
33
18
|
|
34
|
-
|
35
|
-
updated_cache.delete(@category.to_sym)
|
36
|
-
rebuild_cache(updated_cache, Gill.config.cache_path)
|
37
|
-
return true
|
19
|
+
private
|
38
20
|
|
39
|
-
|
21
|
+
def clean_cache
|
22
|
+
Gill.config.clean_cache
|
23
|
+
end
|
40
24
|
|
41
|
-
|
42
|
-
|
25
|
+
def cached_repo_path
|
26
|
+
Gill.config.categories[@category.to_sym][@repo_name.to_sym][:path]
|
27
|
+
end
|
43
28
|
|
29
|
+
def category_exists?
|
30
|
+
return true if File.directory?(@category_path)
|
31
|
+
if Gill.config.categories.has_key?(@category_path.to_sym)
|
32
|
+
return true if File.directory?(cached_repo_path)
|
44
33
|
end
|
34
|
+
raise(CategoryMissing, red("Unknown Category: #{@category}"))
|
35
|
+
end
|
45
36
|
|
37
|
+
def repo_exists?
|
38
|
+
return true if File.directory?(@repo_path) || File.directory?(cached_repo_path)
|
39
|
+
raise(RepositoryMissing, red("Unknown Repository: #{@category}"))
|
46
40
|
end
|
47
|
-
end
|
48
41
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
# @param [Hash] args
|
53
|
-
# A key and value to check the existence of.
|
54
|
-
#
|
55
|
-
# @return [Boolean] valid
|
56
|
-
# Return true if the passed key and value exists in the gill cache file.
|
57
|
-
#
|
58
|
-
def keys_exist(args={})
|
59
|
-
@valid = true
|
60
|
-
args.each do |key,value|
|
61
|
-
@valid = false if !Gill.config.cache[key.to_sym]
|
62
|
-
@valid = false if !Gill.config.cache[key.to_sym][value.to_sym]
|
42
|
+
def known_category?(key)
|
43
|
+
return true if Gill.config.repos.has_key?(key.to_s.to_sym)
|
44
|
+
false
|
63
45
|
end
|
64
|
-
@valid
|
65
|
-
end
|
66
46
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
Dir.enum_for(:foreach, @type_folder).any? {|n| /\A\.\.?\z/ !~ n}
|
72
|
-
end
|
73
|
-
|
74
|
-
#
|
75
|
-
# Check Cache - Raise exceptions
|
76
|
-
#
|
77
|
-
def check_gill_cache_and_folders
|
78
|
-
raise(CategoryMissing, "Unknown Category: `#{@folder}`") unless File.directory?(@type_folder)
|
79
|
-
raise(RepositoryMissing, "Unknown Repository: `#{@folder}`") unless File.directory?(@repo_name)
|
80
|
-
raise(CacheError, 'The gill cache appears to be empty.') if Gill.config.cache.empty?
|
81
|
-
raise(DirectoryError, "The directory #{@repo_name} does not exist or was not cloned with gill.") unless keys_exist(:"#{@category}" => @folder)
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# Remove the gill category folder.
|
86
|
-
#
|
87
|
-
def remove_gill_category_folder
|
88
|
-
unless category_folder_empty?
|
89
|
-
ask "The `#{@category}` directory is empty. Would you like to remove it?", :default => false do
|
90
|
-
STDOUT.puts "#{@category.capitalize} directory removed successfully."
|
91
|
-
FileUtils.rm_rf(@type_folder)
|
47
|
+
def find_parents_for_repo(path)
|
48
|
+
unless basename(path).to_s == basename(Gill.config.source_path).to_s
|
49
|
+
@parent_folders << path if known_category?(basename(path))
|
50
|
+
find_parents_for_repo(parent(path))
|
92
51
|
end
|
93
52
|
end
|
94
|
-
end
|
95
53
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
54
|
+
def remove_repository_files
|
55
|
+
find_parents_for_repo(cached_repo_path)
|
56
|
+
|
57
|
+
ask "Are you sure you want to remove the repository: #{@repo_name}?", :default => false do
|
58
|
+
STDOUT.puts green("#{@repo_name.capitalize} removed successfully.")
|
59
|
+
FileUtils.rm_rf(cached_repo_path)
|
60
|
+
end
|
61
|
+
|
62
|
+
@parent_folders.each do |path|
|
63
|
+
if folder_empty?(path)
|
64
|
+
unless basename(path).to_s == basename(Gill.config.default_path).to_s
|
65
|
+
ask "Would you like to remove the empty parent folder: #{basename(path)}?", :default => false do
|
66
|
+
STDOUT.puts green("#{path.to_s.capitalize} removed successfully.")
|
67
|
+
FileUtils.rm_rf(path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
109
72
|
end
|
110
|
-
end
|
111
73
|
|
112
74
|
end
|
75
|
+
|
113
76
|
end
|
data/lib/gill/version.rb
CHANGED
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Settings::Config do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Gill.config = Settings::Config.new('/tmp')
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:all) do
|
10
|
+
FileUtils.rm_rf('/tmp/source')
|
11
|
+
FileUtils.rm_rf('/tmp/.gillrc')
|
12
|
+
FileUtils.rm_rf('/tmp/.gillcache')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have a source path ok /tmp/source" do
|
16
|
+
Gill.config.source_path.should == '/tmp/source'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have a default path of /tmp/source/misc" do
|
20
|
+
Gill.config.default_path.should == '/tmp/source/misc'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have a cache path of /tmp/.gillcache" do
|
24
|
+
Gill.config.cache_path.should == '/tmp/.gillcache'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have a configuration path of /tmp/.gillrc" do
|
28
|
+
Gill.config.settings_path.should == '/tmp/.gillrc'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have created a .gillcache file." do
|
32
|
+
File.should exist(Gill.config.cache_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have created a .gillrc file." do
|
36
|
+
File.should exist(Gill.config.settings_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have created a source folder." do
|
40
|
+
File.should exist(Gill.config.source_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have created a default repository location folder." do
|
44
|
+
File.should exist(Gill.config.default_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|