evilchelu-braid 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{braid}
3
- s.version = "0.3.7"
3
+ s.version = "0.3.8"
4
4
 
5
5
  s.specification_version = 2 if s.respond_to? :specification_version=
6
6
 
@@ -13,6 +13,7 @@ module Braid
13
13
  MIRROR_TYPES = %w[git svn]
14
14
  WORK_BRANCH = "braid/track"
15
15
  CONFIG_FILE = ".braids"
16
+ REQUIRED_GIT_VERSION = "1.5.4.5"
16
17
  end
17
18
 
18
19
  require 'braid/version'
@@ -3,15 +3,31 @@ module Braid
3
3
  include Operations::Mirror
4
4
  include Operations::Helpers
5
5
 
6
- def self.run(command, *args)
7
- klass = Braid::Commands.const_get(command.to_s.capitalize)
8
- klass.new.run(*args)
9
- rescue => e
10
- # FIXME
11
- end
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
- def self.msg(str)
14
- puts str
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
@@ -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)
@@ -2,6 +2,8 @@ module Braid
2
2
  module Commands
3
3
  class Remove < Command
4
4
  def run(mirror)
5
+ raise Braid::Git::LocalChangesPresent if invoke(:local_changes?)
6
+
5
7
  in_work_branch do
6
8
  params = config.get(mirror)
7
9
  unless params
@@ -2,9 +2,7 @@ module Braid
2
2
  module Commands
3
3
  class Setup < Command
4
4
  def run(mirror)
5
- in_work_branch do
6
- mirror ? setup_one(mirror) : setup_all
7
- end
5
+ mirror ? setup_one(mirror) : setup_all
8
6
  end
9
7
 
10
8
  protected
@@ -2,6 +2,8 @@ module Braid
2
2
  module Commands
3
3
  class Update < Command
4
4
  def run(mirror, options = {})
5
+ raise Braid::Git::LocalChangesPresent if invoke(:local_changes?)
6
+
5
7
  in_work_branch do
6
8
  mirror ? update_one(mirror, options) : update_all
7
9
  end
@@ -23,6 +23,8 @@ module Braid
23
23
 
24
24
  class Git
25
25
  class UnknownRevision < Braid::Exception; end
26
+ class VersionTooLow < Braid::Exception; end
27
+ class LocalChangesPresent < Braid::Exception; end
26
28
  end
27
29
 
28
30
  class Svn
@@ -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
@@ -2,7 +2,7 @@ module Braid #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 7
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evilchelu-braid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristi Balan