gill 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/bin/gill +1 -0
- data/gill.gemspec +7 -3
- data/lib/gill/config/cache.rb +74 -0
- data/lib/gill/config/setup.rb +68 -0
- data/lib/gill/config.rb +18 -90
- data/lib/gill/exceptions/error.rb +1 -1
- data/lib/gill/exceptions.rb +4 -0
- data/lib/gill/gill.rb +144 -0
- data/lib/gill/git.rb +42 -29
- data/lib/gill/helper.rb +39 -0
- data/lib/gill/parse.rb +11 -0
- data/lib/gill/remove.rb +31 -10
- data/lib/gill/version.rb +1 -1
- data/lib/gill.rb +1 -174
- metadata +8 -4
- data/lib/gill/app.rb +0 -58
data/README.rdoc
CHANGED
@@ -22,10 +22,10 @@ Gill Usage:
|
|
22
22
|
|
23
23
|
-l, --list List all cloned repositories.
|
24
24
|
-r, --remove Remove a cloned repository. ie. -r category#folder
|
25
|
+
-u, --update Update repository. ie. -u category#folder#branch
|
25
26
|
-h, --help This help summary page.
|
26
27
|
-v, --version Version number
|
27
28
|
|
28
|
-
|
29
29
|
Cloning a git repository with gill:
|
30
30
|
|
31
31
|
$ gill https://mephux@github.com/mephux/Snorby.git#rails#snorby-dev
|
@@ -102,4 +102,4 @@ Only the parent folder to the cloned repo will be removed.
|
|
102
102
|
|
103
103
|
== Copyright
|
104
104
|
|
105
|
-
Copyright (c) 2010 Dustin Willis Webber. See LICENSE for details.
|
105
|
+
Copyright (c) 2010 Dustin Willis Webber. See LICENSE for details.
|
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.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") 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-10}
|
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}
|
@@ -29,13 +29,17 @@ Gem::Specification.new do |s|
|
|
29
29
|
"bin/gill",
|
30
30
|
"gill.gemspec",
|
31
31
|
"lib/gill.rb",
|
32
|
-
"lib/gill/app.rb",
|
33
32
|
"lib/gill/config.rb",
|
33
|
+
"lib/gill/config/cache.rb",
|
34
|
+
"lib/gill/config/setup.rb",
|
35
|
+
"lib/gill/exceptions.rb",
|
34
36
|
"lib/gill/exceptions/argument_error.rb",
|
35
37
|
"lib/gill/exceptions/directory_error.rb",
|
36
38
|
"lib/gill/exceptions/error.rb",
|
37
39
|
"lib/gill/exceptions/repository_error.rb",
|
40
|
+
"lib/gill/gill.rb",
|
38
41
|
"lib/gill/git.rb",
|
42
|
+
"lib/gill/helper.rb",
|
39
43
|
"lib/gill/parse.rb",
|
40
44
|
"lib/gill/remove.rb",
|
41
45
|
"lib/gill/version.rb",
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Gill
|
2
|
+
class Config
|
3
|
+
|
4
|
+
module Cache
|
5
|
+
|
6
|
+
# Returns the gill cache yaml file.
|
7
|
+
# @return [Hash] the gill cache
|
8
|
+
def cache
|
9
|
+
@cache ||= find_or_create_cache
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns the path of the .gillcache file.
|
13
|
+
# @return [String] path to the gill cache file.
|
14
|
+
def cache_path
|
15
|
+
@cache_path
|
16
|
+
end
|
17
|
+
|
18
|
+
# Find or created the gill cache file.
|
19
|
+
def find_or_create_cache
|
20
|
+
if File.exists?("#{@cache_path}")
|
21
|
+
@cache = YAML.load_file(@cache_path) || build_cache
|
22
|
+
else
|
23
|
+
build_cache
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Build the inital .gillache file in the user home directory.
|
28
|
+
# @return [Hash] the gill cache
|
29
|
+
def build_cache
|
30
|
+
puts 'in build cache'
|
31
|
+
new_cache = {}
|
32
|
+
File.open(@cache_path, 'w') do |out|
|
33
|
+
YAML.dump(new_cache, out)
|
34
|
+
end
|
35
|
+
YAML.load_file(@cache_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Rebuild cache writes updated entries to the .gillache file in the user home directory.
|
39
|
+
# @param [String] path to the gill cache file
|
40
|
+
# @param [String] override the default cache path in the gill configuration file.
|
41
|
+
def rebuild_cache(cache, path=false)
|
42
|
+
@cache_path = path if path
|
43
|
+
File.open("#{@cache_path}", 'w+') do |out|
|
44
|
+
YAML.dump(cache, out)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Checks the current gill cache file for missing entries and removes them accordingly.
|
49
|
+
def cache_check!
|
50
|
+
|
51
|
+
updated_cache = cache
|
52
|
+
updated_cache.each do |key,value|
|
53
|
+
|
54
|
+
if File.directory?("#{source_path}/#{key}")
|
55
|
+
|
56
|
+
value.each do |skey,svalue|
|
57
|
+
unless File.directory?("#{source_path}/#{key}/#{skey}")
|
58
|
+
updated_cache[:"#{key}"].delete(:"#{skey}")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
else
|
63
|
+
|
64
|
+
updated_cache.delete(:"#{key}")
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
rebuild_cache(updated_cache)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Gill
|
2
|
+
class Config
|
3
|
+
|
4
|
+
module Setup
|
5
|
+
|
6
|
+
# Returns the gill configuration.
|
7
|
+
# @return [Hash] the gill configuration
|
8
|
+
def config
|
9
|
+
@config
|
10
|
+
end
|
11
|
+
|
12
|
+
# Finds or created the gill configuration file.
|
13
|
+
# @return [Hash] the gill configuration file
|
14
|
+
def find_or_create_config
|
15
|
+
|
16
|
+
if File.exists?("#{@config_path}")
|
17
|
+
find_or_create_cache
|
18
|
+
@config = YAML.load_file(@config_path)
|
19
|
+
build_source_folder
|
20
|
+
else
|
21
|
+
build_config && find_or_create_cache
|
22
|
+
@config = YAML.load_file(@config_path)
|
23
|
+
build_source_folder
|
24
|
+
end
|
25
|
+
|
26
|
+
YAML.load_file(@config_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
# The gill configuration path.
|
30
|
+
# @return [String] the gill configuration path
|
31
|
+
def config_path
|
32
|
+
@config_path
|
33
|
+
end
|
34
|
+
|
35
|
+
# The source folder path set in the gill configuration file.
|
36
|
+
# @return [String] the gill source folder path.
|
37
|
+
def source_path
|
38
|
+
@config[:source]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Build the initial .gillrc configuration file.
|
42
|
+
def build_config
|
43
|
+
|
44
|
+
config = { :home => @home, :config => @config_path, :source => "#{@home}/source", :cache => @cache_path }
|
45
|
+
|
46
|
+
File.open(@config_path, 'w') do |out|
|
47
|
+
YAML.dump(config, out)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
# Build the initial source directory configured in the .gillrc file.
|
53
|
+
# The initial source directory is only created if it does not exist.
|
54
|
+
def build_source_folder
|
55
|
+
|
56
|
+
unless File.directory?(@config[:source])
|
57
|
+
|
58
|
+
STDERR.puts "Creating Source Directory: " + "#{@config[:source]}"
|
59
|
+
Dir.mkdir(@config[:source])
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/gill/config.rb
CHANGED
@@ -1,102 +1,30 @@
|
|
1
|
+
require 'gill/config/setup'
|
2
|
+
require 'gill/config/cache'
|
3
|
+
|
1
4
|
module Gill
|
2
5
|
|
3
6
|
class Config
|
4
|
-
|
5
|
-
attr_accessor :config
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@home = File.expand_path('~')
|
9
|
-
@path = File.join(@home, '.gillrc')
|
10
|
-
@cache = File.join(@home, '.gillcache')
|
11
|
-
self.setup
|
12
|
-
end
|
13
7
|
|
14
|
-
#
|
15
|
-
|
16
|
-
#
|
17
|
-
def build_config
|
18
|
-
|
19
|
-
config = { :home => @home, :config => @path, :source => "#{@home}/source", :cache => @cache }
|
20
|
-
File.open(@path, 'w') do |out|
|
21
|
-
YAML.dump(config, out)
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# Build the initial source directory configured in the .gillrc file.
|
28
|
-
#
|
29
|
-
# The initial source directory is only created if it does not exist.
|
30
|
-
#
|
31
|
-
def build_source_folder
|
32
|
-
|
33
|
-
unless File.directory?(self.config[:source])
|
34
|
-
|
35
|
-
STDOUT.puts "Creating Source Directory: " + "#{self.config[:source]}"
|
36
|
-
Dir.mkdir(self.config[:source])
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
8
|
+
# Include the gill setup and cache convenience methods.
|
9
|
+
include Setup, Cache
|
41
10
|
|
42
|
-
|
43
|
-
# Build the inital .gillache file in the user home directory.
|
44
|
-
#
|
45
|
-
def build_cache
|
46
|
-
|
47
|
-
cache = { }
|
48
|
-
File.open(@cache, 'w') do |out|
|
49
|
-
|
50
|
-
YAML.dump(cache, out)
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
11
|
+
attr_reader :home, :config_path, :cache_path, :config, :cache
|
55
12
|
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
def self.rebuild_cache(path, cache)
|
60
|
-
|
61
|
-
File.open(path, 'w+') do |out|
|
62
|
-
|
63
|
-
YAML.dump(cache, out)
|
64
|
-
|
65
|
-
end
|
13
|
+
# Initialize the Gill configuration.
|
14
|
+
# @return [Object] the gill configuration
|
15
|
+
def initialize
|
66
16
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
def setup
|
17
|
+
@home = File.expand_path('~')
|
18
|
+
@config_path = File.join(@home, '.gillrc')
|
19
|
+
@cache_path = File.join(@home, '.gillcache')
|
20
|
+
@config = find_or_create_config
|
21
|
+
@cache = cache
|
22
|
+
cache_check! # Check The Cache For Missing Entries.
|
74
23
|
|
75
|
-
|
76
|
-
|
77
|
-
self.build_cache unless File.exists?("#{@cache}")
|
78
|
-
self.config = YAML.load_file(@path)
|
79
|
-
self.build_source_folder
|
80
|
-
|
81
|
-
else
|
82
|
-
|
83
|
-
self.build_config
|
84
|
-
self.build_cache unless File.exists?("#{@cache}")
|
85
|
-
self.config = YAML.load_file(@path)
|
86
|
-
self.build_source_folder
|
87
|
-
|
88
|
-
end
|
24
|
+
self
|
89
25
|
|
90
26
|
end
|
91
|
-
|
92
|
-
#
|
93
|
-
# Yaml
|
94
|
-
# return the configuration file in yaml format.
|
95
|
-
#
|
96
|
-
def yaml
|
97
|
-
self.config
|
98
|
-
end
|
99
|
-
|
27
|
+
|
100
28
|
end
|
101
|
-
|
29
|
+
|
102
30
|
end
|
data/lib/gill/gill.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'gill/config'
|
2
|
+
require 'gill/helper'
|
3
|
+
require 'gill/git'
|
4
|
+
require 'gill/remove'
|
5
|
+
require 'gill/parse'
|
6
|
+
require 'gill/version'
|
7
|
+
require 'gill/exceptions'
|
8
|
+
|
9
|
+
require 'fileutils'
|
10
|
+
require 'optparse'
|
11
|
+
require 'yaml'
|
12
|
+
|
13
|
+
module Gill
|
14
|
+
|
15
|
+
# Module method for the gill configuration.
|
16
|
+
# @return [Object] the gill configuration
|
17
|
+
def Gill.config
|
18
|
+
@config ||= Config.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# Run Gill
|
22
|
+
def Gill.run
|
23
|
+
Gill.optparse(*ARGV)
|
24
|
+
begin
|
25
|
+
uri = Parse.new(@options[:uri])
|
26
|
+
git = Git.new(uri.category, uri.folder, uri.repo)
|
27
|
+
git.clone
|
28
|
+
rescue TypeError => e
|
29
|
+
STDERR.puts "Error: #{e}\nError: Please make sure to remove all whitespace from the category and/or folder name."
|
30
|
+
rescue => e
|
31
|
+
STDERR.puts "Error: #{e}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Gill option parser
|
36
|
+
# @param [Array] passed gill options.
|
37
|
+
def Gill.optparse(*args)
|
38
|
+
|
39
|
+
Gill.config # Load the gill configuration file
|
40
|
+
@opts = OptionParser.new
|
41
|
+
|
42
|
+
@options = {}
|
43
|
+
|
44
|
+
@opts.banner = "Gill - Git, Clone, Cleanliness.\nUsage: gill git://host/repository.git#category/sub-category/...\n\n"
|
45
|
+
|
46
|
+
@opts.on('-l','--list','List all cloned repositories.') do |list|
|
47
|
+
@options[:list] = list
|
48
|
+
end
|
49
|
+
|
50
|
+
@opts.on('-r ','--remove ','Remove a cloned repository. ie. -r category#folder') do |remove|
|
51
|
+
@options[:remove] = remove
|
52
|
+
end
|
53
|
+
|
54
|
+
@opts.on('-u ', '--update ','Update repository. ie. -u category#folder#branch') do |update|
|
55
|
+
@options[:update] = update
|
56
|
+
end
|
57
|
+
|
58
|
+
@opts.on('-h','--help','This help summary page.') do |help|
|
59
|
+
@options[:help] = help
|
60
|
+
end
|
61
|
+
|
62
|
+
@opts.on('-v','--version','Version number') do |version|
|
63
|
+
STDERR.puts "Version: #{Gill::VERSION}"
|
64
|
+
exit -1
|
65
|
+
end
|
66
|
+
|
67
|
+
begin
|
68
|
+
@args = @opts.parse!(args)
|
69
|
+
@options[:uri] = @args[0]
|
70
|
+
Gill.error if @options[:help]
|
71
|
+
Gill.list if @options[:list]
|
72
|
+
Gill.remove if @options[:remove]
|
73
|
+
Gill.update if @options[:update]
|
74
|
+
Gill.error if @options.empty? or @options[:uri].nil?
|
75
|
+
rescue OptionParser::MissingArgument => e
|
76
|
+
STDERR.puts e.message
|
77
|
+
STDERR.puts @opts
|
78
|
+
STDERR.puts "\n"
|
79
|
+
exit -1
|
80
|
+
rescue OptionParser::InvalidOption => e
|
81
|
+
STDERR.puts e.message
|
82
|
+
STDERR.puts @opts
|
83
|
+
STDERR.puts "\n"
|
84
|
+
exit -1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Update a gill repository.
|
89
|
+
def Gill.update
|
90
|
+
begin
|
91
|
+
args = @options[:update].split(/\#/)
|
92
|
+
raise(ArgumentError, "Requires three arguments. category#title#branch") if args.length > 4
|
93
|
+
category, folder, branch = args
|
94
|
+
git = Git.new(category, folder, false)
|
95
|
+
if branch
|
96
|
+
git.update(branch)
|
97
|
+
else
|
98
|
+
git.update
|
99
|
+
end
|
100
|
+
exit -1
|
101
|
+
rescue TypeError => e
|
102
|
+
STDERR.puts "Error: #{e}\nError: Please make sure to remove all whitespace from the category and/or folder name."
|
103
|
+
exit -1
|
104
|
+
rescue => e
|
105
|
+
STDERR.puts "Error: #{e}"
|
106
|
+
exit -1
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# List all gill cloned repositories.
|
111
|
+
def Gill.list
|
112
|
+
STDERR.puts "\n*** Listing Cloned Repositories ***\n\n"
|
113
|
+
unless @config.cache.nil?
|
114
|
+
Gill.config.cache.each do |type,repos|
|
115
|
+
STDERR.puts "\t#{type}:"
|
116
|
+
repos.each do |repo|
|
117
|
+
STDERR.puts "\t #{repo[0]} => " + "#{repo[1]}"
|
118
|
+
end
|
119
|
+
STDERR.puts "\n"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
exit -1
|
123
|
+
end
|
124
|
+
|
125
|
+
# Remove a gill cloned repository.
|
126
|
+
def Gill.remove
|
127
|
+
begin
|
128
|
+
Remove.new(@options[:remove]).remove_repo
|
129
|
+
rescue Gill::DirectoryError => e
|
130
|
+
STDERR.puts "Error: #{e}"
|
131
|
+
rescue => e
|
132
|
+
STDERR.puts "Error: #{e}"
|
133
|
+
end
|
134
|
+
exit -1
|
135
|
+
end
|
136
|
+
|
137
|
+
# Gill Error
|
138
|
+
# @return [Object] gill usage
|
139
|
+
def Gill.error
|
140
|
+
STDERR.puts "#{@opts}\n"
|
141
|
+
exit -1
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
data/lib/gill/git.rb
CHANGED
@@ -1,12 +1,24 @@
|
|
1
1
|
module Gill
|
2
2
|
|
3
|
-
class Git
|
3
|
+
class Git
|
4
|
+
# Include the gill cache convenience methods.
|
5
|
+
include Config::Cache
|
4
6
|
|
7
|
+
# Initialize a new gill git instance.
|
8
|
+
#
|
9
|
+
# @param [String] category
|
10
|
+
# The category for the new cloned repository
|
11
|
+
#
|
12
|
+
# @param [String] folder
|
13
|
+
# The folder name in which the cloned repository will be stored
|
14
|
+
#
|
15
|
+
# @param [String] repo
|
16
|
+
# The git uri for the repository
|
17
|
+
#
|
5
18
|
def initialize(category,folder,repo)
|
6
|
-
super()
|
7
19
|
|
8
20
|
@repo, @category, @folder = repo, category, folder
|
9
|
-
@category_path = File.join(
|
21
|
+
@category_path = File.join(Gill.config.source_path, @category)
|
10
22
|
|
11
23
|
if @folder
|
12
24
|
@folder_path = File.join(@category_path, @folder)
|
@@ -16,7 +28,11 @@ module Gill
|
|
16
28
|
|
17
29
|
end
|
18
30
|
|
19
|
-
|
31
|
+
# Update A Repository
|
32
|
+
#
|
33
|
+
# @param [String] branch
|
34
|
+
# The branch to git pull
|
35
|
+
#
|
20
36
|
def update(branch='master')
|
21
37
|
Dir.chdir(@folder_path)
|
22
38
|
STDOUT.puts "Updating #{@folder} repository."
|
@@ -26,51 +42,48 @@ module Gill
|
|
26
42
|
STDOUT.puts "Failed to update #{@folder.capitalize} successfully."
|
27
43
|
end
|
28
44
|
end
|
29
|
-
|
45
|
+
|
46
|
+
# Update the gill cache after cloning a new repository.
|
30
47
|
def build_cache
|
48
|
+
updated_cache = Gill.config.cache
|
31
49
|
|
32
|
-
|
33
|
-
|
34
|
-
if old_cache[:"#{@category}"]
|
35
|
-
|
36
|
-
old_cache[:"#{@category}"] = old_cache[:"#{@category}"].merge!({:"#{@folder}" => @repo})
|
37
|
-
|
50
|
+
if updated_cache.nil?
|
51
|
+
updated_cache = updated_cache.merge!({:"#{@category}" => {:"#{@folder}" => @repo}})
|
38
52
|
else
|
39
|
-
|
40
|
-
|
53
|
+
|
54
|
+
if updated_cache[:"#{@category}"]
|
55
|
+
updated_cache[:"#{@category}"] = updated_cache[:"#{@category}"].merge!({:"#{@folder}" => @repo})
|
56
|
+
else
|
57
|
+
updated_cache = updated_cache.merge!({:"#{@category}" => {:"#{@folder}" => @repo}})
|
58
|
+
end
|
41
59
|
|
42
60
|
end
|
43
|
-
|
44
|
-
Gill::Config.rebuild_cache(@cache, old_cache)
|
45
|
-
|
61
|
+
rebuild_cache(updated_cache,Gill.config.cache_path)
|
46
62
|
end
|
47
63
|
|
64
|
+
# Create the repository category folder if it does not exist.
|
65
|
+
#
|
66
|
+
# @param [Boolean] make_folder
|
67
|
+
# Pass false to ignore the creation of the passed gill folder
|
68
|
+
#
|
48
69
|
def build_type_folder(make_folder=true)
|
49
|
-
|
50
70
|
unless File.directory?(@category_path)
|
51
|
-
|
52
71
|
FileUtils.mkdir_p(@category_path)
|
53
|
-
|
54
72
|
if make_folder
|
55
|
-
|
56
73
|
unless File.directory?(@folder_path)
|
57
|
-
|
58
74
|
FileUtils.mkdir_p(@folder_path)
|
59
|
-
|
60
75
|
end
|
61
|
-
|
62
76
|
end
|
63
77
|
end
|
64
78
|
end
|
65
|
-
|
79
|
+
|
80
|
+
#
|
81
|
+
#
|
82
|
+
#
|
66
83
|
def clone
|
67
|
-
|
68
84
|
if File.directory?(@folder_path) && @folder
|
69
|
-
|
70
85
|
raise(DirectoryError, "destination path '#{@folder_path}' already exists and is not an empty directory.")
|
71
|
-
|
72
86
|
else
|
73
|
-
|
74
87
|
if @folder
|
75
88
|
build_type_folder
|
76
89
|
build_cache if system('git', 'clone', @repo, @folder_path)
|
@@ -79,9 +92,9 @@ module Gill
|
|
79
92
|
Dir.chdir(@folder_path)
|
80
93
|
build_cache if system('git', 'clone', @repo)
|
81
94
|
end
|
82
|
-
|
83
95
|
end
|
84
96
|
end
|
85
97
|
|
86
98
|
end
|
99
|
+
|
87
100
|
end
|
data/lib/gill/helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Gill
|
2
|
+
module Helper
|
3
|
+
|
4
|
+
# Prompt the use for input
|
5
|
+
#
|
6
|
+
# @param [String] msg
|
7
|
+
# Message to prompt for user input.
|
8
|
+
#
|
9
|
+
# @param [Hash] options
|
10
|
+
#
|
11
|
+
# @option options [Symbol, String] :default
|
12
|
+
# The default option for a return.
|
13
|
+
#
|
14
|
+
def ask(msg, options={})
|
15
|
+
default = options[:default] || :yes
|
16
|
+
if default == :yes
|
17
|
+
STDOUT.print "#{msg} [Y/n] "
|
18
|
+
else
|
19
|
+
STDOUT.print "#{msg} [y/N] "
|
20
|
+
end
|
21
|
+
input = STDIN.gets.chomp
|
22
|
+
STDOUT.flush
|
23
|
+
|
24
|
+
if block_given?
|
25
|
+
if input[/([Yy]|[Yy]es)$/i]
|
26
|
+
yield
|
27
|
+
elsif input[/([Nn]|[Nn]o)$/i]
|
28
|
+
exit -1
|
29
|
+
else
|
30
|
+
yield if default == :yes
|
31
|
+
end
|
32
|
+
else
|
33
|
+
exit -1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/lib/gill/parse.rb
CHANGED
@@ -23,27 +23,38 @@ module Gill
|
|
23
23
|
|
24
24
|
def start
|
25
25
|
self.category = @uri.first
|
26
|
+
|
26
27
|
if @uri.length == 3
|
28
|
+
|
27
29
|
self.repo = @uri.first if valid?(@uri.first)
|
28
30
|
self.category = @uri[1]
|
29
31
|
self.folder = @uri.last
|
32
|
+
|
30
33
|
elsif @uri.length == 2
|
34
|
+
|
31
35
|
self.category = @uri.last
|
32
36
|
self.repo = @uri.first if valid?(@uri.first)
|
33
37
|
self.folder = get_folder(self.repo)
|
38
|
+
|
34
39
|
elsif @uri.length < 2
|
40
|
+
|
35
41
|
raise(ArgumentError, "too few arguments.")
|
42
|
+
|
36
43
|
else
|
44
|
+
|
37
45
|
raise(ArgumentError, "too many arguments.")
|
46
|
+
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
41
50
|
def get_folder(repo)
|
51
|
+
|
42
52
|
if repo =~ /\.git/i
|
43
53
|
repo_name = repo.match(/\S+[\/|\:](\S+)\.git/i)[1]
|
44
54
|
else
|
45
55
|
repo_name = repo.match(/\S+[\/|\:](\S+)\Z/i)[1]
|
46
56
|
end
|
57
|
+
|
47
58
|
repo_name
|
48
59
|
end
|
49
60
|
|
data/lib/gill/remove.rb
CHANGED
@@ -1,13 +1,36 @@
|
|
1
1
|
module Gill
|
2
2
|
|
3
|
-
class Remove
|
3
|
+
class Remove
|
4
|
+
include Config::Cache
|
5
|
+
include Gill::Helper
|
4
6
|
|
5
7
|
def initialize(args)
|
6
8
|
data = args.split('#')
|
7
9
|
raise(ArgumentError, 'Wrong number of arguments.') if data.length != 2
|
10
|
+
@source = Gill.config.source_path
|
8
11
|
@category = data.first
|
9
12
|
@folder = data.last
|
10
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove_cache
|
16
|
+
updated_cache = Gill.config.cache
|
17
|
+
|
18
|
+
if updated_cache[:"#{@category}"]
|
19
|
+
updated_cache[:"#{@category}"].delete(:"#{@folder}")
|
20
|
+
|
21
|
+
if updated_cache[:"#{@category}"].empty?
|
22
|
+
updated_cache.delete(:"#{@category}")
|
23
|
+
rebuild_cache(updated_cache, Gill.config.cache_path)
|
24
|
+
return true
|
25
|
+
|
26
|
+
else
|
27
|
+
|
28
|
+
rebuild_cache(updated_cache, Gill.config.cache_path)
|
29
|
+
return false
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
11
34
|
end
|
12
35
|
|
13
36
|
def remove_repo
|
@@ -15,9 +38,9 @@ module Gill
|
|
15
38
|
type_folder = "#{@source}/#{@category}"
|
16
39
|
folder = "#{@source}/#{@category}/#{@folder}"
|
17
40
|
|
18
|
-
if File.directory?(type_folder) && File.directory?(folder) &&
|
19
|
-
|
20
|
-
if
|
41
|
+
if File.directory?(type_folder) && File.directory?(folder) && !Gill.config.cache.empty?
|
42
|
+
|
43
|
+
if Gill.config.cache[:"#{@category}"][:"#{@folder}"]
|
21
44
|
|
22
45
|
ask "Are you sure you want to remove #{@folder}?", :default => :no do
|
23
46
|
STDOUT.puts "#{@folder.capitalize} removed successfully."
|
@@ -25,20 +48,18 @@ module Gill
|
|
25
48
|
end
|
26
49
|
|
27
50
|
unless Dir.enum_for(:foreach, type_folder).any? {|n| /\A\.\.?\z/ !~ n}
|
28
|
-
|
29
51
|
ask "The `#{@category}` directory is empty. Would you like to remove it?", :default => :no do
|
30
52
|
STDOUT.puts "#{@category.capitalize} directory removed successfully."
|
31
53
|
FileUtils.rm_rf(type_folder)
|
32
54
|
end
|
33
|
-
|
34
55
|
end
|
35
56
|
|
36
57
|
end
|
37
|
-
|
38
|
-
else
|
39
58
|
|
40
|
-
|
59
|
+
remove_cache
|
41
60
|
|
61
|
+
else
|
62
|
+
raise(DirectoryError, "The directory #{@source}/#{@category}/#{@folder} does not exist or was not cloned with gill.")
|
42
63
|
end
|
43
64
|
end
|
44
65
|
|
data/lib/gill/version.rb
CHANGED
data/lib/gill.rb
CHANGED
@@ -1,174 +1 @@
|
|
1
|
-
require 'gill/
|
2
|
-
require 'gill/config'
|
3
|
-
require 'gill/git'
|
4
|
-
require 'gill/remove'
|
5
|
-
require 'gill/parse'
|
6
|
-
require 'gill/version'
|
7
|
-
|
8
|
-
require 'gill/exceptions/error'
|
9
|
-
require 'gill/exceptions/argument_error'
|
10
|
-
require 'gill/exceptions/repository_error'
|
11
|
-
require 'gill/exceptions/directory_error'
|
12
|
-
|
13
|
-
require 'fileutils'
|
14
|
-
require 'yaml'
|
15
|
-
require 'optparse'
|
16
|
-
|
17
|
-
|
18
|
-
module Gill
|
19
|
-
|
20
|
-
#
|
21
|
-
# Load Gill Configuration
|
22
|
-
#
|
23
|
-
GILL_CONFIG = App.config
|
24
|
-
|
25
|
-
#
|
26
|
-
# Run Gill
|
27
|
-
#
|
28
|
-
def Gill.run
|
29
|
-
Gill.check_cache
|
30
|
-
Gill.optparse(*ARGV)
|
31
|
-
begin
|
32
|
-
|
33
|
-
uri = Parse.new(@options[:uri])
|
34
|
-
git = Git.new(uri.category, uri.folder, uri.repo)
|
35
|
-
git.clone
|
36
|
-
|
37
|
-
rescue TypeError => e
|
38
|
-
STDERR.puts "Error: #{e}\nError: Please make sure to remove all whitespace from the category and/or folder name."
|
39
|
-
exit -1
|
40
|
-
rescue => e
|
41
|
-
STDERR.puts "Error: #{e}"
|
42
|
-
exit -1
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def Gill.update
|
47
|
-
begin
|
48
|
-
args = @options[:update].split(/\#/)
|
49
|
-
raise(ArgumentError, "Requires three arguments. category#title#branch") if args.length > 4
|
50
|
-
category, folder, branch = args
|
51
|
-
git = Git.new(category, folder, false)
|
52
|
-
if branch
|
53
|
-
git.update(branch)
|
54
|
-
else
|
55
|
-
git.update
|
56
|
-
end
|
57
|
-
exit -1
|
58
|
-
rescue TypeError => e
|
59
|
-
STDERR.puts "Error: #{e}\nError: Please make sure to remove all whitespace from the category and/or folder name."
|
60
|
-
exit -1
|
61
|
-
rescue => e
|
62
|
-
STDERR.puts "Error: #{e}"
|
63
|
-
exit -1
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def Gill.check_cache
|
70
|
-
cache = GILL_CONFIG[:cache]
|
71
|
-
@new_cache = YAML.load_file(GILL_CONFIG[:cache])
|
72
|
-
source_dir = GILL_CONFIG[:source]
|
73
|
-
@new_cache.each do |key,value|
|
74
|
-
if File.directory?("#{source_dir}/#{key}")
|
75
|
-
value.each do |skey,svalue|
|
76
|
-
unless File.directory?("#{source_dir}/#{key}/#{skey}")
|
77
|
-
@new_cache[:"#{key}"].delete(:"#{skey}")
|
78
|
-
end
|
79
|
-
end
|
80
|
-
else
|
81
|
-
@new_cache.delete(:"#{key}")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
Config.rebuild_cache(cache, @new_cache)
|
85
|
-
end
|
86
|
-
|
87
|
-
def Gill.error
|
88
|
-
STDERR.puts "#{@opts}\n"
|
89
|
-
exit -1
|
90
|
-
end
|
91
|
-
|
92
|
-
def Gill.list
|
93
|
-
cache = YAML.load_file(GILL_CONFIG[:cache])
|
94
|
-
STDOUT.puts "\n*** Listing Cloned Repositories ***\n\n"
|
95
|
-
cache.each do |type,repos|
|
96
|
-
STDOUT.puts " #{type}:"
|
97
|
-
repos.each do |repo|
|
98
|
-
STDOUT.puts " - #{repo[0]} => " + "#{repo[1]}"
|
99
|
-
end
|
100
|
-
STDOUT.puts "\n"
|
101
|
-
end
|
102
|
-
exit -1
|
103
|
-
end
|
104
|
-
|
105
|
-
def Gill.remove
|
106
|
-
begin
|
107
|
-
Remove.new(@options[:remove]).remove_repo
|
108
|
-
rescue Gill::DirectoryError => e
|
109
|
-
STDERR.puts "Error: #{e}"
|
110
|
-
exit -1
|
111
|
-
rescue => e
|
112
|
-
STDERR.puts "Error: #{e}"
|
113
|
-
exit -1
|
114
|
-
end
|
115
|
-
exit -1
|
116
|
-
end
|
117
|
-
|
118
|
-
def Gill.optparse(*args)
|
119
|
-
@opts = OptionParser.new
|
120
|
-
|
121
|
-
@options = {}
|
122
|
-
|
123
|
-
@opts.banner = "Gill - Git, Clone, Cleanliness.\nUsage: gill git://host/repository.git#category/sub-category/...\n\n"
|
124
|
-
|
125
|
-
@opts.on('-l','--list','List repositories.') do |list|
|
126
|
-
@options[:list] = list
|
127
|
-
end
|
128
|
-
|
129
|
-
@opts.on('-r ', '--remove ','Remove repository. ie. -r category#folder') do |remove|
|
130
|
-
@options[:remove] = remove
|
131
|
-
end
|
132
|
-
|
133
|
-
@opts.on('-u ', '--update ','Update repository. ie. -u category#folder#branch') do |update|
|
134
|
-
@options[:update] = update
|
135
|
-
end
|
136
|
-
|
137
|
-
@opts.on('-x','--reload','Force gill cache reload.') do |remove|
|
138
|
-
STDOUT.print "Updating Gill Cache... "
|
139
|
-
Gill.check_cache
|
140
|
-
STDOUT.puts "Done."
|
141
|
-
exit -1
|
142
|
-
end
|
143
|
-
|
144
|
-
@opts.on('-h','--help','This help summary page.') do |help|
|
145
|
-
@options[:help] = help
|
146
|
-
end
|
147
|
-
|
148
|
-
@opts.on('-v','--version','Version number') do |version|
|
149
|
-
puts "Version: #{Gill::VERSION}"
|
150
|
-
exit -1
|
151
|
-
end
|
152
|
-
|
153
|
-
begin
|
154
|
-
@args = @opts.parse!(args)
|
155
|
-
@options[:uri] = @args[0]
|
156
|
-
Gill.error if @options[:help]
|
157
|
-
Gill.list if @options[:list]
|
158
|
-
Gill.remove if @options[:remove]
|
159
|
-
Gill.update if @options[:update]
|
160
|
-
Gill.error if @options.empty? or @options[:uri].nil?
|
161
|
-
rescue OptionParser::MissingArgument => e
|
162
|
-
STDERR.puts e.message
|
163
|
-
STDERR.puts @opts
|
164
|
-
STDERR.puts "\n"
|
165
|
-
exit -1
|
166
|
-
rescue OptionParser::InvalidOption => e
|
167
|
-
STDERR.puts e.message
|
168
|
-
STDERR.puts @opts
|
169
|
-
STDERR.puts "\n"
|
170
|
-
exit -1
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
end
|
1
|
+
require 'gill/gill'
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.8
|
9
|
+
version: 0.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-07-
|
17
|
+
date: 2010-07-10 00:00:00 -04:00
|
18
18
|
default_executable: gill
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -38,13 +38,17 @@ files:
|
|
38
38
|
- bin/gill
|
39
39
|
- gill.gemspec
|
40
40
|
- lib/gill.rb
|
41
|
-
- lib/gill/app.rb
|
42
41
|
- lib/gill/config.rb
|
42
|
+
- lib/gill/config/cache.rb
|
43
|
+
- lib/gill/config/setup.rb
|
44
|
+
- lib/gill/exceptions.rb
|
43
45
|
- lib/gill/exceptions/argument_error.rb
|
44
46
|
- lib/gill/exceptions/directory_error.rb
|
45
47
|
- lib/gill/exceptions/error.rb
|
46
48
|
- lib/gill/exceptions/repository_error.rb
|
49
|
+
- lib/gill/gill.rb
|
47
50
|
- lib/gill/git.rb
|
51
|
+
- lib/gill/helper.rb
|
48
52
|
- lib/gill/parse.rb
|
49
53
|
- lib/gill/remove.rb
|
50
54
|
- lib/gill/version.rb
|
data/lib/gill/app.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module Gill
|
2
|
-
|
3
|
-
class App
|
4
|
-
attr_accessor :gill, :cache, :source, :cache_file
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@gill = Gill::Config.new.yaml
|
8
|
-
@cache = @gill[:cache]
|
9
|
-
@source = @gill[:source]
|
10
|
-
@cache_file = cache
|
11
|
-
end
|
12
|
-
|
13
|
-
#
|
14
|
-
# Return the gill YAML configuration file.
|
15
|
-
#
|
16
|
-
def cache
|
17
|
-
YAML.load_file(@cache)
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
# Return the path for the passed type.
|
22
|
-
#
|
23
|
-
def path(type)
|
24
|
-
return @gill[:'#{type}'] if %w(source cache).include?(type.to_sym)
|
25
|
-
end
|
26
|
-
|
27
|
-
def ask(msg, options={})
|
28
|
-
default = options[:default] || :yes
|
29
|
-
if default == :yes
|
30
|
-
STDOUT.print "#{msg} [Y/n] "
|
31
|
-
else
|
32
|
-
STDOUT.print "#{msg} [y/N] "
|
33
|
-
end
|
34
|
-
input = STDIN.gets.chomp
|
35
|
-
STDOUT.flush
|
36
|
-
|
37
|
-
if block_given?
|
38
|
-
if input[/([Yy]|[Yy]es)$/i]
|
39
|
-
yield
|
40
|
-
elsif input[/([Nn]|[Nn]o)$/i]
|
41
|
-
exit -1
|
42
|
-
else
|
43
|
-
yield if default == :yes
|
44
|
-
end
|
45
|
-
else
|
46
|
-
exit -1
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
#
|
51
|
-
# Return the gill configuration file.
|
52
|
-
#
|
53
|
-
def self.config
|
54
|
-
@gill || Gill::Config.new.yaml
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|