gill 0.1.2 → 1.0.0.rc.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/README.rdoc +3 -3
- data/bin/gill +0 -1
- data/gill.gemspec +5 -3
- data/lib/gill/config/cache.rb +17 -16
- data/lib/gill/config/setup.rb +10 -1
- data/lib/gill/exceptions/cache_error.rb +5 -0
- data/lib/gill/exceptions.rb +1 -0
- data/lib/gill/gill.rb +85 -58
- data/lib/gill/git.rb +11 -6
- data/lib/gill/helper.rb +12 -5
- data/lib/gill/import.rb +113 -0
- data/lib/gill/parse.rb +41 -0
- data/lib/gill/remove.rb +74 -31
- data/lib/gill/version.rb +1 -1
- metadata +14 -10
data/README.rdoc
CHANGED
@@ -34,7 +34,7 @@ Gill Usage:
|
|
34
34
|
|
35
35
|
Cloning a git repository with gill:
|
36
36
|
|
37
|
-
$ gill https://
|
37
|
+
$ gill https://github.com/mephux/Snorby.git#rails#snorby-dev
|
38
38
|
Initialized empty Git repository in /Users/mephux/Source/rails/snorby-dev/.git/
|
39
39
|
remote: Counting objects: 7958, done.
|
40
40
|
remote: Compressing objects: 100% (3367/3367), done.
|
@@ -44,7 +44,7 @@ Cloning a git repository with gill:
|
|
44
44
|
|
45
45
|
This will create a folder called 'rails' and clone the repo inside a folder called 'snorby'. ie: '/Users/mephux/Source/rails/snorby-dev/'
|
46
46
|
|
47
|
-
gill https://
|
47
|
+
gill https://github.com/mephux/gill.git#ruby
|
48
48
|
gill http://github.com/jruby/jruby.git#jruby
|
49
49
|
gill http://github.com/ronin-ruby/ronin.git#security#ronin-dev
|
50
50
|
gill http://github.com/postmodern/spidr.git#security#spidr-dev
|
@@ -72,7 +72,7 @@ Listing cloned repositories:
|
|
72
72
|
spidr-dev => http://github.com/postmodern/spidr.git
|
73
73
|
|
74
74
|
rails:
|
75
|
-
snorby-dev => https://
|
75
|
+
snorby-dev => https://github.com/mephux/Snorby.git
|
76
76
|
|
77
77
|
Removing cloned repositories:
|
78
78
|
|
data/bin/gill
CHANGED
data/gill.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gill}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0.rc.2"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dustin Willis Webber"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-30}
|
13
13
|
s.default_executable = %q{gill}
|
14
14
|
s.description = %q{Gill is a simple Ruby app to help keep your git clones clean and organized.}
|
15
15
|
s.email = %q{dustin.webber@gmail.com}
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/gill/config/setup.rb",
|
35
35
|
"lib/gill/exceptions.rb",
|
36
36
|
"lib/gill/exceptions/argument_error.rb",
|
37
|
+
"lib/gill/exceptions/cache_error.rb",
|
37
38
|
"lib/gill/exceptions/category_missing.rb",
|
38
39
|
"lib/gill/exceptions/directory_error.rb",
|
39
40
|
"lib/gill/exceptions/error.rb",
|
@@ -43,6 +44,7 @@ Gem::Specification.new do |s|
|
|
43
44
|
"lib/gill/gill.rb",
|
44
45
|
"lib/gill/git.rb",
|
45
46
|
"lib/gill/helper.rb",
|
47
|
+
"lib/gill/import.rb",
|
46
48
|
"lib/gill/parse.rb",
|
47
49
|
"lib/gill/remove.rb",
|
48
50
|
"lib/gill/version.rb",
|
data/lib/gill/config/cache.rb
CHANGED
@@ -18,17 +18,16 @@ module Gill
|
|
18
18
|
# Find or created the gill cache file.
|
19
19
|
def find_or_create_cache
|
20
20
|
if File.exists?("#{@cache_path}")
|
21
|
-
@cache = YAML.load_file(@cache_path)
|
21
|
+
@cache = YAML.load_file(@cache_path)
|
22
22
|
else
|
23
23
|
build_cache
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
# Build the inital .gillache file in the user home directory.
|
28
|
-
# @return [Hash] the gill cache
|
28
|
+
# @return [Hash] the gill cache
|
29
29
|
def build_cache
|
30
|
-
|
31
|
-
new_cache = {}
|
30
|
+
new_cache = Hash.new
|
32
31
|
File.open(@cache_path, 'w') do |out|
|
33
32
|
YAML.dump(new_cache, out)
|
34
33
|
end
|
@@ -44,28 +43,30 @@ module Gill
|
|
44
43
|
YAML.dump(cache, out)
|
45
44
|
end
|
46
45
|
end
|
47
|
-
|
46
|
+
|
48
47
|
# Checks the current gill cache file for missing entries and removes them accordingly.
|
49
48
|
def cache_check!
|
50
49
|
|
51
|
-
updated_cache = cache
|
50
|
+
updated_cache = @cache
|
51
|
+
return if updated_cache.nil?
|
52
|
+
|
52
53
|
updated_cache.each do |key,value|
|
53
54
|
|
54
55
|
if File.directory?("#{source_path}/#{key}")
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
unless value.nil?
|
57
|
+
value.each do |skey,svalue|
|
58
|
+
|
59
|
+
unless File.directory?("#{svalue[:path]}")
|
60
|
+
updated_cache[:"#{key}"].delete(:"#{skey}")
|
61
|
+
end
|
62
|
+
|
59
63
|
end
|
60
64
|
end
|
61
|
-
|
62
|
-
else
|
63
|
-
|
64
|
-
updated_cache.delete(:"#{key}")
|
65
|
+
updated_cache.delete(:"#{key}") if updated_cache[:"#{key}"].values.empty?
|
65
66
|
end
|
66
|
-
|
67
|
+
|
67
68
|
end
|
68
|
-
|
69
|
+
|
69
70
|
rebuild_cache(updated_cache)
|
70
71
|
end
|
71
72
|
|
data/lib/gill/config/setup.rb
CHANGED
@@ -16,6 +16,11 @@ module Gill
|
|
16
16
|
if File.exists?("#{@config_path}")
|
17
17
|
find_or_create_cache
|
18
18
|
@config = YAML.load_file(@config_path)
|
19
|
+
|
20
|
+
unless File.exists?(@config[:default]) && File.directory?(@config[:default])
|
21
|
+
Dir.mkdir(@config[:default])
|
22
|
+
end
|
23
|
+
|
19
24
|
build_source_folder
|
20
25
|
else
|
21
26
|
build_config && find_or_create_cache
|
@@ -37,11 +42,15 @@ module Gill
|
|
37
42
|
def source_path
|
38
43
|
@config[:source]
|
39
44
|
end
|
45
|
+
|
46
|
+
def default_path
|
47
|
+
@config[:default]
|
48
|
+
end
|
40
49
|
|
41
50
|
# Build the initial .gillrc configuration file.
|
42
51
|
def build_config
|
43
52
|
|
44
|
-
config = { :home => @home, :config => @config_path, :source => "#{@home}/source", :cache => @cache_path }
|
53
|
+
config = { :home => @home, :config => @config_path, :source => "#{@home}/source", :default => "#{@home}/source/misc", :cache => @cache_path }
|
45
54
|
|
46
55
|
File.open(@config_path, 'w') do |out|
|
47
56
|
YAML.dump(config, out)
|
data/lib/gill/exceptions.rb
CHANGED
data/lib/gill/gill.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'optparse'
|
3
3
|
require 'yaml'
|
4
|
+
require 'pp'
|
4
5
|
|
5
6
|
require 'gill/config'
|
6
7
|
require 'gill/helper'
|
7
8
|
require 'gill/git'
|
9
|
+
require 'gill/import'
|
8
10
|
require 'gill/remove'
|
9
11
|
require 'gill/parse'
|
10
12
|
require 'gill/exceptions'
|
@@ -20,6 +22,9 @@ module Gill
|
|
20
22
|
# Run Gill
|
21
23
|
def Gill.run
|
22
24
|
Gill.optparse(*ARGV)
|
25
|
+
end
|
26
|
+
|
27
|
+
def Gill.pull
|
23
28
|
begin
|
24
29
|
uri = Parse.new(@options[:uri])
|
25
30
|
git = Git.new(uri.category, uri.folder, uri.repo)
|
@@ -31,59 +36,21 @@ module Gill
|
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
34
|
-
#
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
Gill.config # Load the gill configuration file
|
39
|
-
@opts = OptionParser.new
|
40
|
-
|
41
|
-
@options = {}
|
42
|
-
|
43
|
-
@opts.banner = "Gill - Git, Clone, Cleanliness.\nUsage: gill git://host/repository.git#category/sub-category/...\n\n"
|
44
|
-
|
45
|
-
@opts.on('-l','--list','List all cloned repositories.') do |list|
|
46
|
-
@options[:list] = list
|
47
|
-
end
|
48
|
-
|
49
|
-
@opts.on('-r ','--remove ','Remove a cloned repository. ie. -r category#folder') do |remove|
|
50
|
-
@options[:remove] = remove
|
51
|
-
end
|
52
|
-
|
53
|
-
@opts.on('-u ', '--update ','Update repository. ie. -u category#folder#branch') do |update|
|
54
|
-
@options[:update] = update
|
55
|
-
end
|
56
|
-
|
57
|
-
@opts.on('-h','--help','This help summary page.') do |help|
|
58
|
-
@options[:help] = help
|
59
|
-
end
|
60
|
-
|
61
|
-
@opts.on('-v','--version','Version number') do |version|
|
62
|
-
STDERR.puts "Version: #{Gill::VERSION}"
|
63
|
-
exit -1
|
64
|
-
end
|
65
|
-
|
39
|
+
#
|
40
|
+
# Import any preexisting repos intop the gill cache.
|
41
|
+
#
|
42
|
+
def Gill.import_to_gill
|
66
43
|
begin
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
Gill.list if @options[:list]
|
71
|
-
Gill.remove if @options[:remove]
|
72
|
-
Gill.update if @options[:update]
|
73
|
-
Gill.error if @options.empty? or @options[:uri].nil?
|
74
|
-
rescue OptionParser::MissingArgument => e
|
75
|
-
STDERR.puts e.message
|
76
|
-
STDERR.puts @opts
|
77
|
-
STDERR.puts "\n"
|
44
|
+
search = Import.new
|
45
|
+
search.import
|
46
|
+
search.update_cache
|
78
47
|
exit -1
|
79
|
-
rescue
|
80
|
-
STDERR.puts e
|
81
|
-
STDERR.puts @opts
|
82
|
-
STDERR.puts "\n"
|
48
|
+
rescue => e
|
49
|
+
STDERR.puts "Error: #{e}"
|
83
50
|
exit -1
|
84
51
|
end
|
85
52
|
end
|
86
|
-
|
53
|
+
|
87
54
|
# Update a gill repository.
|
88
55
|
def Gill.update
|
89
56
|
begin
|
@@ -110,11 +77,11 @@ module Gill
|
|
110
77
|
# List all gill cloned repositories.
|
111
78
|
def Gill.list
|
112
79
|
STDERR.puts "\n*** Listing Cloned Repositories ***\n\n"
|
113
|
-
unless
|
80
|
+
unless Gill.config.cache.nil?
|
114
81
|
Gill.config.cache.each do |type,repos|
|
115
82
|
STDERR.puts "\t#{type}:"
|
116
83
|
repos.each do |repo|
|
117
|
-
STDERR.puts "\t #{repo[0]} => " + "#{repo[1]}"
|
84
|
+
STDERR.puts "\t #{repo[0]} => " + "#{repo[1][:repo]}"
|
118
85
|
end
|
119
86
|
STDERR.puts "\n"
|
120
87
|
end
|
@@ -124,21 +91,81 @@ module Gill
|
|
124
91
|
|
125
92
|
# Remove a gill cloned repository.
|
126
93
|
def Gill.remove
|
127
|
-
|
94
|
+
begin
|
95
|
+
# Raise exception if the params are not seperated by a `#`.
|
128
96
|
raise(SyntaxError, "Invalid Syntax. Arguments must be separated by `#`. Example: gill -r category#title") unless @options[:remove] =~ /\#/
|
129
97
|
Remove.new(@options[:remove]).remove_repo
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
98
|
+
rescue Gill::DirectoryError => e
|
99
|
+
STDERR.puts "Error: #{e}"
|
100
|
+
rescue => e
|
101
|
+
STDERR.puts "Error: #{e}"
|
102
|
+
end
|
135
103
|
exit -1
|
136
104
|
end
|
137
105
|
|
106
|
+
# Gill option parser
|
107
|
+
# @param [Array] passed gill options.
|
108
|
+
def Gill.optparse(*args)
|
109
|
+
|
110
|
+
|
111
|
+
Gill.config # Load the gill configuration file
|
112
|
+
|
113
|
+
@opts = OptionParser.new
|
114
|
+
|
115
|
+
@options = {}
|
116
|
+
|
117
|
+
@opts.banner = "Gill - Git, Clone, Cleanliness.\nUsage: gill git://host/repository.git#category/sub-category/...\n\n"
|
118
|
+
|
119
|
+
@opts.on('-l','--list','List all cloned repositories.') do |list|
|
120
|
+
Gill.list
|
121
|
+
end
|
122
|
+
|
123
|
+
@opts.on('-r ','--remove ','Remove a cloned repository. ie. -r category#folder') do |remove|
|
124
|
+
@options[:remove] = remove
|
125
|
+
Gill.remove
|
126
|
+
end
|
127
|
+
|
128
|
+
@opts.on('-u ', '--update ','Update repository. ie. -u category#folder#branch') do |update|
|
129
|
+
@options[:update] = update
|
130
|
+
Gill.update
|
131
|
+
end
|
132
|
+
|
133
|
+
@opts.on('-i','--import','Import untracked repository.') do |import|
|
134
|
+
Gill.import_to_gill
|
135
|
+
end
|
136
|
+
|
137
|
+
@opts.on('-h','--help','This help summary page.') do |help|
|
138
|
+
Gill.usage
|
139
|
+
end
|
140
|
+
|
141
|
+
@opts.on('-v','--version','Version number') do |version|
|
142
|
+
STDERR.puts "Version: #{Gill::VERSION}"
|
143
|
+
exit -1
|
144
|
+
end
|
145
|
+
|
146
|
+
begin
|
147
|
+
|
148
|
+
@args = @opts.parse!(args)
|
149
|
+
@options[:uri] = @args[0]
|
150
|
+
Gill.usage if @options.empty? || @options[:uri].nil?
|
151
|
+
Gill.pull
|
152
|
+
rescue OptionParser::MissingArgument => e
|
153
|
+
STDERR.puts e.message
|
154
|
+
STDERR.puts @opts
|
155
|
+
STDERR.puts "\n"
|
156
|
+
exit -1
|
157
|
+
rescue OptionParser::InvalidOption => e
|
158
|
+
STDERR.puts e.message
|
159
|
+
STDERR.puts @opts
|
160
|
+
STDERR.puts "\n"
|
161
|
+
exit -1
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
138
165
|
# Gill Error
|
139
166
|
# @return [Object] gill usage
|
140
|
-
def Gill.
|
141
|
-
|
167
|
+
def Gill.usage
|
168
|
+
STDOUT.puts "#{@opts}\n"
|
142
169
|
exit -1
|
143
170
|
end
|
144
171
|
|
data/lib/gill/git.rb
CHANGED
@@ -4,7 +4,7 @@ module Gill
|
|
4
4
|
class Git
|
5
5
|
# Include the gill cache convenience methods.
|
6
6
|
include Config::Cache
|
7
|
-
include
|
7
|
+
include Helper
|
8
8
|
|
9
9
|
# Initialize a new gill git instance.
|
10
10
|
#
|
@@ -24,7 +24,10 @@ module Gill
|
|
24
24
|
if @category
|
25
25
|
@category_path = File.join(Gill.config.source_path, @category)
|
26
26
|
else
|
27
|
-
|
27
|
+
# If passed only a repository uri.
|
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)
|
28
31
|
@category_path = File.join(Gill.config.source_path, @category)
|
29
32
|
end
|
30
33
|
|
@@ -58,13 +61,13 @@ module Gill
|
|
58
61
|
updated_cache = Gill.config.cache
|
59
62
|
|
60
63
|
if updated_cache.nil?
|
61
|
-
updated_cache = updated_cache.merge!({:"#{@category}" => {:"#{@folder}" => @repo}})
|
64
|
+
updated_cache = updated_cache.merge!({:"#{@category}" => {:"#{@folder}" => { :repo => @repo, :path => @folder_path }}})
|
62
65
|
else
|
63
66
|
|
64
67
|
if updated_cache[:"#{@category}"]
|
65
|
-
updated_cache[:"#{@category}"] = updated_cache[:"#{@category}"].merge!({:"#{@folder}" => @repo})
|
68
|
+
updated_cache[:"#{@category}"] = updated_cache[:"#{@category}"].merge!({:"#{@folder}" => { :repo => @repo, :path => @folder_path }})
|
66
69
|
else
|
67
|
-
updated_cache = updated_cache.merge!({:"#{@category}" => {:"#{@folder}" => @repo}})
|
70
|
+
updated_cache = updated_cache.merge!({:"#{@category}" => {:"#{@folder}" => { :repo => @repo, :path => @folder_path }}})
|
68
71
|
end
|
69
72
|
|
70
73
|
end
|
@@ -87,7 +90,9 @@ module Gill
|
|
87
90
|
end
|
88
91
|
end
|
89
92
|
|
90
|
-
#
|
93
|
+
#
|
94
|
+
# Clone the passed repository uri name.
|
95
|
+
#
|
91
96
|
def clone
|
92
97
|
|
93
98
|
if File.directory?(@folder_path) && @folder
|
data/lib/gill/helper.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
module Gill
|
2
2
|
module Helper
|
3
3
|
|
4
|
+
def basename(path)
|
5
|
+
Pathname.new(path).basename
|
6
|
+
end
|
7
|
+
|
8
|
+
def folder_empty?(folder)
|
9
|
+
Dir.enum_for(:foreach, folder).any? {|n| /\A\.\.?\z/ !~ n}
|
10
|
+
end
|
11
|
+
|
4
12
|
# Prompt the use for input
|
5
13
|
#
|
6
14
|
# @param [String] msg
|
@@ -12,8 +20,9 @@ module Gill
|
|
12
20
|
# The default option for a return.
|
13
21
|
#
|
14
22
|
def ask(msg, options={})
|
15
|
-
default = options[:default] ||
|
16
|
-
|
23
|
+
default = options[:default] || false
|
24
|
+
|
25
|
+
if default
|
17
26
|
STDOUT.print "#{msg} [Y/n] "
|
18
27
|
else
|
19
28
|
STDOUT.print "#{msg} [y/N] "
|
@@ -27,10 +36,8 @@ module Gill
|
|
27
36
|
elsif input[/([Nn]|[Nn]o)$/i]
|
28
37
|
exit -1
|
29
38
|
else
|
30
|
-
yield if default
|
39
|
+
yield if default
|
31
40
|
end
|
32
|
-
else
|
33
|
-
exit -1
|
34
41
|
end
|
35
42
|
end
|
36
43
|
|
data/lib/gill/import.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Gill
|
4
|
+
|
5
|
+
class Import
|
6
|
+
# Include the gill cache convenience methods.
|
7
|
+
include Config::Cache
|
8
|
+
include Helper
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@updated_cache = Gill.config.cache || {}
|
12
|
+
STDOUT.puts "Please wait..."
|
13
|
+
end
|
14
|
+
|
15
|
+
def import(path=nil)
|
16
|
+
|
17
|
+
if path.nil?
|
18
|
+
folder = Gill.config.source_path
|
19
|
+
else
|
20
|
+
folder = path
|
21
|
+
end
|
22
|
+
|
23
|
+
search_folder(folder)
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_repo(path,file,parent)
|
27
|
+
|
28
|
+
if has_git_folder?(path)
|
29
|
+
check_move_import(basename(parent.path), file, path) if has_git_config?(path)
|
30
|
+
else
|
31
|
+
import(path)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def search_folder(folder)
|
37
|
+
current_folder = Dir.new(folder)
|
38
|
+
|
39
|
+
current_folder.entries.each do |file|
|
40
|
+
next if %w(. ..).include?(file)
|
41
|
+
path = File.join(current_folder.path, file)
|
42
|
+
find_repo(path,file,current_folder) if File.directory?(path)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def check_move_import(basename,repo_name,path)
|
48
|
+
git_uri = git_uri_for(path)
|
49
|
+
|
50
|
+
if repo_in_root(basename)
|
51
|
+
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, 'misc', repo_name))
|
53
|
+
add(basename(Gill.config.default_path),repo_name,git_uri,File.join(Gill.config.source_path, 'misc', repo_name))
|
54
|
+
end
|
55
|
+
else
|
56
|
+
add(basename,repo_name,git_uri,path)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def has_git_config?(path)
|
62
|
+
return true if File.exist?(File.join(path, '.git', 'config'))
|
63
|
+
false
|
64
|
+
end
|
65
|
+
|
66
|
+
def move_root_repos_to_default_path(src,dest)
|
67
|
+
FileUtils.mv(src,dest)
|
68
|
+
end
|
69
|
+
|
70
|
+
def git_uri_for(path)
|
71
|
+
File.open(File.join(path, '.git', 'config'), 'r') do |file|
|
72
|
+
@git_uri = file.read[/url\s+\=\s+(\S+)/m,1]
|
73
|
+
file.close
|
74
|
+
end
|
75
|
+
@git_uri
|
76
|
+
end
|
77
|
+
|
78
|
+
def add(category,repo_name,git_uri,path)
|
79
|
+
|
80
|
+
if @updated_cache.has_key?(category.to_s.downcase.to_sym)
|
81
|
+
|
82
|
+
@updated_cache[category.to_s.downcase.to_sym].merge!({repo_name.to_sym => {:repo => git_uri, :path => path}})
|
83
|
+
|
84
|
+
else
|
85
|
+
@updated_cache[category.to_s.downcase.to_sym] = { repo_name.to_sym => { :repo => git_uri, :path => path }}
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def update_cache
|
91
|
+
STDOUT.puts "Import Completed Successfully."
|
92
|
+
rebuild_cache(@updated_cache, Gill.config.cache_path)
|
93
|
+
end
|
94
|
+
|
95
|
+
def repo_in_root(folder)
|
96
|
+
return true if folder.to_s == basename(Gill.config.source_path).to_s
|
97
|
+
false
|
98
|
+
end
|
99
|
+
|
100
|
+
def has_git_folder?(path)
|
101
|
+
temp = Dir.new(path)
|
102
|
+
|
103
|
+
if temp.entries.include?('.git')
|
104
|
+
temp.close
|
105
|
+
return true
|
106
|
+
else
|
107
|
+
return false
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
data/lib/gill/parse.rb
CHANGED
@@ -4,23 +4,46 @@ module Gill
|
|
4
4
|
|
5
5
|
attr_accessor :category, :folder, :repo
|
6
6
|
|
7
|
+
# Initialize a ne wparse object.
|
8
|
+
#
|
9
|
+
# @param [String] uri
|
10
|
+
# The string to be parsed and retunred to create a gill cloned repository.
|
11
|
+
#
|
7
12
|
def initialize(uri)
|
8
13
|
@uri = uri.split(/\#/)
|
9
14
|
self.start
|
10
15
|
end
|
11
16
|
|
17
|
+
#
|
18
|
+
# Setter for the parsed objects category.
|
19
|
+
#
|
12
20
|
def category=(category)
|
13
21
|
@category = category
|
14
22
|
end
|
15
23
|
|
24
|
+
#
|
25
|
+
# Setter for the parsed objects folder.
|
26
|
+
#
|
16
27
|
def folder=(folder)
|
17
28
|
@folder = folder
|
18
29
|
end
|
19
30
|
|
31
|
+
#
|
32
|
+
# Setter for the parsed objects repository uri.
|
33
|
+
#
|
34
|
+
# @param [String] repo
|
35
|
+
# The parsed objects repository uri.
|
36
|
+
#
|
37
|
+
# @return [String] repo
|
38
|
+
# The uri for the repository.
|
39
|
+
#
|
20
40
|
def repo=(repo)
|
21
41
|
@repo = repo
|
22
42
|
end
|
23
43
|
|
44
|
+
#
|
45
|
+
# Set and verefiy the category, folder and repository uri for the parsed object.
|
46
|
+
#
|
24
47
|
def start
|
25
48
|
self.category = @uri.first
|
26
49
|
|
@@ -49,6 +72,15 @@ module Gill
|
|
49
72
|
end
|
50
73
|
end
|
51
74
|
|
75
|
+
#
|
76
|
+
# Find the folder name from the repository uri.
|
77
|
+
#
|
78
|
+
# @param [String] repo
|
79
|
+
# The uri for the remote repository.
|
80
|
+
#
|
81
|
+
# @return [String] repo
|
82
|
+
# The folder/project name of the passed uri.
|
83
|
+
#
|
52
84
|
def get_folder(repo)
|
53
85
|
|
54
86
|
if repo =~ /\.git/i
|
@@ -60,6 +92,15 @@ module Gill
|
|
60
92
|
repo_name
|
61
93
|
end
|
62
94
|
|
95
|
+
#
|
96
|
+
# Check to verify the passed uri is a valid repository uri.
|
97
|
+
#
|
98
|
+
# @param [String] repo
|
99
|
+
# The uri to the remote repository.
|
100
|
+
#
|
101
|
+
# @return [String] repo
|
102
|
+
# Return the repository uri if it is indeed a valid uri.
|
103
|
+
#
|
63
104
|
def valid?(repo)
|
64
105
|
case repo
|
65
106
|
when repo[/\A(http|https|git)\:\/\/\S+[\:|\/]\S+[\.git|\Z]\Z/i]
|
data/lib/gill/remove.rb
CHANGED
@@ -1,25 +1,38 @@
|
|
1
1
|
module Gill
|
2
2
|
|
3
3
|
class Remove
|
4
|
+
|
5
|
+
# include the cache methods
|
4
6
|
include Config::Cache
|
7
|
+
|
8
|
+
# include all helper methods
|
5
9
|
include Helper
|
6
10
|
|
11
|
+
# Initialize a remove object.
|
12
|
+
#
|
13
|
+
# @param [String] args
|
14
|
+
# The string to be parsed for the remove object.
|
15
|
+
#
|
7
16
|
def initialize(args)
|
8
17
|
data = args.split('#')
|
18
|
+
# Raise ArgumentError if passed the incorrect amount of arguments.
|
9
19
|
raise(ArgumentError, 'Wrong number of arguments.') if data.length != 2
|
10
20
|
@source = Gill.config.source_path
|
11
21
|
@category = data.first
|
12
22
|
@folder = data.last
|
13
23
|
end
|
14
24
|
|
25
|
+
#
|
26
|
+
# remove the repository from the gill cache.
|
27
|
+
#
|
15
28
|
def remove_cache
|
16
29
|
updated_cache = Gill.config.cache
|
17
30
|
|
18
|
-
if updated_cache[
|
19
|
-
updated_cache[
|
31
|
+
if updated_cache[@category.to_sym]
|
32
|
+
updated_cache[@category.to_sym].delete(@folder.to_sym)
|
20
33
|
|
21
|
-
if updated_cache[
|
22
|
-
updated_cache.delete(
|
34
|
+
if updated_cache[@category.to_sym].empty?
|
35
|
+
updated_cache.delete(@category.to_sym)
|
23
36
|
rebuild_cache(updated_cache, Gill.config.cache_path)
|
24
37
|
return true
|
25
38
|
|
@@ -33,36 +46,66 @@ module Gill
|
|
33
46
|
end
|
34
47
|
end
|
35
48
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
unless Dir.enum_for(:foreach, type_folder).any? {|n| /\A\.\.?\z/ !~ n}
|
54
|
-
ask "The `#{@category}` directory is empty. Would you like to remove it?", :default => :no do
|
55
|
-
STDOUT.puts "#{@category.capitalize} directory removed successfully."
|
56
|
-
FileUtils.rm_rf(type_folder)
|
57
|
-
end
|
58
|
-
end
|
49
|
+
#
|
50
|
+
# Return true if the passed key and value exists.
|
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]
|
63
|
+
end
|
64
|
+
@valid
|
65
|
+
end
|
59
66
|
|
67
|
+
#
|
68
|
+
# Return true or false if the passed folder contains any files and/or sub-folders.
|
69
|
+
#
|
70
|
+
def category_folder_empty?
|
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)
|
60
92
|
end
|
61
|
-
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# remove all files and folders associated with the remove object.
|
98
|
+
#
|
99
|
+
def remove_repo
|
100
|
+
instance_variable_set(:@type_folder, File.join(@source,@category))
|
101
|
+
instance_variable_set(:@repo_name, File.join(@source,@category,@folder))
|
102
|
+
check_gill_cache_and_folders
|
103
|
+
|
104
|
+
ask "Are you sure you want to remove #{@folder}?", :default => false do
|
105
|
+
STDOUT.puts "#{@folder.capitalize} removed successfully."
|
106
|
+
FileUtils.rm_rf(@repo_name)
|
107
|
+
remove_gill_category_folder
|
62
108
|
remove_cache
|
63
|
-
|
64
|
-
else
|
65
|
-
raise(DirectoryError, "The directory #{@source}/#{@category}/#{@folder} does not exist or was not cloned with gill.")
|
66
109
|
end
|
67
110
|
end
|
68
111
|
|
data/lib/gill/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
4
|
+
prerelease: true
|
6
5
|
segments:
|
7
|
-
- 0
|
8
6
|
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- rc
|
9
10
|
- 2
|
10
|
-
version: 0.
|
11
|
+
version: 1.0.0.rc.2
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Dustin Willis Webber
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-07-
|
19
|
+
date: 2010-07-30 00:00:00 -07:00
|
19
20
|
default_executable: gill
|
20
21
|
dependencies: []
|
21
22
|
|
@@ -44,6 +45,7 @@ files:
|
|
44
45
|
- lib/gill/config/setup.rb
|
45
46
|
- lib/gill/exceptions.rb
|
46
47
|
- lib/gill/exceptions/argument_error.rb
|
48
|
+
- lib/gill/exceptions/cache_error.rb
|
47
49
|
- lib/gill/exceptions/category_missing.rb
|
48
50
|
- lib/gill/exceptions/directory_error.rb
|
49
51
|
- lib/gill/exceptions/error.rb
|
@@ -53,6 +55,7 @@ files:
|
|
53
55
|
- lib/gill/gill.rb
|
54
56
|
- lib/gill/git.rb
|
55
57
|
- lib/gill/helper.rb
|
58
|
+
- lib/gill/import.rb
|
56
59
|
- lib/gill/parse.rb
|
57
60
|
- lib/gill/remove.rb
|
58
61
|
- lib/gill/version.rb
|
@@ -74,19 +77,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
77
|
requirements:
|
75
78
|
- - ">="
|
76
79
|
- !ruby/object:Gem::Version
|
77
|
-
hash:
|
80
|
+
hash: 1109104530552266926
|
78
81
|
segments:
|
79
82
|
- 0
|
80
83
|
version: "0"
|
81
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
85
|
none: false
|
83
86
|
requirements:
|
84
|
-
- - "
|
87
|
+
- - ">"
|
85
88
|
- !ruby/object:Gem::Version
|
86
|
-
hash: 3
|
87
89
|
segments:
|
88
|
-
-
|
89
|
-
|
90
|
+
- 1
|
91
|
+
- 3
|
92
|
+
- 1
|
93
|
+
version: 1.3.1
|
90
94
|
requirements: []
|
91
95
|
|
92
96
|
rubyforge_project:
|