webbynode 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of webbynode might be problematic. Click here for more details.
- data/Rakefile +1 -1
- data/lib/webbynode/commands/init.rb +6 -0
- data/lib/webbynode/git.rb +20 -0
- data/spec/webbynode/commands/init_spec.rb +28 -0
- data/spec/webbynode/git_spec.rb +36 -0
- data/webbynode.gemspec +2 -2
- metadata +3 -3
data/Rakefile
CHANGED
@@ -64,6 +64,12 @@ module Webbynode::Commands
|
|
64
64
|
git.commit "Initial commit"
|
65
65
|
end
|
66
66
|
|
67
|
+
if git.remote_exists?('webbynode')
|
68
|
+
if ask('Webbynode already initialized. Do you want to overwrite the current settings (y/n)?').downcase == 'y'
|
69
|
+
git.delete_remote('webbynode')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
67
73
|
io.log "Adding webbynode as git remote...", :action
|
68
74
|
git.add_remote "webbynode", webby_ip, app_name
|
69
75
|
|
data/lib/webbynode/git.rb
CHANGED
@@ -3,6 +3,7 @@ module Webbynode
|
|
3
3
|
class GitNotRepoError < StandardError; end
|
4
4
|
class GitRemoteDoesNotExistError < StandardError; end
|
5
5
|
class GitRemoteAlreadyExistsError < StandardError; end
|
6
|
+
class GitRemoteCouldNotRemoveError < StandardError; end
|
6
7
|
|
7
8
|
class Git
|
8
9
|
attr_accessor :config, :remote_ip
|
@@ -50,6 +51,16 @@ module Webbynode
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
54
|
+
def delete_remote(name)
|
55
|
+
exec("git remote rm #{name}") do |output|
|
56
|
+
# raise an exception if cannot remove
|
57
|
+
raise GitRemoteCouldNotRemoveError, output if output =~ /Could not remove config section/
|
58
|
+
|
59
|
+
# success if output is empty
|
60
|
+
output.nil? or output.empty?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
53
64
|
def commit(comments)
|
54
65
|
comments.gsub! /"/, '\"'
|
55
66
|
exec("git commit -m \"#{comments}\"") do |output|
|
@@ -85,6 +96,15 @@ module Webbynode
|
|
85
96
|
@remote_ip ||= ($2 if @config["remote"]["webbynode"]["url"] =~ /^(\w+)@(.+):(.+)$/) if @config
|
86
97
|
end
|
87
98
|
|
99
|
+
def remote_exists?(remote)
|
100
|
+
config = parse_config
|
101
|
+
config['remote'].key?(remote)
|
102
|
+
rescue Webbynode::GitNotRepoError
|
103
|
+
return false
|
104
|
+
rescue Webbynode::GitRemoteDoesNotExistError
|
105
|
+
return false
|
106
|
+
end
|
107
|
+
|
88
108
|
def remote_webbynode?
|
89
109
|
return true if io.exec('git remote') =~ /webbynode/
|
90
110
|
false
|
@@ -14,12 +14,40 @@ describe Webbynode::Commands::Init do
|
|
14
14
|
before(:each) do
|
15
15
|
FakeWeb.clean_registry
|
16
16
|
create_init
|
17
|
+
git_handler.stub!(:remote_exists?).and_return(false)
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when already initialized" do
|
21
|
+
it "keep the same remotes when answer is no to overwriting" do
|
22
|
+
command = Webbynode::Commands::Init.new("10.0.1.1")
|
23
|
+
command.should_receive(:git).any_number_of_times.and_return(git_handler)
|
24
|
+
command.should_receive(:ask).with("Webbynode already initialized. Do you want to overwrite the current settings (y/n)?").once.ordered.and_return("n")
|
25
|
+
|
26
|
+
git_handler.should_receive(:present?).and_return(true)
|
27
|
+
git_handler.should_receive(:remote_exists?).with("webbynode").and_return(true)
|
28
|
+
git_handler.should_receive(:delete_remote).with("webbynode").never
|
29
|
+
|
30
|
+
command.run
|
31
|
+
end
|
32
|
+
|
33
|
+
it "delete webbynode remote when answer is yes to overwriting" do
|
34
|
+
command = Webbynode::Commands::Init.new("10.0.1.1")
|
35
|
+
command.should_receive(:git).any_number_of_times.and_return(git_handler)
|
36
|
+
command.should_receive(:ask).with("Webbynode already initialized. Do you want to overwrite the current settings (y/n)?").once.ordered.and_return("y")
|
37
|
+
|
38
|
+
git_handler.should_receive(:present?).and_return(true)
|
39
|
+
git_handler.should_receive(:remote_exists?).with("webbynode").and_return(true)
|
40
|
+
git_handler.should_receive(:delete_remote).with("webbynode")
|
41
|
+
|
42
|
+
command.run
|
43
|
+
end
|
17
44
|
end
|
18
45
|
|
19
46
|
context "selecting an engine" do
|
20
47
|
it "should create the .webbynode/engine file" do
|
21
48
|
command = Webbynode::Commands::Init.new("10.0.1.1", "--engine=php")
|
22
49
|
command.option(:engine).should == 'php'
|
50
|
+
command.should_receive(:git).any_number_of_times.and_return(git_handler)
|
23
51
|
command.should_receive(:io).any_number_of_times.and_return(io_handler)
|
24
52
|
|
25
53
|
io_handler.should_receive(:add_setting).with("engine", "php")
|
data/spec/webbynode/git_spec.rb
CHANGED
@@ -30,6 +30,42 @@ describe Webbynode::Git do
|
|
30
30
|
Webbynode::Git.new.io.class.should == Webbynode::Io
|
31
31
|
end
|
32
32
|
|
33
|
+
describe "#delete_remote" do
|
34
|
+
it "executes remote rm command for the specificed remote" do
|
35
|
+
git = Webbynode::Git.new
|
36
|
+
git.should_receive(:exec).with("git remote rm webbynode")
|
37
|
+
git.delete_remote("webbynode")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should raise an error if the specified remote doesn't exist'" do
|
41
|
+
git = Webbynode::Git.new
|
42
|
+
git.should_receive(:exec).with("git remote rm webbynode").and_yield("error: Could not remove config section 'remote.other'")
|
43
|
+
lambda { git.delete_remote("webbynode") }.should raise_error(Webbynode::GitRemoteCouldNotRemoveError, "error: Could not remove config section 'remote.other'")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#remote_exists?" do
|
48
|
+
it "returns false when git is not present" do
|
49
|
+
git = Webbynode::Git.new
|
50
|
+
git.should_receive(:present?).any_number_of_times.and_return(false)
|
51
|
+
git.remote_exists?("anything").should be_false
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns false if no matching remote found" do
|
55
|
+
git = Webbynode::Git.new
|
56
|
+
git.should_receive(:present?).any_number_of_times.and_return(true)
|
57
|
+
git.should_receive(:parse_config).and_return({'remote'=>{"webbynode"=>"something"}})
|
58
|
+
git.remote_exists?("anything").should be_false
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns true if a matching remote found" do
|
62
|
+
git = Webbynode::Git.new
|
63
|
+
git.should_receive(:present?).any_number_of_times.and_return(true)
|
64
|
+
git.should_receive(:parse_config).and_return({'remote'=>{"webbynode"=>"something"}})
|
65
|
+
git.remote_exists?("webbynode").should be_true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
33
69
|
describe "#present?" do
|
34
70
|
it "should be true if folder .git exists" do
|
35
71
|
io_handler = mock("io")
|
data/webbynode.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{webbynode}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Felipe Coury"]
|
9
|
-
s.date = %q{2010-03-
|
9
|
+
s.date = %q{2010-03-28}
|
10
10
|
s.description = %q{Webbynode Deployment Gem}
|
11
11
|
s.email = %q{felipe@webbynode.com}
|
12
12
|
s.executables = ["webbynode", "wn"]
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Felipe Coury
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-28 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|