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 +12 -0
- data/Gemfile +3 -0
- data/README.textile +5 -10
- data/Rakefile +3 -0
- data/bin/braid +13 -5
- data/braid.gemspec +26 -18
- data/lib/braid.rb +17 -7
- data/lib/braid/command.rb +70 -69
- data/lib/braid/commands/add.rb +3 -3
- data/lib/braid/commands/list.rb +32 -0
- data/lib/braid/commands/push.rb +1 -1
- data/lib/braid/commands/setup.rb +19 -18
- data/lib/braid/commands/update.rb +70 -69
- data/lib/braid/config.rb +9 -9
- data/lib/braid/mirror.rb +49 -48
- data/lib/braid/operations.rb +98 -69
- data/lib/braid/version.rb +3 -0
- data/lib/core_ext.rb +1 -1
- data/test/config_test.rb +1 -1
- data/test/integration/adding_test.rb +2 -2
- data/test/integration/updating_test.rb +4 -4
- data/test/integration_helper.rb +3 -3
- data/test/mirror_test.rb +2 -2
- data/test/operations_test.rb +2 -2
- metadata +101 -95
data/.gitignore
ADDED
data/Gemfile
ADDED
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.
|
11
|
-
* open4 >= 0.
|
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
|
-
|
27
|
-
|
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
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, {
|
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, {
|
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
|
-
|
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
|
3
|
-
s.version
|
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.
|
17
|
+
s.rubyforge_project = %q{braid}
|
6
18
|
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
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.
|
12
|
-
|
13
|
-
s.
|
14
|
-
s.
|
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
|
-
|
5
|
-
|
6
|
-
CONFIG_FILE = ".braids"
|
5
|
+
CONFIG_FILE = ".braids"
|
7
6
|
REQUIRED_GIT_VERSION = "1.6"
|
8
7
|
|
9
|
-
def self.verbose
|
10
|
-
|
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.
|
13
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
43
|
+
def setup_remote(mirror)
|
44
|
+
Command.run(:setup, mirror.path)
|
45
|
+
end
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
def use_local_cache?
|
48
|
+
Braid.use_local_cache
|
49
|
+
end
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
def self.verify_git_version!
|
52
|
+
git.require_version!(REQUIRED_GIT_VERSION)
|
53
|
+
end
|
57
54
|
|
58
|
-
|
59
|
-
|
55
|
+
def bail_on_local_changes!
|
56
|
+
git.ensure_clean!
|
57
|
+
end
|
60
58
|
|
61
|
-
|
62
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
82
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
82
|
+
def add_config_file
|
83
|
+
git.add(CONFIG_FILE)
|
84
|
+
end
|
89
85
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
94
|
+
return git.rev_parse(mirror.remote)
|
101
95
|
else
|
102
|
-
|
96
|
+
return svn.head_revision(mirror.url)
|
103
97
|
end
|
104
|
-
|
98
|
+
end
|
105
99
|
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
107
|
+
if new_revision == old_revision
|
108
|
+
raise InvalidRevision, "mirror is already at requested revision"
|
109
|
+
end
|
114
110
|
|
115
|
-
|
116
|
-
|
117
|
-
|
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
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
data/lib/braid/commands/add.rb
CHANGED
@@ -5,9 +5,9 @@ module Braid
|
|
5
5
|
bail_on_local_changes!
|
6
6
|
|
7
7
|
with_reset_on_error do
|
8
|
-
mirror
|
8
|
+
mirror = config.add_from_options(url, options)
|
9
9
|
|
10
|
-
branch_message
|
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
|
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
|