evilchelu-braid 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/braid.gemspec +1 -1
- data/lib/braid.rb +1 -0
- data/lib/braid/command.rb +24 -8
- data/lib/braid/commands/add.rb +2 -0
- data/lib/braid/commands/remove.rb +2 -0
- data/lib/braid/commands/setup.rb +1 -3
- data/lib/braid/commands/update.rb +2 -0
- data/lib/braid/exceptions.rb +2 -0
- data/lib/braid/operations.rb +31 -0
- data/lib/braid/version.rb +1 -1
- data/spec/operations_spec.rb +27 -0
- metadata +1 -1
data/braid.gemspec
CHANGED
data/lib/braid.rb
CHANGED
data/lib/braid/command.rb
CHANGED
@@ -3,15 +3,31 @@ module Braid
|
|
3
3
|
include Operations::Mirror
|
4
4
|
include Operations::Helpers
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
class << self
|
7
|
+
include Operations::Helpers
|
8
|
+
include Operations::Git
|
9
|
+
|
10
|
+
def run(command, *args)
|
11
|
+
raise Braid::Git::VersionTooLow unless verify_git_version(REQUIRED_GIT_VERSION)
|
12
|
+
|
13
|
+
klass = Braid::Commands.const_get(command.to_s.capitalize)
|
14
|
+
klass.new.run(*args)
|
15
|
+
|
16
|
+
rescue Braid::Git::LocalChangesPresent => e
|
17
|
+
msg "Local changes are present. You have to commit or stash them before running braid commands."
|
18
|
+
msg "Exiting."
|
19
|
+
|
20
|
+
rescue Braid::Git::VersionTooLow => e
|
21
|
+
msg "This version of braid requires at least git #{REQUIRED_GIT_VERSION}. You have #{extract_git_version}."
|
22
|
+
msg "Exiting."
|
12
23
|
|
13
|
-
|
14
|
-
|
24
|
+
rescue => e
|
25
|
+
# FIXME
|
26
|
+
end
|
27
|
+
|
28
|
+
def msg(str)
|
29
|
+
puts str
|
30
|
+
end
|
15
31
|
end
|
16
32
|
|
17
33
|
def config
|
data/lib/braid/commands/add.rb
CHANGED
@@ -2,6 +2,8 @@ module Braid
|
|
2
2
|
module Commands
|
3
3
|
class Add < Command
|
4
4
|
def run(remote, options = {})
|
5
|
+
raise Braid::Git::LocalChangesPresent if invoke(:local_changes?)
|
6
|
+
|
5
7
|
in_work_branch do
|
6
8
|
mirror, params = config.add_from_options(remote, options)
|
7
9
|
local_branch = get_local_branch_name(mirror, params)
|
data/lib/braid/commands/setup.rb
CHANGED
data/lib/braid/exceptions.rb
CHANGED
data/lib/braid/operations.rb
CHANGED
@@ -73,6 +73,11 @@ module Braid
|
|
73
73
|
exec!("git rm -r #{path}")
|
74
74
|
true
|
75
75
|
end
|
76
|
+
|
77
|
+
def local_changes?
|
78
|
+
status, out, err = exec("git status")
|
79
|
+
out.split("\n").grep(/nothing to commit \(working directory clean\)/).empty?
|
80
|
+
end
|
76
81
|
end
|
77
82
|
|
78
83
|
module Svn
|
@@ -111,6 +116,32 @@ module Braid
|
|
111
116
|
end
|
112
117
|
end
|
113
118
|
|
119
|
+
def extract_git_version
|
120
|
+
status, out, err = exec!("git --version")
|
121
|
+
return out.sub(/^git version/, "").strip
|
122
|
+
end
|
123
|
+
|
124
|
+
def verify_git_version(required)
|
125
|
+
required_version = required.split(".")
|
126
|
+
actual_version = extract_git_version.split(".")
|
127
|
+
actual_version.each_with_index do |actual_piece, idx|
|
128
|
+
required_piece = required_version[idx]
|
129
|
+
|
130
|
+
return true unless required_piece
|
131
|
+
|
132
|
+
case (actual_piece <=> required_piece)
|
133
|
+
when -1
|
134
|
+
return false
|
135
|
+
when 1
|
136
|
+
return true
|
137
|
+
when 0
|
138
|
+
next
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
return actual_version.length >= required_version.length
|
143
|
+
end
|
144
|
+
|
114
145
|
def find_git_revision(commit)
|
115
146
|
invoke(:git_rev_parse, commit)
|
116
147
|
rescue Braid::Commands::ShellExecutionError
|
data/lib/braid/version.rb
CHANGED
data/spec/operations_spec.rb
CHANGED
@@ -19,3 +19,30 @@ describe "Braid::Operations::Mirror#find_remote" do
|
|
19
19
|
find_remote("N/A").should == false
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
describe Braid::Operations::Helpers, "extract_git_version" do
|
24
|
+
it "should extract from git --version output" do
|
25
|
+
self.stub!(:exec!).and_return([0, "git version 1.5.5.1.98.gf0ec4\n", ""])
|
26
|
+
extract_git_version.should == "1.5.5.1.98.gf0ec4"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Braid::Operations::Helpers, "verify_git_version against 1.5.4.5" do
|
31
|
+
required_version = "1.5.4.5"
|
32
|
+
should_pass = %w(1.5.4.6 1.5.5 1.6 1.5.4.5.2 1.5.5.1.98.gf0ec4)
|
33
|
+
should_not_pass = %w(1.5.4.4 1.5.4 1.5.3 1.4.5.6)
|
34
|
+
|
35
|
+
should_pass.each do |actual_version|
|
36
|
+
it "should be true for #{actual_version}" do
|
37
|
+
self.stub!(:extract_git_version).and_return(actual_version)
|
38
|
+
verify_git_version("1.5.4.5").should == true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should_not_pass.each do |actual_version|
|
43
|
+
it "should be false for #{actual_version}" do
|
44
|
+
self.stub!(:extract_git_version).and_return(actual_version)
|
45
|
+
verify_git_version("1.5.4.5").should == false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|