gill 1.0.0.rc.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # GILL DEPS
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  group(:development) do
@@ -10,4 +12,4 @@ group(:doc) do
10
12
  gem 'yard', '~> 0.5.3'
11
13
  end
12
14
 
13
- gem 'rspec', '~> 1.3.0', :group => [:development]
15
+ gem 'rspec', '>= 1.3.0', :group => [:development]
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ bluecloth (2.0.7)
5
+ gemcutter (0.6.1)
6
+ git (1.2.5)
7
+ jeweler (1.4.0)
8
+ gemcutter (>= 0.1.0)
9
+ git (>= 1.2.5)
10
+ rubyforge (>= 2.0.0)
11
+ json_pure (1.4.5)
12
+ rake (0.8.7)
13
+ rspec (1.3.0)
14
+ rubyforge (2.0.4)
15
+ json_pure (>= 1.1.7)
16
+ yard (0.5.8)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bluecloth (~> 2.0.7)
23
+ jeweler (~> 1.4.0)
24
+ rake (~> 0.8.7)
25
+ rspec (>= 1.3.0)
26
+ yard (~> 0.5.3)
File without changes
data/README.rdoc CHANGED
@@ -1,7 +1,5 @@
1
1
  = gill
2
2
 
3
- *NOTICE: THIS IS BETA SOFTWARE!
4
-
5
3
  Gill is a simple Ruby app to help keep your git clones clean and organized. Gill creates a source directory (~/source) in the users home path were all cloned repos will be stored. The gill default source location can be changed at any time by simply editing the ".gillrc" in the users home directory.
6
4
 
7
5
  Files created by gill:
@@ -26,11 +24,13 @@ Gill Usage:
26
24
  Gill - Git, Clone, Cleanliness.
27
25
  Usage: gill git://host/repository.git#category/sub-category/...
28
26
 
29
- -l, --list List all cloned repositories.
30
- -r, --remove Remove a cloned repository. ie. -r category#folder
31
- -u, --update Update repository. ie. -u category#folder#branch
32
- -h, --help This help summary page.
33
- -v, --version Version number
27
+ -l, --list List all cloned repositories.
28
+ -r, --remove Remove a cloned repository. ie. -r category#folder
29
+ -u, --update Update repository. ie. -u category#folder#branch
30
+ -i, --import Import untracked repository.
31
+ -h, --help This help summary page.
32
+ -v, --version Version number
33
+
34
34
 
35
35
  Cloning a git repository with gill:
36
36
 
@@ -77,13 +77,13 @@ Listing cloned repositories:
77
77
  Removing cloned repositories:
78
78
 
79
79
  $ gill -r rails#snorby-dev
80
- Removing: rails => snorby-dev
80
+ Are you sure you want to remove the repository: snorby-dev? [y/N] y
81
81
  Repository Removed Successfully.
82
- Updating Cache...
83
82
 
84
83
  Updating cloned repositories:
85
84
 
86
- $ gill -u rails#snorby-dev
85
+ $ gill -u snorby-dev
86
+ Update ronin => /Users/mephux/source/rails/snorby-dev? [Y/n] y
87
87
  Updating snorby-dev repository.
88
88
  From https://github.com/mephux/Snorby
89
89
  * branch master -> FETCH_HEAD
data/bin/gill CHANGED
@@ -6,4 +6,4 @@ unless $LOAD_PATH.include?(lib_dir)
6
6
  end
7
7
 
8
8
  require 'gill'
9
- Gill.run
9
+ Gill.setup
data/lib/gill/cli.rb ADDED
@@ -0,0 +1,138 @@
1
+ require 'optparse'
2
+
3
+ require 'gill/helper'
4
+ require 'gill/config'
5
+ require 'gill/remove'
6
+ require 'gill/import'
7
+ require 'gill/parse'
8
+ require 'gill/git'
9
+ require 'gill/exceptions'
10
+
11
+ module Gill
12
+
13
+ module CLI
14
+ include Helper
15
+
16
+ def CLI.pull(args)
17
+ begin
18
+ uri = Parse.new(args)
19
+ git = Git.new(uri.category, uri.folder, uri.repo)
20
+ git.clone
21
+ rescue TypeError => e
22
+ STDERR.puts "Error: #{e}"
23
+ rescue => e
24
+ STDERR.puts "Error: #{e}"
25
+ end
26
+ end
27
+
28
+ #
29
+ # Import any preexisting repos intop the gill cache.
30
+ #
31
+ def CLI.import
32
+ begin
33
+ search = Import.new
34
+ search.import
35
+ search.update_cache
36
+ exit -1
37
+ rescue => e
38
+ STDERR.puts "Error: #{e}"
39
+ exit -1
40
+ end
41
+ end
42
+
43
+ # Update a gill repository.
44
+ def CLI.update(repo_name)
45
+ begin
46
+ git = Git.new(false, repo_name, false)
47
+ git.update
48
+ exit -1
49
+ rescue TypeError => e
50
+ STDERR.puts "Error: #{e}\n"
51
+ exit -1
52
+ rescue => e
53
+ STDERR.puts "Error: #{e}"
54
+ exit -1
55
+ end
56
+ end
57
+
58
+ # List all gill cloned repositories.
59
+ def CLI.list
60
+ Gill.config.list_entries
61
+ exit -1
62
+ end
63
+
64
+ # Remove a gill cloned repository.
65
+ def CLI.remove(args)
66
+ begin
67
+ # Raise exception if the params are not seperated by a `#`.
68
+ raise(SyntaxError, "Invalid Syntax. Arguments must be separated by `#`") unless args =~ /\#/
69
+ Remove.new(args).remove_repo
70
+
71
+ rescue => e
72
+ STDERR.puts "Error: #{e}"
73
+ exit -1
74
+ end
75
+ exit -1
76
+ end
77
+
78
+ # Gill option parser
79
+ # @param [Array] passed gill options.
80
+ def optparse(*args)
81
+
82
+ @opts = OptionParser.new
83
+
84
+ @options = {}
85
+
86
+ @opts.banner = "Gill - Git, Clone, Cleanliness.\nUsage: gill git://host/repository.git#category/sub-category/...\n\n"
87
+
88
+ @opts.on('-l','--list','List all cloned repositories.') do |list|
89
+ CLI.list
90
+ end
91
+
92
+ @opts.on('-r ','--remove ','Remove a cloned repository. ie. -r category#folder') do |remove|
93
+ CLI.remove(remove)
94
+ end
95
+
96
+ @opts.on('-u ', '--update ','Update repository. ie. -u category#folder#branch') do |update|
97
+ CLI.update(update)
98
+ end
99
+
100
+ @opts.on('-i','--import','Import untracked repository.') do |import|
101
+ CLI.import
102
+ end
103
+
104
+ @opts.on('-h','--help','This help summary page.') do |help|
105
+ usage
106
+ end
107
+
108
+ @opts.on('-v','--version','Version number') do |version|
109
+ STDOUT.puts "Version: #{Gill::VERSION}"
110
+ exit -1
111
+ end
112
+
113
+ begin
114
+
115
+ @args = @opts.parse!(args)
116
+ usage if @args.empty? || @args[0].nil?
117
+ CLI.pull(@args[0])
118
+ rescue OptionParser::MissingArgument => e
119
+ gillerror e.message
120
+ SDTOUT.puts @opts
121
+ SDTOUT.puts "\n"
122
+ exit -1
123
+ rescue OptionParser::InvalidOption => e
124
+ gillerror e.message
125
+ SDTOUT.puts @opts
126
+ SDTOUT.puts "\n"
127
+ exit -1
128
+ end
129
+ end
130
+
131
+ def usage
132
+ STDOUT.puts "#{@opts}\n"
133
+ exit -1
134
+ end
135
+
136
+ end
137
+
138
+ end
data/lib/gill/config.rb CHANGED
@@ -1,30 +1,173 @@
1
- require 'gill/config/setup'
2
- require 'gill/config/cache'
3
-
4
1
  module Gill
5
2
 
6
- class Config
7
-
8
- # Include the gill setup and cache convenience methods.
9
- include Setup, Cache
10
-
11
- attr_reader :home, :config_path, :cache_path, :config, :cache
12
-
13
- # Initialize the Gill configuration.
14
- # @return [Object] the gill configuration
15
- def initialize
16
-
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.
23
-
24
- self
25
-
3
+ FROZENKEYS = [:version, :categories].freeze
4
+
5
+ module Settings
6
+
7
+ class Config
8
+ include Helper
9
+
10
+ attr_reader :home, :config_path, :cache_path, :settings, :cache, :repos
11
+
12
+ def initialize(home_path=nil)
13
+ @home = home_path || File.expand_path('~')
14
+ @settings_path = File.join(@home, '.gillrc')
15
+ @cache_path = File.join(@home, '.gillcache')
16
+ file_check!
17
+ version_check!
18
+ check_default_folders!
19
+ self
20
+ end
21
+
22
+ def file_check!
23
+
24
+ if File.exists?(@settings_path)
25
+ load_gill_settings
26
+ else
27
+ setup_gill_settings
28
+ end
29
+
30
+ if File.exists?(@cache_path)
31
+ load_gill_cache
32
+ else
33
+ setup_gill_cache
34
+ end
35
+
36
+ end
37
+
38
+ def categories
39
+ @repos = @cache[:categories]
40
+ end
41
+
42
+ def source_path
43
+ @source_path = @settings[:source]
44
+ end
45
+
46
+ def cache_path
47
+ @source_path = @settings[:cache]
48
+ end
49
+
50
+ def settings_path
51
+ @settings_path = @settings[:settings]
52
+ end
53
+
54
+ def default_path
55
+ @default_path = @settings[:default]
56
+ end
57
+
58
+ def write_settings(settings)
59
+ File.open(@settings_path, 'w') do |out|
60
+ YAML.dump(settings, out)
61
+ end
62
+ end
63
+
64
+ def write_cache(cache)
65
+ File.open(@cache_path, 'w') do |out|
66
+ YAML.dump(cache, out)
67
+ end
68
+ end
69
+
70
+ def list_entries
71
+ STDERR.puts green("\n*** Listing Cloned Repositories ***\n")
72
+ categories.each do |category,repos|
73
+ STDERR.puts "\t#{category}:"
74
+ repos.each do |repo|
75
+ STDERR.puts "\t #{green(repo[0])} => " + "#{repo[1][:repo]}"
76
+ end
77
+ STDERR.puts "\n"
78
+ end
79
+ end
80
+
81
+ def clean_cache
82
+ @clean_cache = Gill.config.cache
83
+
84
+ @clean_cache[:categories].each do |key,value|
85
+
86
+ value.each do |k,v|
87
+ @clean_cache[:categories][key.to_sym].delete(k.to_sym) unless File.directory?(v[:path].to_s)
88
+ end
89
+
90
+ @clean_cache[:categories].delete(key.to_sym) if @clean_cache[:categories][key.to_sym].empty?
91
+
92
+ end
93
+
94
+ write_cache(@clean_cache)
95
+
96
+ end
97
+
98
+ def paths
99
+ @paths = []
100
+ Gill.config.categories.each do |key,value|
101
+ value.each do |k,v|
102
+ @paths << v[:path]
103
+ end
104
+ end
105
+ @paths
106
+ end
107
+
108
+ private
109
+
110
+ def version_check!
111
+ unless current_settings_version && current_cache_version
112
+ STDOUT.puts red("Your Gill configuration is outdated.")
113
+ STDOUT.puts red("The must upgrade the gill configuration files to #{Gill::VERSION} to continue.")
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
+
121
+ end
122
+ end
123
+
124
+ 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
+ FileUtils.rm_rf(@cache_path)
127
+ FileUtils.rm_rf(@settings_path)
128
+ end
129
+
130
+ def current_settings_version
131
+ return true if (@settings[:version] == Gill::VERSION)
132
+ false
133
+ end
134
+
135
+ def current_cache_version
136
+ return true if (@cache[:version] == Gill::VERSION)
137
+ false
138
+ end
139
+
140
+ def load_gill_settings
141
+ @settings = YAML.load_file(@settings_path)
142
+ end
143
+
144
+ def load_gill_cache
145
+ @cache = YAML.load_file(@cache_path)
146
+ end
147
+
148
+ def setup_gill_settings
149
+ settings = {
150
+ :version => Gill::VERSION,
151
+ :settings => @settings_path,
152
+ :source => "#{@home}/source",
153
+ :default => "#{@home}/source/misc",
154
+ :cache => @cache_path
155
+ }
156
+ write_settings(settings)
157
+ file_check!
158
+ end
159
+
160
+ def setup_gill_cache
161
+ cache = { :version => Gill::VERSION, :categories => {} }
162
+ write_cache(cache)
163
+ file_check!
164
+ end
165
+
166
+ def check_default_folders!
167
+ FileUtils.mkdir(source_path) unless File.exists?(source_path) && File.directory?(source_path)
168
+ FileUtils.mkdir(default_path) unless File.exists?(default_path) && File.directory?(default_path)
169
+ end
170
+
26
171
  end
27
-
28
172
  end
29
-
30
173
  end
data/lib/gill/gill.rb CHANGED
@@ -1,172 +1,29 @@
1
1
  require 'fileutils'
2
- require 'optparse'
2
+ require 'pathname'
3
3
  require 'yaml'
4
4
  require 'pp'
5
5
 
6
- require 'gill/config'
7
- require 'gill/helper'
8
- require 'gill/git'
9
- require 'gill/import'
10
- require 'gill/remove'
11
- require 'gill/parse'
12
- require 'gill/exceptions'
6
+ require 'gill/cli'
13
7
 
14
8
  module Gill
15
9
 
16
- # Module method for the gill configuration.
17
- # @return [Object] the gill configuration
18
- def Gill.config
19
- @config ||= Config.new
20
- end
21
-
22
- # Run Gill
23
- def Gill.run
24
- Gill.optparse(*ARGV)
25
- end
26
-
27
- def Gill.pull
28
- begin
29
- uri = Parse.new(@options[:uri])
30
- git = Git.new(uri.category, uri.folder, uri.repo)
31
- git.clone
32
- rescue TypeError => e
33
- STDERR.puts "Error: #{e}\nError: Please make sure to remove all whitespace from the category and/or folder name."
34
- rescue => e
35
- STDERR.puts "Error: #{e}"
36
- end
37
- end
38
-
39
- #
40
- # Import any preexisting repos intop the gill cache.
41
- #
42
- def Gill.import_to_gill
43
- begin
44
- search = Import.new
45
- search.import
46
- search.update_cache
47
- exit -1
48
- rescue => e
49
- STDERR.puts "Error: #{e}"
50
- exit -1
51
- end
10
+ class << self
11
+ include CLI
52
12
  end
53
13
 
54
- # Update a gill repository.
55
- def Gill.update
56
- begin
57
- raise(SyntaxError, "Invalid Syntax. Arguments must be separated by `#`. Example: gill -u category#title") unless @options[:update] =~ /\#/
58
- args = @options[:update].split(/\#/)
59
- raise(ArgumentError, "Requires argument. category#title") if args.length != 2
60
- category, folder, branch = args
61
- git = Git.new(category, folder, false)
62
- if branch
63
- git.update(branch)
64
- else
65
- git.update
66
- end
67
- exit -1
68
- rescue TypeError => e
69
- STDERR.puts "Error: #{e}\nError: Please make sure to remove all whitespace from the category and/or folder name."
70
- exit -1
71
- rescue => e
72
- STDERR.puts "Error: #{e}"
73
- exit -1
74
- end
14
+ def Gill.config=(config=nil)
15
+ @config = config
75
16
  end
76
17
 
77
- # List all gill cloned repositories.
78
- def Gill.list
79
- STDERR.puts "\n*** Listing Cloned Repositories ***\n\n"
80
- unless Gill.config.cache.nil?
81
- Gill.config.cache.each do |type,repos|
82
- STDERR.puts "\t#{type}:"
83
- repos.each do |repo|
84
- STDERR.puts "\t #{repo[0]} => " + "#{repo[1][:repo]}"
85
- end
86
- STDERR.puts "\n"
87
- end
88
- end
89
- exit -1
90
- end
91
-
92
- # Remove a gill cloned repository.
93
- def Gill.remove
94
- begin
95
- # Raise exception if the params are not seperated by a `#`.
96
- raise(SyntaxError, "Invalid Syntax. Arguments must be separated by `#`. Example: gill -r category#title") unless @options[:remove] =~ /\#/
97
- Remove.new(@options[:remove]).remove_repo
98
- rescue Gill::DirectoryError => e
99
- STDERR.puts "Error: #{e}"
100
- rescue => e
101
- STDERR.puts "Error: #{e}"
102
- end
103
- exit -1
104
- end
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
18
+ def Gill.config
19
+ return @config if defined?(@config)
20
+ Gill.config = Settings::Config.new
163
21
  end
164
22
 
165
- # Gill Error
166
- # @return [Object] gill usage
167
- def Gill.usage
168
- STDOUT.puts "#{@opts}\n"
169
- exit -1
23
+ def Gill.setup
24
+ Gill.config
25
+ Gill.config.clean_cache
26
+ optparse(*ARGV)
170
27
  end
171
28
 
172
29
  end