rugs 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  # RUGS - RUby Git Setup
2
2
 
3
- A helper script that makes setting up git repositories a snap.
3
+ A helper script that makes setting up remote git repositories a snap.
4
4
 
5
5
  RUGS has three main functions:
6
6
 
@@ -8,7 +8,7 @@ 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`. If you have a default server set you don't even have to specify the server you can just run `rugs create repo_name`.
11
+ RUGS makes creating remote repos as simple as `rugs create repo_name on server_name`.
12
12
 
13
13
  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
14
 
@@ -16,5 +16,31 @@ Once you've set up your project using RUGS you just use Git as you normally woul
16
16
 
17
17
  ## Status
18
18
 
19
- **In Development**
20
- Beginning development.
19
+ **Alpha**
20
+ Basic functionality done:
21
+
22
+ * Stores config info for remotes
23
+ * Sets up local repos
24
+ * Sets up remote repos
25
+ * Automatically adds default remotes to repos
26
+
27
+ ## To do
28
+
29
+ Lots...
30
+
31
+ * Add setup templates
32
+ * Add hook framework to store and run hooks from the repo itself.
33
+
34
+
35
+ ## Instructions
36
+
37
+ * Install the gem.
38
+ * Add a remote repo.
39
+ * Create a new project
40
+
41
+ It might look something like this:
42
+
43
+ gem install rugs
44
+
45
+ rugs remote_add origin git@git-server:/srv/repos/git
46
+ rugs create new_project on origin
data/_spike/psych.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ require 'psych'
3
+
4
+ x = {a: "The a", b: "the b"}
5
+ fn = "test.yaml"
6
+
7
+ File.open(fn, "w+") do |file|
8
+ file.write(x.to_yaml)
9
+ end
10
+
11
+ y = Psych.load(File.open(fn))
12
+
13
+ puts y
14
+
15
+ z = Psych.load(File.open("no_such_file.yaml"))
16
+
17
+ puts z
data/_spike/test.yaml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ :a: The a
3
+ :b: the b
data/lib/rugs.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "rugs/version"
2
+ require "rugs/config"
2
3
  require "rugs/git"
3
- require "rugs/client"
4
- require "rugs/server"
5
-
4
+ require "rugs/client"
data/lib/rugs/client.rb CHANGED
@@ -1,11 +1,74 @@
1
- require 'fileutils'
2
-
3
1
  module RUGS
4
-
2
+
5
3
  class Client
4
+
5
+ def remote_list
6
+ @remote_list ||= Config.load("remotes")
7
+ end
8
+
9
+ def default_remotes
10
+ @default_remotes ||= remote_list.select do |remote, keys|
11
+ keys[:default]
12
+ end
13
+ end
6
14
 
7
- def self.create(repo_name)
8
- Git.init(repo_name) unless Dir.exists?("#{repo_name}/.git")
15
+ def create(repo_name, *remote)
16
+
17
+ make_local_repo(repo_name)
18
+ add_defaults(repo_name)
19
+ make_hooks(repo_name)
20
+
21
+ unless remote.empty?
22
+ just_name = repo_name.split("/").last
23
+ make_remote_repo(just_name, remote.last)
24
+ end
25
+
26
+ end
27
+
28
+ def remote_add(remote, url_path, default=false)
29
+ url, path = url_path.split(":")
30
+
31
+ default = (remote == 'origin' || default == 'default')
32
+
33
+ remote_list.merge!(remote => {url: url, path: path, default: default})
34
+ Config.save("remotes", remote_list)
35
+ end
36
+
37
+ def remote_remove(remote)
38
+ remote_list.delete(remote)
39
+ Config.save("remotes", remote_list)
40
+ end
41
+
42
+ def default(remote, is_default=true)
43
+ remote_list[remote][:default] = is_default
44
+ end
45
+
46
+ def undefault(remote)
47
+ default remote, false
48
+ end
49
+
50
+ private
51
+
52
+ def make_local_repo(repo_name)
53
+ return if Dir.exists?("#{repo_name}/.git")
54
+ Git.init(repo_name)
55
+ end
56
+
57
+ def make_remote_repo(repo_name, remote)
58
+ url = remote_list[remote][:url]
59
+ path = remote_list[remote][:path]
60
+ default = remote_list[remote][:default]
61
+
62
+ `ssh #{url} 'git init #{"#{path}/" if path}#{repo_name}.git --bare'`
63
+ end
64
+
65
+ def add_defaults(repo_name)
66
+ default_remotes.each do |remote, keys|
67
+ Git.remote_add(repo_name, remote, keys[:url])
68
+ end
69
+ end
70
+
71
+ def make_hooks(repo_name)
9
72
  FileUtils.mkdir_p "#{repo_name}/git_hooks"
10
73
  end
11
74
 
@@ -0,0 +1,36 @@
1
+ require 'psych'
2
+
3
+ module RUGS
4
+
5
+ class Config
6
+
7
+
8
+ def self.load(name)
9
+ return {} unless File.exist?(config_file(name))
10
+ Psych.load(File.open(config_file(name)))
11
+ end
12
+
13
+ def self.save(name, hash)
14
+ File.open(config_file(name), "w") do |file|
15
+ file.write(hash.to_yaml)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def self.config_file(name)
22
+ build_path(PATH, "#{name}.yaml")
23
+ end
24
+
25
+ def self.build_path(root, append)
26
+ File.expand_path(File.join(root, "/#{append}"))
27
+ end
28
+
29
+ public
30
+
31
+ PATH = build_path(File.dirname(__FILE__), "../../config")
32
+ #File.expand_path(File.join(File.dirname(__FILE__), "/../config"))
33
+
34
+ end
35
+
36
+ end
data/lib/rugs/git.rb CHANGED
@@ -2,11 +2,24 @@ require 'open3'
2
2
 
3
3
  module RUGS
4
4
 
5
- # a very dumb wrapper for git
5
+ # a very simple wrapper for git, only wraps what I nee
6
6
  class Git
7
7
 
8
- def self.method_missing(meth, args)
9
- out, status = Open3.capture2e("git", meth.to_s, args)
8
+ def self.init(repo_name)
9
+ exec 'init', repo_name
10
+ end
11
+
12
+ def self.remote_add(repo_name, server, url)
13
+ pwd = FileUtils.pwd
14
+ FileUtils.cd repo_name
15
+ exec 'remote', 'add', server, url
16
+ FileUtils.cd pwd
17
+ end
18
+
19
+ private
20
+
21
+ def self.exec(cmd, *args)
22
+ out, status = Open3.capture2e("git", cmd, *args)
10
23
  raise Object::Exception(out) if status.exitstatus != 0
11
24
  out
12
25
  end
data/lib/rugs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RUGS
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/rugs.gemspec CHANGED
@@ -8,16 +8,32 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Mike Bethany"]
9
9
  s.email = ["mikbe.tk@gmail.com"]
10
10
  s.homepage = "http://mikbe.tk"
11
- s.summary = %q{Place holder gem}
12
- s.description = %q{Nothing to see here, move along.}
11
+ s.summary = %q{A helper script that makes setting up remote git repositories a snap.}
12
+ s.description =
13
+ """
14
+ == RUGS - RUby Git Setup
15
+
16
+ A helper script that makes setting up remote git repositories a snap.
17
+
18
+ RUGS has three main functions:
19
+
20
+ * Creates a local git repository using default templates or ones you create.
21
+ * Sets up a remote repository to mirror your local one.
22
+ * Adds a framework of git hooks allowing you to store and run your own hooks in directly from the repo.
23
+
24
+ RUGS makes creating remote repos as simple as `rugs create repo_name on server_name`.
25
+
26
+ 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
+
28
+ 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
+
30
+ """
13
31
 
14
32
  s.files = `git ls-files`.split("\n")
15
33
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
34
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
35
  s.require_paths = ["lib"]
18
36
 
19
- # specify any dependencies here; for example:
20
- # s.add_development_dependency "rspec"
21
37
  s.add_development_dependency "rspec"
22
38
 
23
39
  # s.add_runtime_dependency "rest-client"
@@ -1,26 +1,160 @@
1
1
  require 'spec_helper'
2
- require 'fileutils'
2
+ require 'psych'
3
3
 
4
4
  describe RUGS::Client do
5
5
 
6
- let(:client) {RUGS::Client}
6
+ let(:client) {RUGS::Client.new}
7
+
8
+ let(:remote){'test'}
9
+ let(:url){'root@git-test'}
10
+ let(:path){'/srv/repos/git'}
11
+
12
+ let(:repo_name){random_name}
13
+ let(:local_repo){"#{TEMP_DIR}/#{repo_name}"}
14
+
15
+ let(:test_hash){
16
+ {"test"=>{:url=>url, path: nil, :default=>true}}
17
+ }
18
+ let(:another_hash){
19
+ {"another"=>{:url=>"git@another_server.org", path: nil, :default=>true}}
20
+ }
7
21
 
8
- context 'When creating repos' do
22
+ context 'when managing remote server settings' do
23
+
24
+ context "and adding or removing servers" do
25
+
26
+ it "should remember remote servers" do
27
+ client.remote_add(remote, url)
28
+
29
+ client.remote_list.should include(remote)
30
+ end
31
+
32
+ it "should forget remote servers" do
33
+ client.remote_add(remote, url)
34
+
35
+ client.remote_remove(remote)
36
+ client.remote_list.should be_empty
37
+ end
38
+
39
+ end
40
+
41
+ context "and configuring defaults" do
42
+
43
+ it "should remember default remotes" do
44
+ client.remote_add(remote, url, "default")
45
+ client.default_remotes.should include(test_hash)
46
+ end
47
+
48
+ it "should set origin remots as defaults" do
49
+ client.remote_add('origin', url)
50
+ client.default_remotes.should include(
51
+ {"origin"=>{:url=>"root@git-test", :path=>nil, :default=>true}}
52
+ )
53
+ end
9
54
 
10
- let(:repo_name) {temp_name}
55
+ it "should remember multiple default remote" do
56
+ client.remote_add(remote, url, "default")
57
+ client.remote_add('another', 'git@another_server.org', "default")
58
+
59
+ client.default_remotes.should == {}.merge(test_hash).merge(another_hash)
60
+ end
11
61
 
12
- it 'should create a git repo' do
13
- client.create repo_name
14
- Dir.exists?(repo_name).should be_true
62
+ it "should set an exisiting remote as a default" do
63
+ client.remote_add(remote, url)
64
+ client.default(remote)
65
+ client.default_remotes.should include(remote)
66
+ end
67
+
68
+ it "should un-default a remote" do
69
+ client.remote_add(remote, url, "default")
70
+ client.undefault(remote)
71
+ client.default_remotes.should_not include(remote)
72
+ end
73
+
15
74
  end
75
+
76
+ context "and setting a path to the git repo" do
77
+
78
+ it "should save the remote path if one is given" do
79
+ client.remote_add(remote, "#{url}:#{path}")
80
+ client.remote_list[remote][:path].should == path
81
+ end
82
+
83
+ it "should not save a remote path if none is given" do
84
+ client.remote_add(remote, url)
85
+ client.remote_list[remote][:path].should be_nil
86
+ end
16
87
 
17
- it 'should create a git_hooks directory in the local repo' do
18
- client.create repo_name
19
- Dir.exists?("#{repo_name}/git_hooks").should be_true
20
88
  end
21
89
 
22
90
  end
23
91
 
24
- after(:all) {FileUtils.rm_rf TEMP}
92
+ context 'when creating local repos' do
93
+
94
+ it 'should create a local git repo' do
95
+ client.create local_repo
96
+ Dir.exists?(local_repo).should be_true
97
+ end
98
+
99
+ it 'should set the default remotes automatically' do
100
+ client.remote_add(remote, url, "default")
101
+ client.remote_add('some_remote', 'git@server.org', "default")
102
+ client.create local_repo
103
+
104
+ remotes = `git --git-dir="#{local_repo}/.git" --work-tree="#{local_repo}" remote`
105
+ remotes.should include("test", "some_remote")
106
+ end
107
+
108
+ it "should not set default remotes if there aren't any" do
109
+ client.remote_add(remote, url)
110
+ client.remote_add('some_remote', 'git@server.org')
111
+ client.create local_repo
112
+
113
+ remotes = `git --git-dir="#{local_repo}/.git" --work-tree="#{local_repo}" remote`
114
+ remotes.should be_empty
115
+ end
116
+
117
+ end
118
+
119
+ # It's probably best to set up a git server on a virtual machine for these tests.
120
+ # These tests are set up with the following system in place...
121
+ #
122
+ # You can download a free, ready to run Linux VM from here:
123
+ # http://www.turnkeylinux.org/revision-control
124
+ #
125
+ # And you can use the free VirtualBox software to run it:
126
+ # http://www.virtualbox.org/wiki/Downloads
127
+ #
128
+ # You'll also want to set ssh to login without a password, see:
129
+ # http://mikbe.tk/2010/09/08/login-to-ssh-without-a-password-easily/
130
+ #
131
+ context 'when creating remote repos' do
132
+
133
+ it 'should create a repo on the remote server' do
134
+ client.remote_add(remote, "#{url}:#{path}")
135
+ client.create local_repo, remote
136
+
137
+ out, status = Open3.capture2e("ssh",
138
+ "#{url}", "ls #{path}/#{repo_name}.git"
139
+ )
140
+ `ssh #{url} 'rm -rf #{path}/*.git'`
141
+ out.should_not include("No such file")
142
+ end
143
+
144
+ end
145
+
146
+ context "mit der hooks" do
147
+
148
+ # it 'should create a git_hooks directory in the local repo' do
149
+ # client.create repo_name
150
+ # Dir.exists?("#{repo_name}/git_hooks").should be_true
151
+ # end
152
+
153
+ end
25
154
 
155
+ after(:each) do
156
+ clean_config
157
+ clean_temp
158
+ end
159
+
26
160
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'psych'
3
+
4
+ describe RUGS::Client do
5
+
6
+ let(:config) {RUGS::Config}
7
+ let(:file_name){random_name}
8
+ let(:config_file){"#{config::PATH}/#{file_name}.yaml"}
9
+ let(:data){{some_key: 'some data'}}
10
+
11
+ it "should create a config file" do
12
+ config.save(file_name, data)
13
+
14
+ File.exist?(config_file).should be_true
15
+ end
16
+
17
+ it "should save the server's address in the config file" do
18
+ config.save(file_name, data)
19
+
20
+ servers = Psych.load(File.open(config_file))
21
+ servers.should include(data)
22
+ end
23
+
24
+ it "should load saved data" do
25
+ config.save(file_name, data)
26
+
27
+ config.load(file_name).should == data
28
+ end
29
+
30
+ after(:each) {clean_config}
31
+
32
+ end
@@ -4,18 +4,25 @@ require 'fileutils'
4
4
  describe RUGS::Git do
5
5
 
6
6
  let(:git) {RUGS::Git}
7
-
8
- it 'should run commands git knows' do
9
- repo_name = temp_name
10
- git.init(repo_name).should include("Initialized empty Git repository")
11
- end
7
+ let(:file_name) {random_name}
8
+ let(:repo_path) {"#{Dir.tmpdir}/#{file_name}"}
12
9
 
13
- it 'should not run commands git does not know' do
14
- repo_name = temp_name
15
- expect{git.unicorn_and_rainbows(repo_name)}.should
16
- raise_error(Object::Exception)
10
+ it 'should initialize a local repository' do
11
+ git.init(repo_path).should include("Initialized empty Git repository")
12
+ end
13
+
14
+ it 'should add remote settings to the repo' do
15
+ server = random_name
16
+ url = "git@#{random_name}.org"
17
+
18
+ git.init(repo_path)
19
+ git.remote_add(repo_path, server, url)
20
+
21
+ remotes = `git --git-dir="#{repo_path}/.git" --work-tree="#{repo_path}" remote`
22
+ remotes.should include(server)
23
+
17
24
  end
18
25
 
19
- after(:all) {FileUtils.rm_rf TEMP}
20
-
26
+ after(:all) {clean_temp}
27
+
21
28
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,21 @@
1
1
  $: << '.'
2
2
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "/../lib"))
3
+
3
4
  require 'rspec'
4
5
  require 'rugs'
6
+ require 'fileutils'
7
+ require 'tmpdir'
5
8
 
6
- TEMP = "temp_rspec"
9
+ def random_name
10
+ 12.times.map{('a'..'z').to_a.sample}.join
11
+ end
7
12
 
8
- def temp_name(length=8)
9
- "#{TEMP}/" + length.times.map{('a'..'z').to_a.sample}.join
13
+ def clean_config
14
+ FileUtils.rm Dir["#{RUGS::Config::PATH}/*"]
10
15
  end
16
+
17
+ def clean_temp
18
+ FileUtils.rm_rf TEMP_DIR
19
+ end
20
+
21
+ TEMP_DIR = "#{Dir.tmpdir}/#{random_name}"
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.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-23 00:00:00.000000000Z
12
+ date: 2011-09-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2152139360 !ruby/object:Gem::Requirement
16
+ requirement: &2152208160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,8 +21,19 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152139360
25
- description: Nothing to see here, move along.
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"
26
37
  email:
27
38
  - mikbe.tk@gmail.com
28
39
  executables: []
@@ -33,17 +44,19 @@ files:
33
44
  - Gemfile
34
45
  - README.markdown
35
46
  - Rakefile
47
+ - _spike/psych.rb
48
+ - _spike/test.yaml
36
49
  - autotest/discover.rb
37
50
  - lib/rugs.rb
38
51
  - lib/rugs/client.rb
52
+ - lib/rugs/config.rb
39
53
  - lib/rugs/file_events.rb
40
54
  - lib/rugs/git.rb
41
- - lib/rugs/server.rb
42
55
  - lib/rugs/version.rb
43
56
  - rugs.gemspec
44
57
  - spec/rugs/client_spec.rb
58
+ - spec/rugs/config_spec.rb
45
59
  - spec/rugs/git_spec.rb
46
- - spec/rugs/server_spec.rb
47
60
  - spec/spec_helper.rb
48
61
  homepage: http://mikbe.tk
49
62
  licenses: []
@@ -68,9 +81,9 @@ rubyforge_project:
68
81
  rubygems_version: 1.8.10
69
82
  signing_key:
70
83
  specification_version: 3
71
- summary: Place holder gem
84
+ summary: A helper script that makes setting up remote git repositories a snap.
72
85
  test_files:
73
86
  - spec/rugs/client_spec.rb
87
+ - spec/rugs/config_spec.rb
74
88
  - spec/rugs/git_spec.rb
75
- - spec/rugs/server_spec.rb
76
89
  - spec/spec_helper.rb
data/lib/rugs/server.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'fileutils'
2
-
3
- module RUGS
4
-
5
- class Server
6
-
7
- end
8
-
9
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
- require 'fileutils'
3
-
4
- describe RUGS::Server do
5
- let(:server) {RUGS::Server.new}
6
-
7
- context 'When creating repos' do
8
-
9
- end
10
-
11
- after(:all) {FileUtils.rm_rf TEMP}
12
-
13
- end