rugs 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Mike Bethany
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown CHANGED
@@ -8,7 +8,11 @@ RUGS has three main functions:
8
8
  * Sets up a remote repository to mirror your local one.
9
9
  * Adds a framework of git hooks allowing you to store and run your own hooks in directly from the repo.
10
10
 
11
- RUGS makes creating remote repos as simple as `rugs create repo_name on server_name`.
11
+ RUGS makes creating remote repos as simple as `rugs create repo_name on server_name`. A local and remote repo will be created and your default remotes will automatically to the local repo.
12
+
13
+ [This is to-do functionality so the "instructions" are just brainstorming]
14
+ If you want to create just a local repo but add a remote as origin you would do this:
15
+ `rugs create repo_name on server_name using remote as origin`
12
16
 
13
17
  RUGS even allows you to automatically embed your Git hooks in the repo itself. No more jumping through hoops to make sure your hooks are maintained with your project; with RUGS you just store your hook scripts in the `git_hooks` directory and they're automatically updated and run.
14
18
 
@@ -19,28 +23,35 @@ Once you've set up your project using RUGS you just use Git as you normally woul
19
23
  **Alpha**
20
24
  Basic functionality done:
21
25
 
22
- * Stores config info for remotes
23
- * Sets up local repos
24
- * Sets up remote repos
25
- * Automatically adds default remotes to repos
26
+ * Stores config info for remotes.
27
+ * Sets up local repos.
28
+ * Sets up remote repos.
29
+ * Automatically adds default remotes to repos.
26
30
 
27
- ## To do
31
+ ## To-do
28
32
 
29
- Lots...
33
+ Lots:
30
34
 
31
- * Add setup templates
35
+ * Add setup templates.
32
36
  * Add hook framework to store and run hooks from the repo itself.
37
+ * Deal with existing repos.
38
+ * Figure out how to set remotes in a repo as some name other than the remote's name.
39
+
40
+ Non-functionality stuff:
33
41
 
42
+ * Refactor (of course).
43
+ * Clean up test, they're really ugly.
34
44
 
35
45
  ## Instructions
36
46
 
37
47
  * Install the gem.
38
48
  * Add a remote repo.
39
- * Create a new project
49
+ * Create a new project.
40
50
 
41
51
  It might look something like this:
42
52
 
43
53
  gem install rugs
44
54
 
45
55
  rugs remote_add origin git@git-server:/srv/repos/git
46
- rugs create new_project on origin
56
+ rugs create new_project on origin
57
+
data/bin/rugs ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
3
+ require 'commandable'
4
+ Commandable.verbose_parameters = false
5
+ Commandable.color_output = true
6
+ Commandable.app_exe = "rugs"
7
+ Commandable.app_info =
8
+ """
9
+ RUGS - RUby Git Setup
10
+ A helper script that makes setting up remote git repositories a snap.
11
+ Copyright (c) 2012 Mike Bethany
12
+ http://mikbe.tk
13
+ """
14
+
15
+ require 'rugs'
16
+ Commandable.execute(ARGV)
data/lib/rugs/client.rb CHANGED
@@ -1,30 +1,48 @@
1
+ require 'commandable'
2
+
1
3
  module RUGS
2
4
 
3
5
  class Client
4
-
5
- def remote_list
6
- @remote_list ||= Config.load("remotes")
6
+ extend Commandable
7
+
8
+ command 'stored remotes'
9
+ def remotes
10
+ remote_list.collect do |remote, keys|
11
+ url = keys[:url]
12
+ path = keys[:path]
13
+ default = keys[:default]
14
+ "#{remote}: #{url}#{":#{path}" if path}; default? #{default}"
15
+ end.insert(0, "All remotes:")
7
16
  end
8
-
9
- def default_remotes
10
- @default_remotes ||= remote_list.select do |remote, keys|
11
- keys[:default]
12
- end
17
+
18
+ command 'remotes that will automatically be added to repos'
19
+ def defaults
20
+ default_remotes.collect do |remote, keys|
21
+ url = keys[:url]
22
+ path = keys[:path]
23
+ default = keys[:default]
24
+ "#{remote}: #{url}#{":#{path}" if path}; default? #{default}"
25
+ end.insert(0, "Default remotes:")
13
26
  end
14
27
 
28
+ command 'make and set up a remote'
15
29
  def create(repo_name, *remote)
16
-
30
+ just_name = repo_name.split("/").last
31
+
17
32
  make_local_repo(repo_name)
18
33
  add_defaults(repo_name)
19
34
  make_hooks(repo_name)
20
35
 
36
+ FileUtils.cd repo_name
37
+
21
38
  unless remote.empty?
22
- just_name = repo_name.split("/").last
23
39
  make_remote_repo(just_name, remote.last)
40
+
24
41
  end
25
-
42
+ "Created #{just_name} locally#{" and on remote #{remote.last}" unless remote.empty?}"
26
43
  end
27
44
 
45
+ command 'add a remote server to be used when setting up repos'
28
46
  def remote_add(remote, url_path, default=false)
29
47
  url, path = url_path.split(":")
30
48
 
@@ -32,19 +50,44 @@ module RUGS
32
50
 
33
51
  remote_list.merge!(remote => {url: url, path: path, default: default})
34
52
  Config.save("remotes", remote_list)
53
+
54
+ puts "Added remote #{remote}."
55
+ remotes
35
56
  end
36
57
 
58
+ command 'remove a remote server from the list of remotes'
37
59
  def remote_remove(remote)
38
60
  remote_list.delete(remote)
39
61
  Config.save("remotes", remote_list)
62
+
63
+ puts "Removed remote #{remote}."
64
+ remotes
40
65
  end
41
66
 
42
- def default(remote, is_default=true)
67
+ command 'make an existing remote a default remote'
68
+ def set_default(remote, is_default=true)
43
69
  remote_list[remote][:default] = is_default
70
+ if is_default
71
+ "Set #{remote} as a default"
72
+ else
73
+ "Removed #{remote} from defaults"
74
+ end
75
+ remotes
76
+ end
77
+
78
+ command 'remove a remote from the default list'
79
+ def unset_default(remote)
80
+ set_default remote, false
81
+ end
82
+
83
+ def default_remotes
84
+ @default_remotes ||= remote_list.select do |remote, keys|
85
+ keys[:default]
86
+ end
44
87
  end
45
88
 
46
- def undefault(remote)
47
- default remote, false
89
+ def remote_list
90
+ @remote_list ||= Config.load("remotes")
48
91
  end
49
92
 
50
93
  private
@@ -64,7 +107,15 @@ module RUGS
64
107
 
65
108
  def add_defaults(repo_name)
66
109
  default_remotes.each do |remote, keys|
67
- Git.remote_add(repo_name, remote, keys[:url])
110
+ url = keys[:url]
111
+ path = keys[:path]
112
+ just_name = repo_name.split("/").last
113
+
114
+ Git.remote_add(
115
+ repo_name,
116
+ remote,
117
+ "#{url}:#{"#{path}/" if path}#{just_name}.git"
118
+ )
68
119
  end
69
120
  end
70
121
 
data/lib/rugs/config.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'psych'
2
+ require 'fileutils'
2
3
 
3
4
  module RUGS
4
5
 
5
6
  class Config
6
7
 
7
-
8
8
  def self.load(name)
9
9
  return {} unless File.exist?(config_file(name))
10
10
  Psych.load(File.open(config_file(name)))
@@ -28,9 +28,11 @@ module RUGS
28
28
 
29
29
  public
30
30
 
31
- PATH = build_path(File.dirname(__FILE__), "../../config")
31
+ PATH = build_path("~/.rugs", "config")
32
32
  #File.expand_path(File.join(File.dirname(__FILE__), "/../config"))
33
33
 
34
+ FileUtils.mkdir_p PATH
35
+
34
36
  end
35
37
 
36
38
  end
data/lib/rugs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RUGS
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/rugs.gemspec CHANGED
@@ -11,13 +11,18 @@ Gem::Specification.new do |s|
11
11
  s.summary = %q{A helper script that makes setting up remote git repositories a snap.}
12
12
  s.description =
13
13
  """
14
- == RUGS - RUby Git Setup
14
+ = RUGS - RUby Git Setup
15
15
 
16
16
  A helper script that makes setting up remote git repositories a snap.
17
17
 
18
+ == WARNING: This is still alpha so use it at your own risk!
19
+ Note: I don't use alpha/beta in the version numbers until I have a first real release because of how Ruby Gems handles them.
20
+
21
+ == What is it?
22
+
18
23
  RUGS has three main functions:
19
24
 
20
- * Creates a local git repository using default templates or ones you create.
25
+ * Creates a local git repository and directory structure using default templates or ones you create.
21
26
  * Sets up a remote repository to mirror your local one.
22
27
  * Adds a framework of git hooks allowing you to store and run your own hooks in directly from the repo.
23
28
 
@@ -26,16 +31,17 @@ RUGS makes creating remote repos as simple as `rugs create repo_name on server_n
26
31
  RUGS even allows you to automatically embed your Git hooks in the repo itself. No more jumping through hoops to make sure your hooks are maintained with your project; with RUGS you just store your hook scripts in the `git_hooks` directory and they're automatically updated and run.
27
32
 
28
33
  Once you've set up your project using RUGS you just use Git as you normally would with the exception of your hooks being the in `git_hooks` directory.
29
-
34
+
30
35
  """
31
36
 
32
37
  s.files = `git ls-files`.split("\n")
33
38
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
34
39
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
35
- s.require_paths = ["lib"]
40
+ s.require_paths = ["lib","config"]
36
41
 
37
42
  s.add_development_dependency "rspec"
38
43
 
39
- # s.add_runtime_dependency "rest-client"
40
-
44
+ s.add_runtime_dependency "commandable"
45
+ s.add_runtime_dependency "term-ansicolor-hi"
46
+
41
47
  end
@@ -2,23 +2,23 @@ require 'spec_helper'
2
2
  require 'psych'
3
3
 
4
4
  describe RUGS::Client do
5
-
5
+
6
6
  let(:client) {RUGS::Client.new}
7
7
 
8
8
  let(:remote){'test'}
9
9
  let(:url){'root@git-test'}
10
10
  let(:path){'/srv/repos/git'}
11
-
11
+
12
12
  let(:repo_name){random_name}
13
13
  let(:local_repo){"#{TEMP_DIR}/#{repo_name}"}
14
-
14
+
15
15
  let(:test_hash){
16
16
  {"test"=>{:url=>url, path: nil, :default=>true}}
17
17
  }
18
18
  let(:another_hash){
19
19
  {"another"=>{:url=>"git@another_server.org", path: nil, :default=>true}}
20
20
  }
21
-
21
+
22
22
  context 'when managing remote server settings' do
23
23
 
24
24
  context "and adding or removing servers" do
@@ -61,13 +61,13 @@ describe RUGS::Client do
61
61
 
62
62
  it "should set an exisiting remote as a default" do
63
63
  client.remote_add(remote, url)
64
- client.default(remote)
64
+ client.set_default(remote)
65
65
  client.default_remotes.should include(remote)
66
66
  end
67
67
 
68
68
  it "should un-default a remote" do
69
69
  client.remote_add(remote, url, "default")
70
- client.undefault(remote)
70
+ client.unset_default(remote)
71
71
  client.default_remotes.should_not include(remote)
72
72
  end
73
73
 
@@ -88,7 +88,7 @@ describe RUGS::Client do
88
88
  end
89
89
 
90
90
  end
91
-
91
+
92
92
  context 'when creating local repos' do
93
93
 
94
94
  it 'should create a local git repo' do
@@ -114,6 +114,22 @@ describe RUGS::Client do
114
114
  remotes.should be_empty
115
115
  end
116
116
 
117
+ it "should build the remote path" do
118
+ client.remote_add(remote, url, "default")
119
+ client.create local_repo
120
+
121
+ remotes = `git --git-dir="#{local_repo}/.git" --work-tree="#{local_repo}" remote -v`
122
+ remotes.should include("#{url}:#{repo_name}.git")
123
+ end
124
+
125
+ it "should build the remote path with a path" do
126
+ client.remote_add(remote, "#{url}:#{path}", "default")
127
+ client.create local_repo
128
+
129
+ remotes = `git --git-dir="#{local_repo}/.git" --work-tree="#{local_repo}" remote -v`
130
+ remotes.should include("#{url}:#{path}/#{repo_name}.git")
131
+ end
132
+
117
133
  end
118
134
 
119
135
  # It's probably best to set up a git server on a virtual machine for these tests.
@@ -151,7 +167,7 @@ describe RUGS::Client do
151
167
  # end
152
168
 
153
169
  end
154
-
170
+
155
171
  after(:each) do
156
172
  clean_config
157
173
  clean_temp
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rugs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2152208160 !ruby/object:Gem::Requirement
16
+ requirement: &2151814960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,32 +21,59 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152208160
25
- description: ! "\n== RUGS - RUby Git Setup\n\nA helper script that makes setting up
26
- remote git repositories a snap. \n\nRUGS has three main functions: \n\n* Creates
27
- a local git repository using default templates or ones you create.\n* Sets up a
28
- remote repository to mirror your local one.\n* Adds a framework of git hooks allowing
29
- you to store and run your own hooks in directly from the repo.\n\nRUGS makes creating
30
- remote repos as simple as `rugs create repo_name on server_name`.\n\nRUGS even allows
31
- you to automatically embed your Git hooks in the repo itself. No more jumping through
32
- hoops to make sure your hooks are maintained with your project; with RUGS you just
33
- store your hook scripts in the `git_hooks` directory and they're automatically updated
34
- and run. \n\nOnce you've set up your project using RUGS you just use Git as you
35
- normally would with the exception of your hooks being the in `git_hooks` directory.
36
- \ \n \n"
24
+ version_requirements: *2151814960
25
+ - !ruby/object:Gem::Dependency
26
+ name: commandable
27
+ requirement: &2151813620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2151813620
36
+ - !ruby/object:Gem::Dependency
37
+ name: term-ansicolor-hi
38
+ requirement: &2151813040 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2151813040
47
+ description: ! "\n= RUGS - RUby Git Setup\n\nA helper script that makes setting up
48
+ remote git repositories a snap. \n\n== WARNING: This is still alpha so use it at
49
+ your own risk!\nNote: I don't use alpha/beta in the version numbers until I have
50
+ a first real release because of how Ruby Gems handles them.\n\n== What is it?\n\nRUGS
51
+ has three main functions: \n\n* Creates a local git repository and directory structure
52
+ using default templates or ones you create.\n* Sets up a remote repository to mirror
53
+ your local one.\n* Adds a framework of git hooks allowing you to store and run your
54
+ own hooks in directly from the repo.\n\nRUGS makes creating remote repos as simple
55
+ as `rugs create repo_name on server_name`.\n\nRUGS even allows you to automatically
56
+ embed your Git hooks in the repo itself. No more jumping through hoops to make sure
57
+ your hooks are maintained with your project; with RUGS you just store your hook
58
+ scripts in the `git_hooks` directory and they're automatically updated and run.
59
+ \ \n\nOnce you've set up your project using RUGS you just use Git as you normally
60
+ would with the exception of your hooks being the in `git_hooks` directory. \n\n"
37
61
  email:
38
62
  - mikbe.tk@gmail.com
39
- executables: []
63
+ executables:
64
+ - rugs
40
65
  extensions: []
41
66
  extra_rdoc_files: []
42
67
  files:
43
68
  - .gitignore
44
69
  - Gemfile
70
+ - LICENCE
45
71
  - README.markdown
46
72
  - Rakefile
47
73
  - _spike/psych.rb
48
74
  - _spike/test.yaml
49
75
  - autotest/discover.rb
76
+ - bin/rugs
50
77
  - lib/rugs.rb
51
78
  - lib/rugs/client.rb
52
79
  - lib/rugs/config.rb
@@ -64,6 +91,7 @@ post_install_message:
64
91
  rdoc_options: []
65
92
  require_paths:
66
93
  - lib
94
+ - config
67
95
  required_ruby_version: !ruby/object:Gem::Requirement
68
96
  none: false
69
97
  requirements: