braid 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sw?
4
+ .DS_Store
5
+ .bundle
6
+ .idea
7
+ Gemfile.lock
8
+ coverage
9
+ nbproject
10
+ pkg
11
+ pkg/*
12
+ rdoc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.textile CHANGED
@@ -7,24 +7,19 @@ The project homepage is at "http://github.com/evilchelu/braid/wikis/home":http:/
7
7
  h2. Requirements
8
8
 
9
9
  * git 1.6+ (and git-svn if you want to mirror svn repositories)
10
- * main >= 2.8.0
11
- * open4 >= 0.9.6
10
+ * main >= 4.2.0
11
+ * open4 >= 1.0.1 (unless using jruby)
12
12
 
13
13
  h2. Installing using rubygems - official releases
14
14
 
15
15
  gem install braid
16
16
 
17
- h2. Installing using rubygems - development releases
18
-
19
- gem sources -a http://gems.github.com
20
- gem install evilchelu-braid
21
-
22
17
  h2. Installing from source
23
18
 
24
19
  git clone git://github.com/evilchelu/braid.git
25
20
  cd braid
26
- gem build braid.gemspec
27
- sudo gem install braid-x.y.z.gem
21
+ bundle install
22
+ rake install # possibly requiring sudo
28
23
 
29
24
  h2. Quick usage - ruby project
30
25
 
@@ -116,5 +111,5 @@ h2. Contributors (alphabetically)
116
111
  * Ferdinand Svehla
117
112
  * Michael Klishin
118
113
  * Roman Heinrich
114
+ * Travis Tilley
119
115
  * Tyler Rick
120
-
data/Rakefile CHANGED
@@ -1,3 +1,6 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
1
4
  require 'rake'
2
5
  require 'rake/testtask'
3
6
 
data/bin/braid CHANGED
@@ -55,7 +55,7 @@ Main {
55
55
 
56
56
  run {
57
57
  Braid.verbose = verbose
58
- Braid::Command.run(:add, url, { "type" => type, "path" => path, "branch" => branch, "rails_plugin" => rails_plugin, "revision" => revision, "full" => full })
58
+ Braid::Command.run(:add, url, {"type" => type, "path" => path, "branch" => branch, "rails_plugin" => rails_plugin, "revision" => revision, "full" => full})
59
59
  }
60
60
  }
61
61
 
@@ -79,7 +79,7 @@ Main {
79
79
 
80
80
  run {
81
81
  Braid.verbose = verbose
82
- Braid::Command.run(:update, path, { "revision" => revision, "head" => head })
82
+ Braid::Command.run(:update, path, {"revision" => revision, "head" => head})
83
83
  }
84
84
  }
85
85
 
@@ -99,8 +99,8 @@ Main {
99
99
  mixin :argument_path, :option_verbose, :option_keep_remote
100
100
 
101
101
  run {
102
- options = {
103
- :keep => keep
102
+ options = {
103
+ :keep => keep
104
104
  }
105
105
  Braid.verbose = verbose
106
106
  Braid::Command.run(:remove, path, options)
@@ -153,6 +153,14 @@ Main {
153
153
  }
154
154
  }
155
155
 
156
+ mode(:list) {
157
+ description 'Show all tracked mirrors (and if updates are available).'
158
+
159
+ run {
160
+ Braid::Command.run(:list)
161
+ }
162
+ }
163
+
156
164
  mixin(:argument_path) {
157
165
  argument(:path) {
158
166
  attr
@@ -225,7 +233,7 @@ Main {
225
233
 
226
234
  mixin(:option_verbose) {
227
235
  option(:verbose, :v) {
228
- optional
236
+ optional
229
237
  desc 'log shell commands'
230
238
  attr
231
239
  }
data/braid.gemspec CHANGED
@@ -1,25 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'braid/version'
4
+
1
5
  Gem::Specification.new do |s|
2
- s.name = %q{braid}
3
- s.version = "0.6.2"
6
+ s.name = %q{braid}
7
+ s.version = Braid::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+
10
+ s.authors = ["Cristi Balan", "Norbert Crombach"]
11
+ s.email = %q{evil@che.lu}
12
+
13
+ s.homepage = %q{http://evil.che.lu/projects/braid}
14
+ s.summary = %q{A simple tool for tracking vendor branches in git.}
15
+ s.description = %q{A simple tool for tracking vendor branches in git.}
4
16
 
5
- s.specification_version = 2 if s.respond_to? :specification_version=
17
+ s.rubyforge_project = %q{braid}
6
18
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Cristi Balan", "Norbert Crombach"]
9
- s.date = %q{2010-07-19}
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
10
22
  s.default_executable = %q{braid}
11
- s.description = %q{A simple tool for tracking vendor branches in git.}
12
- s.email = %q{evil@che.lu}
13
- s.executables = ["braid"]
14
- s.files = ["bin/braid", "braid.gemspec", "lib/braid/command.rb", "lib/braid/commands/add.rb", "lib/braid/commands/diff.rb", "lib/braid/commands/push.rb", "lib/braid/commands/remove.rb", "lib/braid/commands/setup.rb", "lib/braid/commands/update.rb", "lib/braid/config.rb", "lib/braid/mirror.rb", "lib/braid/operations.rb", "lib/braid.rb", "lib/core_ext.rb", "LICENSE", "Rakefile", "README.textile", "test/braid_test.rb", "test/config_test.rb", "test/fixtures/shiny/README", "test/fixtures/skit1/layouts/layout.liquid", "test/fixtures/skit1/preview.png", "test/fixtures/skit1.1/layouts/layout.liquid", "test/fixtures/skit1.2/layouts/layout.liquid", "test/integration/adding_test.rb", "test/integration/updating_test.rb", "test/integration_helper.rb", "test/mirror_test.rb", "test/operations_test.rb", "test/test_helper.rb"]
15
- s.has_rdoc = false
16
- s.homepage = %q{http://evil.che.lu/projects/braid}
17
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "braid", "--main"]
18
- s.require_paths = ["lib"]
19
- s.rubyforge_project = %q{braid}
20
- s.rubygems_version = %q{1.1.0}
21
- s.summary = %q{A simple tool for tracking vendor branches in git.}
23
+ s.require_paths = ["lib"]
24
+
25
+ s.has_rdoc = false
26
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "braid", "--main"]
22
27
 
23
28
  s.add_dependency(%q<main>, [">= 4.2.0"])
24
- s.add_dependency(%q<open4>, [">= 1.0.1"])
29
+ s.add_dependency(%q<open4>, [">= 1.0.1"]) unless defined?(JRUBY_VERSION)
30
+
31
+ s.add_development_dependency(%q<test-spec>, [">= 0.10.0"])
32
+ s.add_development_dependency(%q<mocha>, [">= 0.9.11"])
25
33
  end
data/lib/braid.rb CHANGED
@@ -1,16 +1,25 @@
1
1
  $:.unshift dirname = File.dirname(__FILE__)
2
+ require 'braid/version'
2
3
 
3
4
  module Braid
4
- VERSION = "0.6.2"
5
-
6
- CONFIG_FILE = ".braids"
5
+ CONFIG_FILE = ".braids"
7
6
  REQUIRED_GIT_VERSION = "1.6"
8
7
 
9
- def self.verbose; @verbose || false; end
10
- def self.verbose=(new_value); @verbose = !!new_value; end
8
+ def self.verbose
9
+ @verbose || false
10
+ end
11
+
12
+ def self.verbose=(new_value)
13
+ @verbose = !!new_value
14
+ end
15
+
16
+ def self.use_local_cache
17
+ [nil, "true", "1"].include?(ENV["BRAID_USE_LOCAL_CACHE"])
18
+ end
11
19
 
12
- def self.use_local_cache; [nil, "true", "1"].include?(ENV["BRAID_USE_LOCAL_CACHE"]); end
13
- def self.local_cache_dir; File.expand_path(ENV["BRAID_LOCAL_CACHE_DIR"] || "#{ENV["HOME"]}/.braid/cache"); end
20
+ def self.local_cache_dir
21
+ File.expand_path(ENV["BRAID_LOCAL_CACHE_DIR"] || "#{ENV["HOME"]}/.braid/cache")
22
+ end
14
23
 
15
24
  class BraidError < StandardError
16
25
  def message
@@ -25,6 +34,7 @@ require 'braid/operations'
25
34
  require 'braid/mirror'
26
35
  require 'braid/config'
27
36
  require 'braid/command'
37
+
28
38
  Dir[dirname + '/braid/commands/*'].each do |file|
29
39
  require file
30
40
  end
data/lib/braid/command.rb CHANGED
@@ -14,10 +14,10 @@ module Braid
14
14
 
15
15
  rescue BraidError => error
16
16
  case error
17
- when Operations::ShellExecutionError
18
- msg "Shell error: #{error.message}"
19
- else
20
- msg "Error: #{error.message}"
17
+ when Operations::ShellExecutionError
18
+ msg "Shell error: #{error.message}"
19
+ else
20
+ msg "Error: #{error.message}"
21
21
  end
22
22
  exit(1)
23
23
  end
@@ -39,93 +39,94 @@ module Braid
39
39
  end
40
40
 
41
41
  private
42
- def setup_remote(mirror)
43
- Command.run(:setup, mirror.path)
44
- end
45
42
 
46
- def use_local_cache?
47
- Braid.use_local_cache
48
- end
43
+ def setup_remote(mirror)
44
+ Command.run(:setup, mirror.path)
45
+ end
49
46
 
50
- def self.verify_git_version!
51
- git.require_version!(REQUIRED_GIT_VERSION)
52
- end
47
+ def use_local_cache?
48
+ Braid.use_local_cache
49
+ end
53
50
 
54
- def bail_on_local_changes!
55
- git.ensure_clean!
56
- end
51
+ def self.verify_git_version!
52
+ git.require_version!(REQUIRED_GIT_VERSION)
53
+ end
57
54
 
58
- def with_reset_on_error
59
- work_head = git.head
55
+ def bail_on_local_changes!
56
+ git.ensure_clean!
57
+ end
60
58
 
61
- begin
62
- yield
63
- rescue => error
64
- msg "Resetting to '#{work_head[0, 7]}'."
65
- git.reset_hard(work_head)
66
- raise error
67
- end
68
- end
59
+ def with_reset_on_error
60
+ work_head = git.head
69
61
 
70
- def load_and_migrate_config
71
- config = Config.new
72
- unless config.valid?
73
- msg "Configuration is outdated. Migrating."
74
- bail_on_local_changes!
75
- config.migrate!
76
- git.commit("Upgrade .braids", "-- .braids")
77
- end
78
- config
62
+ begin
63
+ yield
64
+ rescue => error
65
+ msg "Resetting to '#{work_head[0, 7]}'."
66
+ git.reset_hard(work_head)
67
+ raise error
79
68
  end
69
+ end
80
70
 
81
- def add_config_file
82
- git.add(CONFIG_FILE)
71
+ def load_and_migrate_config
72
+ config = Config.new
73
+ unless config.valid?
74
+ msg "Configuration is outdated. Migrating."
75
+ bail_on_local_changes!
76
+ config.migrate!
77
+ git.commit("Upgrade .braids", "-- .braids")
83
78
  end
79
+ config
80
+ end
84
81
 
85
- def display_revision(mirror, revision = nil)
86
- revision ||= mirror.revision
87
- mirror.type == "svn" ? "r#{revision}" : "'#{revision[0, 7]}'"
88
- end
82
+ def add_config_file
83
+ git.add(CONFIG_FILE)
84
+ end
89
85
 
90
- def validate_new_revision(mirror, new_revision)
91
- unless new_revision
92
- unless mirror.type == "svn"
93
- return git.rev_parse(mirror.remote)
94
- else
95
- return svn.head_revision(mirror.url)
96
- end
97
- end
86
+ def display_revision(mirror, revision = nil)
87
+ revision ||= mirror.revision
88
+ mirror.type == "svn" ? "r#{revision}" : "'#{revision[0, 7]}'"
89
+ end
98
90
 
91
+ def validate_new_revision(mirror, new_revision)
92
+ unless new_revision
99
93
  unless mirror.type == "svn"
100
- new_revision = git.rev_parse(new_revision)
94
+ return git.rev_parse(mirror.remote)
101
95
  else
102
- new_revision = svn.clean_revision(new_revision)
96
+ return svn.head_revision(mirror.url)
103
97
  end
104
- old_revision = mirror.revision
98
+ end
105
99
 
106
- if new_revision == old_revision
107
- raise InvalidRevision, "mirror is already at requested revision"
108
- end
100
+ unless mirror.type == "svn"
101
+ new_revision = git.rev_parse(new_revision)
102
+ else
103
+ new_revision = svn.clean_revision(new_revision)
104
+ end
105
+ old_revision = mirror.revision
109
106
 
110
- if mirror.type == "svn"
111
- if old_revision && new_revision < old_revision
112
- raise InvalidRevision, "local revision is higher than request revision"
113
- end
107
+ if new_revision == old_revision
108
+ raise InvalidRevision, "mirror is already at requested revision"
109
+ end
114
110
 
115
- if svn.head_revision(mirror.url) < new_revision
116
- raise InvalidRevision, "requested revision is higher than remote revision"
117
- end
111
+ if mirror.type == "svn"
112
+ if old_revision && new_revision < old_revision
113
+ raise InvalidRevision, "local revision is higher than request revision"
118
114
  end
119
115
 
120
- new_revision
116
+ if svn.head_revision(mirror.url) < new_revision
117
+ raise InvalidRevision, "requested revision is higher than remote revision"
118
+ end
121
119
  end
122
120
 
123
- def determine_target_revision(mirror, new_revision)
124
- unless mirror.type == "svn"
125
- git.rev_parse(new_revision)
126
- else
127
- git_svn.commit_hash(mirror.remote, new_revision)
128
- end
121
+ new_revision
122
+ end
123
+
124
+ def determine_target_revision(mirror, new_revision)
125
+ unless mirror.type == "svn"
126
+ git.rev_parse(new_revision)
127
+ else
128
+ git_svn.commit_hash(mirror.remote, new_revision)
129
129
  end
130
+ end
130
131
  end
131
132
  end
@@ -5,9 +5,9 @@ module Braid
5
5
  bail_on_local_changes!
6
6
 
7
7
  with_reset_on_error do
8
- mirror = config.add_from_options(url, options)
8
+ mirror = config.add_from_options(url, options)
9
9
 
10
- branch_message = (mirror.type == "svn" || mirror.branch == "master") ? "" : " branch '#{mirror.branch}'"
10
+ branch_message = (mirror.type == "svn" || mirror.branch == "master") ? "" : " branch '#{mirror.branch}'"
11
11
  revision_message = options["revision"] ? " at #{display_revision(mirror, options["revision"])}" : ""
12
12
  msg "Adding #{mirror.type} mirror of '#{mirror.url}'#{branch_message}#{revision_message}."
13
13
 
@@ -17,7 +17,7 @@ module Braid
17
17
  setup_remote(mirror)
18
18
  mirror.fetch
19
19
 
20
- new_revision = validate_new_revision(mirror, options["revision"])
20
+ new_revision = validate_new_revision(mirror, options["revision"])
21
21
  target_revision = determine_target_revision(mirror, new_revision)
22
22
 
23
23
  unless mirror.squashed?
@@ -0,0 +1,32 @@
1
+ module Braid
2
+ module Commands
3
+ class List < Command
4
+ def run(path = nil, options = {})
5
+ with_reset_on_error do
6
+ path ? list_one(path, options) : list_all(options)
7
+ end
8
+ end
9
+
10
+ protected
11
+ def list_all(options = {})
12
+ options.reject! { |k, v| %w(revision head).include?(k) }
13
+ print "\n"
14
+ msg "Listing all mirrors.\n=======================================================\n"
15
+ config.mirrors.each_with_index do |path, i|
16
+ mirror = config.get!(path)
17
+ print " #{i + 1}) #{path.to_s}"
18
+ print " [LOCKED]" if mirror.locked?
19
+ setup_remote(mirror)
20
+ msg "Fetching new commits for '#{mirror.path}'." if verbose?
21
+ mirror.fetch
22
+ new_revision = validate_new_revision(mirror, options["revision"])
23
+ target_revision = determine_target_revision(mirror, new_revision)
24
+ print " !!! UPDATE AVAILABLE !!!" if new_revision.to_s != mirror.base_revision.to_s
25
+ print "\n"
26
+ end
27
+ print "\n"
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -5,7 +5,7 @@ module Braid
5
5
  module Commands
6
6
  class Push < Command
7
7
  def run(path, options = {})
8
- mirror = config.get!(path)
8
+ mirror = config.get!(path)
9
9
 
10
10
  #mirror.fetch
11
11